Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara: Stubbing No Route Matches

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?

like image 265
thank_you Avatar asked Aug 26 '16 13:08

thank_you


1 Answers

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']
like image 193
Thomas Walpole Avatar answered Oct 11 '22 09:10

Thomas Walpole