Testability is one of the reasons I try to keep myself away from observers 
or callbacks in general.

What's wrong with introducing plain ruby classes that wrapping up all those 
callback logics? Explicit over magics, no?

On Friday, 8 June 2012 22:14:32 UTC+10, Craig Read wrote:
>
> Thanks for the help guys. :)
>
> I figured when it started feeling like "hard work" that I was definitely 
> "doing it wrong". :o
>
> Craig...
>
> On Fri, Jun 8, 2012 at 9:13 PM, Malcolm Locke <[email protected]>wrote:
>
>> On Fri, Jun 08, 2012 at 12:49:08PM +1000, Craig Read wrote:
>> > How do you guys suggest testing observers via rspec?
>> > Or should I test the impacts my observers have via cucumber?
>>
>> You have probably discovered this already, but I've found observers need
>> a little voodoo to test directly, something like this:
>>
>>  describe MymodelObserver do
>>
>>    # Can't use the default subject, need to set it up like this
>>    subject { MymodelObserver.instance }
>>
>>    let(:mymodel) { mock_model(Mymodel) }
>>
>>    describe '#after_save' do
>>
>>      it "calls heavy_lifting() on the model" do
>>        mymodel.should_receive(:heavy_lifting)
>>        subject.after_save(mymodel)
>>      end
>>
>>    end
>>
>>  end
>>
>> This doesn't help you much with stubbing your where calls, but I plus
>> one Dave and Pat's advice on that.
>>
>> Malc
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby or Rails Oceania" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group at 
>> http://groups.google.com/group/rails-oceania?hl=en.
>>
>>
>
>
> -- 
> Craig Read
>
> @Catharz
> https://github.com/Catharz
> http://stackoverflow.com/users/158893/catharz
>
>  

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rails-oceania/-/gKcYfGpYlncJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to