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)
describe Foo do
it "invokes #baz" do
expect_any_instance_of(Foo).to receive(:baz).and_return(20)
subject.baz
end
end
But this code is not much expressive than the first one I wrote. In the first
one, I stub the method, with return value.
Then I call it and matched all things with the expectations, which it seems no
more possible in Rspec.
--
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/53B98E8A.50202%40xaviershay.com.
For more options, visit https://groups.google.com/d/optout.