[rspec-users] Test Design Question #1
patmaddox at me.com
Thu Mar 31 03:52:25 EDT 2011
What do you mean that it's "leaking" into the other test? If you have transactions turned on, then any records inserted into the db will be removed for the next test.
My guess is that other tests just don't set up the required data...which is a problem with ActiveRecord callbacks and observers. In that case, you'll want to use a test data builder like fixjour or Factory Girl, so you only have to set up the data in one place. Another approach is to move your after_create code into an observer and use my no_peeping_toms gem which disables observers in tests (and makes you explicitly enable them, either all of them or individually). This way you can test your callbacks in the unit tests for that behavior, and disable them everywhere else.
On Mar 30, 2011, at 9:31 AM, Curtis j Schofield wrote:
> I have an model in rails with an after_create that generates another
> object (for the purpose of making an audit trail).
> In the unit test - i want to verify this behavior.
> This behaviour - in other tests is breaking some exceptions around
> (include) - since the creation of the new audit trail
> is leaking into this other unit test.
> In the controller test this behavior doesn't matter - in the
> integration test i do want this behavior.
> What am i doing wrong here?
> make haste slowly \
> festina lente \
> mobile +1_415_632_6001
> curtis.schofield at gmail.com
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users