What argument should I pass for mock(), stub() and double()

Hi - I’m reading the RSpec book.

I see an example like:

customer = double(‘customer’)

What is the customer that is in the argument for?
How is this different from:

customer = double()

? Can anybody explain to me?

  • Jon

John,

I may well be wrong, but I believe it’s just a tag or name, so when
you
print out - you see <#Double customer> rather tahn something
inexplicable, that is at least how it appears to work using Mocha

  • Lee

On Oct 11, 2009, at 6:21 AM, Lee H. wrote:

John,

I may well be wrong, but I believe it’s just a tag or name, so
when you print out - you see <#Double customer> rather
tahn something inexplicable, that is at least how it appears to work
using Mocha

Not so much when you print it out, but when there is a failure and
rspec prints out a failure message for you. This is actually explained
in the book - on page 207 if you’ve got beta 10:

To create a double, just use the double( ) method, like this:

thingamajig_double = double(‘thing-a-ma-jig’)

The string argument is optional, but highly recommended as it is used
in failure messages.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs