Jeremy Hageman wrote:
As someone relatively new to rspec, I am interested in hearing the
wisdom of the group in the area of using a fixture replacement gem
(such as machinist or factory girl) instead of mocking the model. To
me it seems that using a fixture replacement, instead of a mock, would
circumvent some of rspec's framework in a bad way. Or perhaps there
are certain places where a fixture replacement can be beneficial, and
certain places where only a mock will do?

Do many of you guys in the group use a fixture replacement?

As the author of FixtureReplacement (which I guess coined the term), I use one (it) all of the time.

Rails / AR is heavily centered around removing abstraction layers from the database - as such, most testing involves the database. Any one who has used mocking in this arena knows how brittle mocks in a rails app can become.

Mocking is used outside of rails for two reasons. The first is as a design tool. The idea behind that is that by defining the interfaces before the details you'll end up with a cleaner, more intuitve interface. The second is where it is necessary to do so, e.g., external API's etc.

But (full) mocking comes with a price - brittle specs. David C. has suggested in the past that after the implementation is complete, mocks could (and often should) be replaced with the real objects.

Most mocks used in a rails project server neither of these purposes. Primarily they are used for speed - which so far has been the primary trade off with using a fixture replacement (such as FixtureReplacement, FactoryGirl, etc).

Those who advocate mocking all find the need for a higher level coverage tool, such as cucumber, etc. Either way (until a better solution, such as guillotine becomes available), you'll end up running a slow-ish test suite.

Regards,

Scott
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to