3

I'm trying to run cucumber using VCR gem, chrome driver, and webmock but it's not working. One problem is that none of the requests are getting recorded. I do have VCR set to ignore_localhost which I believe is needed due to javascript as explained in this SO answer.

But why doesn't my step request to visit a url (say www.test.com) get recorded? I see the chrome browser loading up and the address in the URL so I know the cucumber step is going there.

If i turn off ignore_localhost then I see some recordings but the uri's are all 127.0.0.1. The uri I'd expect is showing up in body: string instead of the uri. Why is this happening?

request:
  method: post
  uri: http://127.0.0.1:9592/session/87bb12aa8b5b1230399b98bcc7d0ba11/url
  body:
    encoding: US-ASCII
    string: ! '{"url":"http://www.test.com"}'
  headers:
    Accept:
    - application/json
    Content-Type:
    - application/json; charset=utf-8
    Content-Length:
    - '46'
    User-Agent:
    - Ruby

Incase it helps, here's my VCR config

VCR.configure do |c|
  c.cassette_library_dir = 'features/support/vcr_cassettes'
  c.hook_into :webmock
  c.ignore_localhost = true
end
Community
  • 1
  • 1
Dty
  • 12,253
  • 6
  • 43
  • 61

1 Answers1

1

First of all, set your configuration like this:

VCR.configure do |c|
  c.cassette_library_dir = 'features/support/vcr_cassettes'
  c.hook_into :webmock
  c.ignore_localhost = true
  c.allow_http_connections_when_no_cassette = false
end

With the last option you tell VCR that no real http requests are allowed, without a cassette. Now run your tests. I bet that it'll throw an error! Now you have to tell VCR when to use which cassette. Have a look at the cucumber helpers for VCR here https://www.relishapp.com/vcr/vcr/v/2-4-0/docs/test-frameworks/usage-with-cucumber

VCR includes some helpers for other testing frameworks too https://www.relishapp.com/vcr/vcr/v/2-4-0/docs/test-frameworks

23tux
  • 14,104
  • 15
  • 88
  • 187