You should be able to check message expectations on an instance of MyTask
.
For example,
it "is observable" do
task = MyTask.new
task.should_receive :add_observer
task.should_receive :changed
task.should_receive :notify_observers
task.perform
end
Ideally, I wouldn't do it this way since a lot of message expectations on the object under test are being made. Instead, I might check some external state that is a result of calling perform
.
EDIT
If you want to check instance methods on MyObserver
, you could do something like this, before calling perform
:
observer = mock
MyObserver.stub(:new).and_return(observer)
observer.should_receive(:some_method) #replace `some_method` with whatever instance method you want