Ruby on rails Can';对Flickr API的t存根请求

Ruby on rails Can';对Flickr API的t存根请求,ruby-on-rails,rspec,flickr,webmock,Ruby On Rails,Rspec,Flickr,Webmock,我无法为我的应用程序存根到Flickr API的请求 控制器测试。我使用gem'flickraw'从flickrapi获取数据 flickr_search_controller.rb: module Dashboard class FlickrSearchController < Dashboard::BaseController respond_to :js def search @search_tag = params[:search] p

我无法为我的应用程序存根到Flickr API的请求 控制器测试。我使用gem'flickraw'从flickrapi获取数据

flickr_search_controller.rb:

module Dashboard
  class FlickrSearchController < Dashboard::BaseController
    respond_to :js

    def search
      @search_tag = params[:search]
      photos_list = if @search_tag.blank?
                      flickr.photos.getRecent(per_page: 10)
                    else
                      flickr.photos.search(text: @search_tag, per_page: 10)
                    end

      @photos = photos_list.map { |photo| FlickRaw.url_q(photo) }
    end
  end
end
结束 我在控制台中得到下一个错误:

Failures:

1) Dashboard::FlickrSearchController when user didn't set search tag returns recend photo
 Failure/Error: flickr.photos.getRecent(per_page: 10)

 WebMock::NetConnectNotAllowedError:
   Real HTTP connections are disabled. Unregistered request: POST https://api.flickr.com/services/rest/ with body 'method=flickr.reflection.getMethods&format=json&nojsoncallback=1' with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'OAuth realm="https://api.flickr.com/services/rest/", oauth_consumer_key="32904448e7d40c7e833c7b381c86cd31", oauth_nonce="lCL%2FUM9o8go5XNVy4F7p%2FNxHJrY%2BvFNLhlzueFq8Juc%3D", oauth_signature="1b77fc6af54b2b51%26", oauth_signature_method="PLAINTEXT", oauth_timestamp="1455128674", oauth_token="", oauth_version="1.0"', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'FlickRaw/0.9.8'}

   You can stub this request with the following snippet:

   stub_request(:post, "https://api.flickr.com/services/rest/").
     with(:body => {"format"=>"json", "method"=>"flickr.reflection.getMethods", "nojsoncallback"=>"1"},
          :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'OAuth realm="https://api.flickr.com/services/rest/", oauth_consumer_key="32904448e7d40c7e833c7b381c86cd31", oauth_nonce="lCL%2FUM9o8go5XNVy4F7p%2FNxHJrY%2BvFNLhlzueFq8Juc%3D", oauth_signature="1b77fc6af54b2b51%26", oauth_signature_method="PLAINTEXT", oauth_timestamp="1455128674", oauth_token="", oauth_version="1.0"', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'FlickRaw/0.9.8'}).
     to_return(:status => 200, :body => "", :headers => {})

   ============================================================

有人知道我如何存根这个请求吗?

注意uri中的斜杠,你存根的请求不是正在发出的请求

注意uri中的斜杠,你存根的请求不是正在发出的请求

我使用flickraw缓存版本解决它。我使用flickraw缓存版本解决它。
Failures:

1) Dashboard::FlickrSearchController when user didn't set search tag returns recend photo
 Failure/Error: flickr.photos.getRecent(per_page: 10)

 WebMock::NetConnectNotAllowedError:
   Real HTTP connections are disabled. Unregistered request: POST https://api.flickr.com/services/rest/ with body 'method=flickr.reflection.getMethods&format=json&nojsoncallback=1' with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'OAuth realm="https://api.flickr.com/services/rest/", oauth_consumer_key="32904448e7d40c7e833c7b381c86cd31", oauth_nonce="lCL%2FUM9o8go5XNVy4F7p%2FNxHJrY%2BvFNLhlzueFq8Juc%3D", oauth_signature="1b77fc6af54b2b51%26", oauth_signature_method="PLAINTEXT", oauth_timestamp="1455128674", oauth_token="", oauth_version="1.0"', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'FlickRaw/0.9.8'}

   You can stub this request with the following snippet:

   stub_request(:post, "https://api.flickr.com/services/rest/").
     with(:body => {"format"=>"json", "method"=>"flickr.reflection.getMethods", "nojsoncallback"=>"1"},
          :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'OAuth realm="https://api.flickr.com/services/rest/", oauth_consumer_key="32904448e7d40c7e833c7b381c86cd31", oauth_nonce="lCL%2FUM9o8go5XNVy4F7p%2FNxHJrY%2BvFNLhlzueFq8Juc%3D", oauth_signature="1b77fc6af54b2b51%26", oauth_signature_method="PLAINTEXT", oauth_timestamp="1455128674", oauth_token="", oauth_version="1.0"', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'FlickRaw/0.9.8'}).
     to_return(:status => 200, :body => "", :headers => {})

   ============================================================