Search code examples
ruby-on-rails-3.2capybararspec2vcr

how to test bad network connection with rspec


I'd like to test for connection errors to an external api. What is the best way to go about and do this?

in my controller i have

begin
 result = connect.to_api
rescue Error::TooManyRequests => e
 flash = e
end

I'd like to test that the error gets displayed to the user.


Solution

  • Got my test to pass with

    Connect.should_receive(:to_api).and_raise(Error::TooManyRequests)