*sigh* There's a small, but meaningful difference between:
expect { my_thing.do_stuff }.to change(my_thing.my_value).to(some_value)
and
expect { my_thing.do_stuff }.to change{my_thing.my_value}.to(some_value)
(note the braces on the last line...)
*sigh* There's a small, but meaningful difference between:
expect { my_thing.do_stuff }.to change(my_thing.my_value).to(some_value)
and
expect { my_thing.do_stuff }.to change{my_thing.my_value}.to(some_value)
(note the braces on the last line...)
I've recently had to learn the other side of testing - ie rspec, due to my new contract having a test suite written in "the other testing suite" * ;)
Seems fairly straightforward so far, but there's one big worry I have: Rspec has a huge reliance upon mocks.
Now I completely understand (and endorse) the benefits of using mocks. It means you can independantly test a model/controller/whatever without it mattering if something happens to have broken in some other model/module/whatever. This is a Good Thing and allows for more accurate testing due to all the benefits of loose coupling. However, I get a bit worried if everything is mocked out and there are no integration-style tests at all.
For example, if I'm testing a view, and using rspec best practice I've mocked out all model objects and don't bother with the real thing. What happens if a model changes (say a column is removed that shows up on an index list)? The view specs all rely on a mock that explicitly states what is returned, so the view specs all still pass. But the index page will be broken for a user that actually uses the site, because the real object doesn't bahave that way anymore. The mocks and the model are out of synch. :P
In an infrequently-used area of the site, this sort of error may go undetected and slip through to release.
This worries me. I know I like to rely on my test suite to catch things like this wherever possible. Sure I generally do a manual click-through, but I know that this is unreliable especially WRT edge-cases.
So, am I needlessly worrying? Have I simply missed something about how rspec is supposed to be used? What's best practice in this situation?
*Which admittedly feels a lot like having to switch from vi to emacs... Sure I know that "the other one" works for lots of people, and I meant to get around to learning it someday...