我的录像机与 webmock 规范有问题。当我运行 rspec spec/ 时,我总是遇到同样的问题
.rvm/gems/ruby-2.1.3/gems/webmock-1.18.0/lib/webmock/http_lib_adapters/net_http.rb:114:in `request': Real HTTP connections are disabled. Unregistered request: POST https://somevalue@accounts.spotify.com/api/token with body 'grant_type=client_credentials' with headers {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'29', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'} (WebMock::NetConnectNotAllowedError)
You can stub this request with the following snippet:
stub_request(:post, "https://somevalue@accounts.spotify.com/api/token").
with(:body => {"grant_type"=>"client_credentials"},
:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'29', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
to_return(:status => 200, :body => "", :headers => {})
============================================================
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rest_client-1.8.2/lib/restclient/request.rb:186:in `block in transmit'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/webmock-1.18.0/lib/webmock/http_lib_adapters/net_http.rb:123:in `start_without_connect'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/webmock-1.18.0/lib/webmock/http_lib_adapters/net_http.rb:150:in `start'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rest_client-1.8.2/lib/restclient/request.rb:182:in `transmit'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rest_client-1.8.2/lib/restclient/request.rb:68:in `execute'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rest_client-1.8.2/lib/restclient/request.rb:35:in `execute'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rest_client-1.8.2/lib/restclient.rb:73:in `post'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspotify-1.9.0/lib/rspotify/connection.rb:27:in `authenticate'
from /home/pnc/sites/spolisty/config/initializers/devise.rb:260:in `block in <top (required)>'
from /home/pnc/.rvm/gems/ruby-2.1.3/bundler/gems/devise-a9d90503e903/lib/devise.rb:293:in `setup'
from /home/pnc/sites/spolisty/config/initializers/devise.rb:3:in `<top (required)>'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/dependencies.rb:268:in `load'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/dependencies.rb:268:in `block in load'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/dependencies.rb:268:in `load'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0.rc1/lib/active_support/notifications.rb:166:in `instrument'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/engine.rb:651:in `load_config_initializer'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/engine.rb:615:in `each'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/engine.rb:615:in `block in <class:Engine>'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:30:in `instance_exec'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:30:in `run'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:44:in `each'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:44:in `tsort_each_child'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:411:in `call'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /home/pnc/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/initializable.rb:54:in `run_initializers'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0.rc1/lib/rails/application.rb:352:in `initialize!'
from /home/pnc/sites/spolisty/config/environment.rb:5:in `<top (required)>'
from /home/pnc/sites/spolisty/spec/rails_helper.rb:3:in `require'
from /home/pnc/sites/spolisty/spec/rails_helper.rb:3:in `<top (required)>'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1072:in `require'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1072:in `block in requires='
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1072:in `each'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1072:in `requires='
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration_options.rb:103:in `block in process_options_into'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration_options.rb:102:in `each'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration_options.rb:102:in `process_options_into'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/configuration_options.rb:22:in `configure'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:95:in `setup'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
from /home/pnc/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
from /home/pnc/.rvm/gems/ruby-2.1.3/bin/rspec:23:in `load'
from /home/pnc/.rvm/gems/ruby-2.1.3/bin/rspec:23:in `<main>'
from /home/pnc/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `eval'
from /home/pnc/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `<main>'
我试图解决这个问题:
将 c.ignore_localhost = true 添加到我的 vcr 配置中
将此代码添加到我的 rails_helper.rb
需要 'webmock/cucumber' WebMock.disable_net_connect!(:allow_localhost => true)
我尝试删除我使用 vcr 的所有测试,然后运行 rspec spec/ 但仍然出现此错误
这个错误告诉我我可以存根这个请求,但我该怎么做呢?
知道如何解决此错误吗?