[rspec-users] Mock in lambda?

David Chelimsky dchelimsky at gmail.com
Sun Dec 26 00:25:15 EST 2010

On Sun, Dec 26, 2010 at 12:05 AM, Zhi-Qiang Lei <zhiqiang.lei at gmail.com> wrote:
> Hi,
> I have a lambda.
> Test = lambda { kill(333) }
> How should I spec if I want to make sure this Test will send kill message with 333? Thanks.

Depends on the scope in which the block will be evaluated. Since kill
is being called with no receiver, its implicit receiver will be the
object in which it is evaluated, so you can mock it on that object,

class Foo
  def bar

foo = Foo.new
foo.bar { kill(333) }

Not sure if that aligns with your situation, but that should give you an idea.


> Best regards,
> Zhi-Qiang Lei
> zhiqiang.lei at gmail.com
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list