[rspec-users] Stub that returns hash values
Ashley Moran
ashley.moran at patchspace.co.uk
Fri Oct 23 03:24:38 EDT 2009
On 21 Oct 2009, at 19:18, Stephen Eley wrote:
> 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.
To be fair, Carl did say he wanted to "learn when it is appropriate to
use them" as opposed to just using them indiscriminately. And the
answer may be "never". I suppose it's quite possible that mocks do
suck, and we just haven't realised yet. But that's ok, they suck less
than inspecting instance variables, so I'm happy, at least.
What I would suggest is to not try to learn how to use mocks on
production code*, unless you have pretty thorough means of integration
testing. Incorrect mocking leads to brittle specs* and that leads to
hidden bugs* and thrashing during refactoring*.
In fact, if you don't use a tool such as Cucumber, I'd recommend
learning that over mocking first. (You don't need to use Cucumber,
but it's more suited for high-level descriptions than RSpec.) As
RSpec lets you refactor without risk of breaking units of code,
Cucumber lets you refactor your code and specs across units. That
gives you a metric on how well you're using mocks - unexpected
Cucumber failures indicate a faulty assumption somewhere. Of course,
that assumes your Cucumber features are solid...
Just my coin of small denomination. Other learning strategies are
available.
Ashley
* which was my situation
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/
More information about the rspec-users
mailing list