-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.rb
57 lines (50 loc) · 1.52 KB
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'puma'
require 'puma/configuration'
require 'puma/events'
require 'rack'
require 'rack/contrib'
require 'tony'
module Tony
module Test
module Goldens
class Server
def initialize(failures)
app = Tony::App.new
slim = Tony::Slim.new(views: __dir__)
server = ::Rack::Builder.new {
use(Tony::Static, public_folder: __dir__)
use(Tony::Static, public_folder: '/')
use(::Rack::JSONBodyParser)
run(app)
}
conf = Puma::Configuration.new { |user_config|
user_config.app(server)
user_config.port(0)
}
events = Puma::Events.new($stdout, $stderr)
launcher = Puma::Launcher.new(conf, events: events)
app.get('/', ->(_, resp) {
resp.write(slim.render(:review, failures: failures))
})
app.post('/finish', ->(_, resp) {
launcher.stop
resp.write('All done...please close this window.')
})
app.post('/reject', ->(_, resp) {
resp.status = 201
})
app.post('/accept', ->(req, resp) {
failure = failures[req.params[:index].to_i]
FileUtils.mkdir_p(File.dirname(failure.golden))
FileUtils.mv(failure.new, failure.golden)
resp.status = 201
})
events.on_booted {
system("open http://localhost:#{launcher.connected_ports.first}")
}
launcher.run
end
end
end
end
end