[rspec-users] message expectations without explicit receiver

David Chelimsky dchelimsky at gmail.com
Fri Apr 10 17:39:08 EDT 2009


On Fri, Apr 10, 2009 at 3:43 PM, Barun Singh <barunio at gmail.com> wrote:
> 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 }

Why the lambda? Is it ever called? The following works as expected:

class Foo
  def bar
    baz
  end

  def baz
  end
end

describe "a message expectation on the same object" do
  it "works just fine" do
    foo = Foo.new
    foo.should_receive(:baz)
    foo.bar
  end
end

- David

>
> 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)?

Something

>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list