Skip to content

Commit c1a7e7d

Browse files
odlpPragTob
authored andcommitted
Use Rack::Directory to serve coverage report
Simplifies Capybara config References: - https://www.rubydoc.info/github/rack/rack/Rack/Directory - https://www.rubydoc.info/gems/rack/Rack/Static
1 parent 9cd3a46 commit c1a7e7d

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

features/support/env.rb

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,12 @@
1111
require "capybara/apparition"
1212
require "simplecov"
1313

14-
# Fake rack app for capybara that just returns the latest coverage report from aruba temp project dir
15-
Capybara.app = lambda { |env|
16-
request_path = env["REQUEST_PATH"] || "/"
17-
request_path = "/index.html" if request_path == "/"
18-
corresponding_file_path =
19-
File.join(File.dirname(__FILE__), "../../tmp/aruba/project/coverage", request_path)
20-
21-
content =
22-
if File.exist?(corresponding_file_path)
23-
File.read(corresponding_file_path)
24-
else
25-
# See #776 for whatever reason sometimes JRuby in one feature couldn't
26-
# find the loading.gif - which isn't essential so answering empty string
27-
# should be good enough
28-
warn "Couldn't find #{corresponding_file_path} generating empty response"
29-
""
30-
end
31-
32-
[
33-
200,
34-
{"Content-Type" => "text/html"},
35-
[content]
36-
]
37-
}
14+
# Rack app for Capybara which returns the latest coverage report from Aruba temp project dir
15+
coverage_dir = File.expand_path("../../tmp/aruba/project/coverage/", __dir__)
16+
Capybara.app = Rack::Builder.new do
17+
use Rack::Static, urls: {"/" => "index.html"}, root: coverage_dir
18+
run Rack::Directory.new(coverage_dir)
19+
end.to_app
3820

3921
Capybara.configure do |config|
4022
config.ignore_hidden_elements = false

0 commit comments

Comments
 (0)