[rspec-users] should_receive break the method chain?

56 views
Skip to first unread message

Zhenning Guan

unread,
Jul 29, 2010, 8:46:50 AM7/29/10
to rspec...@rubyforge.org
class A
def process
@b.calculate
end
end


it 'should change b calculate value' do
@b.should_receive(:calculate)
@a.process

@b.calculae_value.should == 'after_calculae'
end

it will fail, if I comment out #@b.should_receive(:calculate), the test
pass,
or if comment out #@b.calculae_value.should == 'after_calculae', also
pass.

so my colleague said maybe should_receive break the mehod chain and
return.
thing is really going this way?
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

David Chelimsky

unread,
Jul 29, 2010, 9:31:48 AM7/29/10
to rspec...@rubyforge.org
On Jul 29, 2010, at 7:46 AM, Zhenning Guan wrote:

> class A
> def process
> @b.calculate
> end
> end
>
>
> it 'should change b calculate value' do
> @b.should_receive(:calculate)
> @a.process
>
> @b.calculae_value.should == 'after_calculae'
> end
>
> it will fail, if I comment out #@b.should_receive(:calculate), the test
> pass,
> or if comment out #@b.calculae_value.should == 'after_calculae', also
> pass.
>
> so my colleague said maybe should_receive break the mehod chain and
> return.
> thing is really going this way?

Your colleague is correct. Any time you use object.stub(:method) or object.should_receive(:method) on a real object, the method is replaced by the mock framework. This is true with all of the popular ruby mock/test double frameworks. The one way to get around that is to use RR's[1] proxy.

HTH,
David

[1] http://github.com/btakita/rr

Reply all
Reply to author
Forward
0 new messages