mocking Observers is not cleaned up between tests #112

Closed
travisp opened this Issue Mar 1, 2012 · 4 comments

Comments

Projects
None yet
5 participants

travisp commented Mar 1, 2012

This looks similar to issue 52: #52

Basically, if I am touching an observer (a singleton) in one test, it seems to affect another test. Example:

it "acts on the after_create notification" do
  thing = FactoryGirl.build(:thing)
  FeedObserver.any_instance.should_receive(:after_create) #or FeedObserver.instance.should_receive(:after_create)
  thing.save!
end
it "creates a LogEvent" do
  obs = FeedObserver.instance
  expect {
    obs.after_create(@thing)
  }.to change(TimelineEvent, :count).by(1)  
end

In the second test FeedObserver.instance returns a mocked object

Contributor

justinko commented Jun 1, 2012

@travisp Observers in Rails are "singletons" - FeedObserver.instance will always return the same instance. No need to use any_instance here. I tried mocking FeedObserver.instance and could not duplicate your error.

@kaiwren I did duplicate his code and got a SystemStackError on master. I'm sure there is a conflict between how observers are implemented and any_instance.

Contributor

kaiwren commented Jun 1, 2012

@justinko Noted. I'll look into this.

Owner

myronmarston commented Dec 19, 2012

@alindeman -- you pushed some fixes to any_instance a bit ago--do you think it fixed this issue? (I forget now what issues you fixed exactly).

Contributor

alindeman commented Dec 19, 2012

I believe a727464 should have fixed the SystemStackError portion, yes :)

alindeman closed this Dec 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment