Mock in lambda?

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.

Best regards,
Zhi-Qiang L.
[email protected]

On Sun, Dec 26, 2010 at 12:05 AM, Zhi-Qiang L. [email protected]
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,
e.g:

class Foo
def bar
yield
end
end

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

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

HTH,
David

Hi,

I’m trying to mock the scope.

Test = lambda { kill(333) }
app = double(“test”)
app.should_receive(:kill).with(333).once
app.instance_eval Test

It will say that kill method miss in app. And to stub a kill method will
not help. Can I only define a new class to test it? Thanks.

On Dec 26, 2010, at 1:25 PM, David C. wrote:

is being called with no receiver, its implicit receiver will be the
foo.should_receive(:kill)


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Best regards,
Zhi-Qiang L.
[email protected]

Sorry, it is my codes’ fault. It works now.

On Dec 26, 2010, at 3:47 PM, Zhi-Qiang L. wrote:

Zhi-Qiang L.
http://rubyforge.org/mailman/listinfo/rspec-users

Best regards,
Zhi-Qiang L.
[email protected]

Best regards,
Zhi-Qiang L.
[email protected]