简体   繁体   中英

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?

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM