RSpec Webmock无法正常工作

时间:2017-11-12 15:27:54

标签: ruby-on-rails rspec httparty webmock

我发出此请求: https://api.yotpo.com/products/abc123apikey/yotpo_global_reviews/reviews

这是我的错误:

    Failure/Error: resp = HTTParty.get(BASE_URL + PRODUCTS + yotpo_api_key + GLOBAL_REVIEWS)

 WebMock::NetConnectNotAllowedError:
   Real HTTP connections are disabled. Unregistered request: GET https://api.yotpo.com/products/abc123apikey/yotpo_global_reviews/reviews with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}

   You can stub this request with the following snippet:

   stub_request(:get, "https://api.yotpo.com/products/abc123apikey/yotpo_global_reviews/reviews").
     with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
     to_return(status: 200, body: "", headers: {})

   registered request stubs:

   stub_request(:any, "/https:\/\/api.baremetrics.com/")
   stub_request(:post, "https://api.mixpanel.com/track")
   stub_request(:post, "https://api.mixpanel.com/engage")

我正在使用确切的代码段,但没有任何工作。我已经搜索并试了一堆,没有任何改变。我也试过删除标题。

我在这个存根请求中看不到任何动态的东西。我犯了一些明显的错误吗?

1 个答案:

答案 0 :(得分:0)

我的存根文件位于错误的目录中。请删除此问题。