On 6/07/2014 10:15 am, Arup Rakshit wrote:
On Sunday, July 06, 2014 10:59:38 AM Xavier Shay wrote:
On 6/07/2014 9:45 am, Arup Rakshit wrote:
On Sunday, July 06, 2014 09:23:06 AM Antonio Antillon wrote:
Hi Arup,
try doing this in your foo_spec.rb
describe Foo do
before { allow(Foo).to receive(:baz).and_return(20) }
# all other lines as they are
end
Basically this example is a small part of my actual code. I generally
sometime don't want to call the original method, rather I stub it, the
way I set the example in my original post. Then from the example, I call
the method and expect it to show the same behavior the way I stubbed it.
In Rspec 3 it seems *stubbing* is not possible. *stubbing* and
*expectation* is merged in the same line of code, like below and it works
too :-
This is what `allow` does. It is different from `expect`. Try it:
allow_any_instance_of(Foo).to receive(:baz).and_return(20)
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
--
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/53B995CC.3020505%40xaviershay.com.
For more options, visit https://groups.google.com/d/optout.