CaseyJones CaseyJones - 4 months ago 25
Ruby Question

rspec stubbing passing the same arguments

Sample code:

class Foo
def initialize(abc)
@abc = abc
@bind = bar
def bar

Now I want to stub bar using rspec and custom stub:

allow('Foo').to receive(:bar).and_return(

The issue is that the
has to be initialize with the same arguments
receives. Is it possible to get a copy of params passed to
at the time we are stubbing and reuse them in the stub class?


Not sure why you want to do what you're doing (probably there is a simpler way), but for what it's worth:

allow("Foo").to receive(:bar) { |arg1, arg2|, arg2) }

RSpec docs, block stub implementation