I am using webmock for stubbing requests. I stubbed a request using the following code.
stub_request(:delete, "https://graph.facebook.com/v2.0/1741/likes?access_token=this_is_a_test_token").to_return(body: "true")
And I get the following error :-
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")
It was working before when I used http://...com/1741/likes
I just made a change in the stub request for adding a namespace v2.0
and the test cases are broken.
You've changed the URL that you're stubbing. You should stub using the message displayed with the query params specified in the with
method arguments!