I have a capybara test that checks for content on a page. I have an img tag thats src calls for a URL that does not exist. When I run the test I receive:
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/avatars/original/missing.png"
I honestly don't care about this request. Is there any way for me stub /avatars/original/missing.png
on my Capybara test?
When using Poltergeist you can use the blacklist functionality to block specific requests. If using Poltergeist 1.10.0+ you can configure it for every test in the driver registration block by adding the :url_blacklist option
Capybara.register_driver :poltergeist do |app|
# Change domain name as necessary
options = { url_blacklist: ['http://www.example.com/avatars/original/missing.png'] } # you can also use * as a wildcard
Capybara::Poltergeist::Driver.new(app, options)
end
In pre 1.10 or if you want to do it on a test by test/before block basis you can do
page.driver.browser.url_blacklist = ['http://www.example.com/avatars/original/missing.png']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With