Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't disable Webmock / VCR when running rake task #6

Closed
bgentry opened this issue May 6, 2016 · 2 comments
Closed

Can't disable Webmock / VCR when running rake task #6

bgentry opened this issue May 6, 2016 · 2 comments

Comments

@bgentry
Copy link

bgentry commented May 6, 2016

I'm trying to run the rake knapsack_pro:rspec task on my dockerized Buildkite fleet. However, Webmock is getting in the way:

** Invoke knapsack_pro:rspec (first_time)
** Execute knapsack_pro:rspec
D, [2016-05-06T05:57:53.344852 #55] DEBUG -- : ** [Raven] Event not sent due to excluded environment: test
rake aborted!
WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: POST http://api.knapsackpro.com/v1/build_distributions/subset with body 

...redacted

============================================================/usr/local/bundle/gems/webmock-1.21.0/lib/webmock/http_lib_adapters/net_http.rb:114:in `request'
/usr/local/lib/ruby/2.3.0/net/http.rb:1421:in `send_entity'
/usr/local/lib/ruby/2.3.0/net/http.rb:1209:in `post'
/usr/local/bundle/gems/knapsack_pro-0.7.0/lib/knapsack_pro/client/connection.rb:75:in `post'
/usr/local/bundle/gems/knapsack_pro-0.7.0/lib/knapsack_pro/client/connection.rb:11:in `call'
/usr/local/bundle/gems/knapsack_pro-0.7.0/lib/knapsack_pro/allocator.rb:19:in `test_file_paths'
/usr/local/bundle/gems/knapsack_pro-0.7.0/lib/knapsack_pro/runners/base_runner.rb:14:in `test_file_paths'
/usr/local/bundle/gems/knapsack_pro-0.7.0/lib/knapsack_pro/runners/base_runner.rb:18:in `stringify_test_file_paths'
/usr/local/bundle/gems/knapsack_pro-0.7.0/lib/knapsack_pro/runners/rspec_runner.rb:9:in `run'
/usr/local/bundle/gems/knapsack_pro-0.7.0/lib/tasks/rspec.rake:5:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/usr/local/bundle/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/usr/local/bundle/bin/rake:17:in `load'
/usr/local/bundle/bin/rake:17:in `<main>'
Tasks: TOP => knapsack_pro:rspec

I believe I'm ignoring requests to this hostname correctly in my spec_helper.rb:

# Setup VCR
VCR.configure do |config|
  config.cassette_library_dir = 'spec/fixtures/vcr'
  config.hook_into :webmock
  # allow requests to localhost and knapsack pro:
  config.ignore_hosts 'localhost', '127.0.0.1', '0.0.0.0', 'api.knapsackpro.com'
end

Do I need to do something else to get VCR & webmock out of the way for the knapsack_pro rake task?

@bgentry
Copy link
Author

bgentry commented May 6, 2016

I did find a workaround. I put this in my Rakefile immediately after the call to load KnapsackPro tasks:

WebMock.disable_net_connect!(:allow => 'api.knapsackpro.com') if defined?(WebMock)

@ArturT
Copy link
Member

ArturT commented May 6, 2016

Great. I've updated example of Rakefile in readme.

@ArturT ArturT closed this as completed May 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants