Rails Fixtures vs Mocks

I am developing a Rails application, and I just talked with a colleague about the fact that in our tests there is a mixture of devices and layouts that we make using cucumber and Rspec. The question will be: when should each of them be used?

+7
ruby-on-rails mocking fixtures
source share
1 answer

I would use a mock object, if using a real object is impractical / not necessary. Say, for example, you need to call some remote API, such as address search by zip code. You probably want to make fun of the object, so calls to it are not actually executed every time you run your tests. There are other reasons, such as improved speed, requesting data that changes where you need the exact answer, or perhaps it does not exist. This allows you to test the objects individually, since you can determine that when you call these methods on this mock object, you will get it back, and you really do not need to run the code, since this is not important for this test.

If you use devices, you will have a real object, and methods, etc. will be called, and their code will be launched, unless, of course, you drown the methods, something for another question.

Hope this helps. There is a good peepcode ( http://peepcode.com/products/rspec-mocks-and-models ) for mockery and knocking, maybe check this out.

+14
source share

All Articles