首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Webmock未响应stub_request

Webmock未响应stub_request
EN

Stack Overflow用户
提问于 2013-11-07 19:49:47
回答 1查看 2.6K关注 0票数 3

在feature/support/webmock.rb中,我有

代码语言:javascript
复制
stub_request(:get, /(http\:\/\/catalog\.viglink\.com\/vigcatalog\/products\.xml\?include_identifiers=true&key=.*&keyword_upc=628586348097&results_per_page=20)/).
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'User-Agent'=>'Ruby'}).
to_return(:status => 200, :body => File.open('spec/support/628586348097.txt'))

我有两个应该调用此存根的黄瓜场景。在一种情况下,存根被识别,并且测试通过。在另一个场景中,我收到以下内容:

代码语言:javascript
复制
Real HTTP connections are disabled. Unregistered request: GET http://catalog.viglink.com/vigcatalog/products.xml?include_identifiers=true&key=key&keyword_upc=628586348097&results_per_page=20 with headers {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}

You can stub this request with the following snippet:

stub_request(:get, "http://catalog.viglink.com/vigcatalog/products.xml?include_identifiers=true&key=key&keyword_upc=628586348097&results_per_page=20").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(:status => 200, :body => "", :headers => {})

关于webmock无法识别存根请求的原因有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2014-08-22 02:31:06

在webmock.rb文件中,请确保将stub_requests放在Before块中。否则,您将需要在您的步骤中包含它们...

代码语言:javascript
复制
require 'webmock/cucumber'

Before do
  WebMock.disable_net_connect! #A precaution to avoid webmock making real http calls

  stub_request(:get, /.*url*/).to_return(:body => File.new("#{::Rails.root}/support/webmock/listing.json")
end
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19835157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档