2015-04-19 52 views
0

我正在使用webmock進行存根請求。 我使用下面的代碼存根請求。webmock自動檢測url中的`?`

stub_request(:delete, "https://graph.facebook.com/v2.0/1741/likes?access_token=this_is_a_test_token").to_return(body: "true") 

而且我得到以下錯誤: -

WebMock::NetConnectNotAllowedError: 
     Real HTTP connections are disabled. Unregistered request: DELETE https://graph.facebook.com/v2.0/1741/likes with body 'access_token=this_is_a_test_token' with headers {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'Date'=>'Sun, 19 Apr 2015 08:43:06 GMT', 'User-Agent'=>'FbGraph2 (0.5.0) (2.5.1, ruby 2.1.2 (2014-05-08))'} 

     You can stub this request with the following snippet: 

     stub_request(:delete, "https://graph.facebook.com/v2.0/1741/likes"). 
     with(:body => {"access_token"=>"this_is_a_test_token"}, 
       :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'Date'=>'Sun, 19 Apr 2015 08:43:06 GMT', 'User-Agent'=>'FbGraph2 (0.5.0) (2.5.1, ruby 2.1.2 (2014-05-08))'}). 
     to_return(:status => 200, :body => "", :headers => {}) 

     registered request stubs: 

     stub_request(:delete, "https://graph.facebook.com/v2.0/1741/likes?access_token=this_is_a_test_token") 

它,當我用http://...com/1741/likes我只是做存根要求的改變增加一個命名空間v2.0和測試用例破裂前的工作。

回答

2

您已更改了您要存根的網址。您應該使用with方法參數中指定的查詢參數顯示的消息進行存根!