[rspec-users] Stub that returns hash values

Stephen Eley sfeley at gmail.com
Wed Oct 21 14:18:42 EDT 2009


On Wed, Oct 21, 2009 at 1:12 PM, Carl Graff <cagraff at cox.net> wrote:
>
> In truth, due to my inexperience and confusion, mocks seem to slow my
> development more than just creating real objects. But since there has been
> so much effort to put these into testing frameworks, I think it must be
> important to try and learn when it is appropriate to use them.

That is a fallacious line of reasoning.  A lot of effort has also gone
into American football, every Michael Bay movie, and Windows Vista.
QED.

My suggestion on _any_ technology is not to use it in serious practice
unless you have a good idea _why_ you're using it and what it can
offer you.  "I want to play with this and determine what the fuss is"
can be a good reason -- provided you have the leisure to do so -- but
"All the hotshot programmers say it's important" is not sufficient and
_durable_ reason in itself.  If you don't know _why_ they say it, find
out.  If you're not sure you grok it, try it both ways, but be
objective about the results.  Don't hold onto a practice blindly.

If your testing so far seems to be going just fine without mocks and
you haven't hit any snags, great.  Maybe you're not hitting use cases
where they're really helpful.  Maybe you've figured out how to address
the same problems in other ways.  Heck, maybe everyone else is _wrong_
about them.  (This does in fact happen in software culture, though
it's easy to overestimate the likelihood.)  Do what works, as long as
it works.

When it *stops* working for you, or you advance enough in your own
proficiency that things you hadn't thought about before start to seem
questionable or annoying, be prepared to adapt and to try things.
Maybe at that point, mocks will be just what you need.


-- 
Have Fun,
   Steve Eley (sfeley at gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org


More information about the rspec-users mailing list