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 :-

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.



-- 
================
Regards,
Arup Rakshit
================
Debugging is twice as hard as writing the code in the first place. Therefore, 
if you write the code as cleverly as possible, you are, by definition, not 
smart enough to debug it.

--Brian Kernighan

-- 
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/3844040.rnviGAYIHu%40linux-wzza.site.
For more options, visit https://groups.google.com/d/optout.

Reply via email to