Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Mocking a web request like webmock. #967

Closed
majioa opened this issue Nov 23, 2016 · 3 comments
Closed

Mocking a web request like webmock. #967

majioa opened this issue Nov 23, 2016 · 3 comments

Comments

@majioa
Copy link

majioa commented Nov 23, 2016

How can I mock requests to the external web-sites similar to it is done in webmock?

I saw the access to external resources is allowing/denying by call to the proper method in the config like:

Capybara::Webkit.configure do |config|
    config.allow_url("www.sandbox.paypal.com")
end

I wish to use something like:

Capybara::Webkit.configure do |config|
    config.mock_url("www.sandbox.paypal.com").with(PaypalFake)
end

where PaypalFake is the fake sinatra app. Is it there something like this in capybara-webkit?

@mhoran
Copy link
Collaborator

mhoran commented Nov 23, 2016

You'll need to use something like Puffing Billy to intercept the request and proxy it to a fake. Capybara.javascript_driver = :webkit_billy will set that all up for you, or you can manually set the proxy for capybara-webkit to point to puffing-billy.

@majioa
Copy link
Author

majioa commented Nov 23, 2016

@mhoran how to set proxy from webkit to puffing-billy?

@mhoran
Copy link
Collaborator

mhoran commented Nov 23, 2016

Capybara::Webkit.configure do |config|
  # Use a proxy
  config.use_proxy(
    host: Billy.proxy.host
    port: Billy.proxy.port
  )
end

You may also want to set other options as documented here: https://github.com/thoughtbot/capybara-webkit#configuration.

@majioa majioa closed this as completed Nov 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants