Reputation: 13181
I have a set of files in a folder under spec/support/fixtures directory. I need those files to be accessible through an uri such as "http://127.0.0.0:#{Capybara.current_session.server.port}/test_fixtures"
After many trail and errors I ended up the following solution: In rails_helper.rb I added the following code:
Capybara.app = Rack::Builder.new do
map '/' do
run Rails.application
end
map '/test_fixtures' do
run Rack::File.new('spec/support/fixtures')
end
end.to_app
It works well, but the solution to re-create Capybara app does not seem elegant to me. I'm looking for a better solution... or is it ok like this ?
Thanks
Upvotes: 1
Views: 55
Reputation: 49880
For your stated goal you have implemented things correctly and that is exactly what the Capybara.app
setting is meant for. The only thing I would recommend doing is moving it into a separate file and requiring that file in your rails_helper.
Upvotes: 1