Instances stubbed with `any_instance` blow up when used after spec is finished
Created by: kylewelsby
Linked with #85 (closed)
I don't believe this issue to be completely resolved.
Stubbing the connection to raise ActiveResource::TimeoutError
allows the current example to pass as expected, any subsequent examples will fail with a SystemStackError
.
Here we have a testing example which proves the failure.
require 'active_resource'
class Person < ActiveResource::Base
self.site = "http://example.com"
self.timeout = 4
end
describe Person do
before do
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people.xml", {}
end
end
it "rescues from Timeout" do
ActiveResource::Connection.any_instance.stub(:request).
and_raise(ActiveResource::TimeoutError.new("Nope taken too long"))
expect{
Person.find(:all)
}.to raise_error(ActiveResource::TimeoutError, 'Nope taken too long')
end
it "doesn't raise system stack error" do
expect{
Person.find(:all).should be_an_instance_of Array
}.to_not raise_error(SystemStackError, "stack level too deep")
end
end
Rails 3.2.7
Ruby
- ruby 1.8.7 (2012-02-08 MBARI 8/0x6770 on patchlevel 358) [i686-darwin11.3.0], MBARI 0x6770, Ruby Enterprise Edition 2012.02
- ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]