Keith Tom
2007-Sep-26 03:50 UTC
[rspec-users] Testing record creation independently of implementation
Hi guys, I just had a question on testing a method whose behaviour includes creating a record in the database. How would one go about doing this? At first, it seems okay to cheat and just make sure that create() or new() is called with the correct parameters. So, @model.should_receive(:create).with(params) or, @model.should_receive(:new).with(params) But if I wanted to have it be implementation independent, then the only thing I can think of is to check the database at the end for the record I''m expecting, like, @model = Model.find_last_created @model.attributes.should be == params There are some assumptions here, but at least it is focussed on the end result of the record, and not so much how it was created. Any suggestions are really appreciated. Thanks in advance! Keith