mocking Observers is not cleaned up between tests #112

travisp opened this Issue Mar 1, 2012 · 4 comments


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 =
  FeedObserver.any_instance.should_receive(:after_create) #or FeedObserver.instance.should_receive(:after_create)!
it "creates a LogEvent" do
  obs = FeedObserver.instance
  expect {
  }.to change(TimelineEvent, :count).by(1)  

In the second test FeedObserver.instance returns a mocked object


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.


kaiwren commented Jun 1, 2012

@justinko Noted. I'll look into this.


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).


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