Hi Barun,
Here is my take on this...

Why are you mocking methods on the object under test? The aim of BDD is to
specify the behaviour of the class. When you are mocking, the intention is
to spec one object in isolation. When you define expectations between
objects you are specifying object interaction.

Mocking method on the object under test ties your spec to your
implementation. If you decided to implement 'methodA' in some other way that
lead to the same behaviour, then your specs shuould still pass. In your case
they would not.

Cheers
Nigel

2009/4/11 Barun Singh <baru...@gmail.com>

> A model I'm trying to spec looks something like this
>
> class MyClass
>   def methodA
>     do some stuff
>     methodB
>   end
>
>   def methodB
>     do some stuff
>   end
> end
>
> my spec looks something like this:
>
> x = MyClass.new
> x.should_receive(:methodB)
> lambda{ x.methodA }
>
> In the situation outlined above, the spec fails.  But, if I change the
> definition of methodA to be as follows the spec passes (note the addition of
> "self" as the receiver):
>
> def methodA
>   do some stuff
>   self.methodB
> end
>
>
> The code doesn't actually need for me to identify "self" as the receiver on
> order for it to work.  But rSpec seems to require this.  Is there an
> alternative way to write the spec so that it passes in the original case
> (where I call methodB without an explicit receiver)?
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to