1

When I have dependencies such as http or authenticate, how can I use Cucumber without being slowed down on these services ?

1

You should mock / stub those dependencies.

WebMock can do that. It stubs at a low HTTP client lib level.
Add require 'webmock/cucumber' in the support/env.rb file

Examples:

Simulate basic http

stub_request(:get, "www.test.com").to_return(:body => "Test")
stub_request(:post, "www.test.com").with(:body => "test", :header => "Content-Type: application/json")

stub_request(:POST, "https://github.com/login/oauth/access_token").with("client_id={client_id}
&client_secret={secret}
&code={code}").to_return("access_token={token}
&token_type=bearer")

Simulate OAuth

stub_request(:GET, "httpsL//api.github.com/users/wayneye")
.with(:headers => 'Authorization: token{fake_token}')
.and_return('"name": "Wayne Ye", "public_repos":9, "company": "ThoughtWorks"')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.