On 6/07/2014 11:16 am, Arup Rakshit wrote:
Nice to know. Could you elaborate what is the diff between
*expect_any_instance_of* and *allow_any_instance_of* ... Which one to use
in what case... Example code may help also for better understanding....
in your words, allow_any = stubbing, expect_any = expectation
This is described here:
https://relishapp.com/rspec/rspec-mocks/v/3-0/docs/working-with-legacy-code/
any-instance (follow the links to "Allow" and "Expect")
Cheers,
Xavier
That's helpful really. I am going through the Relish doco page by page. So
still couldn't reach to the page you linked. :-) But I got it clear. It seems,
I can change these 2 methods interchangeably. No difference in their use. Both
will run happily :-
RSpec.describe "allow_any_instance_of" do
context "with receive_messages" do
it "stubs multiple methods" do
allow_any_instance_of(Object).to receive_messages(:foo => 'foo', :bar =>
'bar')
o = Object.new
expect(o.foo).to eq('foo')
expect(o.bar).to eq('bar')
end
end
end
and
RSpec.describe "allow_any_instance_of" do
context "with receive_messages" do
it "stubs multiple methods" do
expect_any_instance_of(Object).to receive_messages(:foo => 'foo', :bar
=> 'bar')
o = Object.new
expect(o.foo).to eq('foo')
expect(o.bar).to eq('bar')
end
end
end
Only difference remains on people, who like allow_*, will use this, who don't
like it, will use expect_* ... :-)
`expect_` will raise if the message is never received, allow won't.
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/53B9DDA2.9010905%40xaviershay.com.
For more options, visit https://groups.google.com/d/optout.