Hi Everyone,

I have an observer which performs some calculations based on a number of
relationships (including polymorphic relationships) and stores (aka caches)
the results on a model related to the one being observed.

I ran into a bit of yak shaving while getting that observer adequately
tested (via rspec).
I started off using stubs, but finally ran into an issue where a
calculation was using a count of related rows using a "where" to filter the
relations.
The test barfed because the array of stubs I was (quite happily) using for
my other rspec tests wouldn't respond to where.

I tried for hours to fix this and got nowhere, so I ended up changing all
my spec helpers so they instantiated real models instead of stubs.
The tests now pass, I refactored my test code to be a little cleaner, and
the tests actually run a little faster (that bit has me stumped).
But I still feel dirty having those tests hit the database.

I have the rspec book, which covers testing models, controllers and views,
but says nothing about testing observers.

How do you guys suggest testing observers via rspec?
Or should I test the impacts my observers have via cucumber?

Cheers,

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