Hello all,
I am attempting to use a basic stub_request to simulate an error 500 when making a web request. Unfortunately I was not able to understand how to get this to work. I was wondering if anyone can tell me what I am missing.
My current code I have for the moment is:
context 'an invalid connection' do
it 'should return an error message in error array' do
stub_request(:any, "http://api.openweathermap.org/").to_return(:status => [500, "Internal Server Error"])
end
end
The error I am getting is:
Failures:
1) OpenWeatherMapWrapper#current_weather an invalid connection should return an error message in error array
Failure/Error: stub_request(:any, "http://api.openweathermap.org/").to_return(:status => [500, "Internal Server Error"])
NoMethodError:
undefined method `stub_request' for #<RSpec::ExampleGroups::OpenWeatherMapWrapper::CurrentWeather::AnInvalidConnection:0x007fa92c430418>
# ./spec/apis/open_weather_map_wrapper_spec.rb:22:in `block (4 levels) in <top (required)>
I tried adding
But that didn't seem to address the issue.
The end result is that I would be able to stub the request to the root url and then expect to get the error 500 for the test to pass.
Any help is greatly appreciated.
Thanks,