[rspec-users] Adding stubs for an included argument
edvard.majakari at gmail.com
Tue Jan 5 05:09:32 EST 2010
My scenario is as follows, and so far I have not found the clean way
to implement the following.
In a method I have a method called allowed_for?(*args) used as
if o.allowed_for?(:foo, :bar)
elsif o.allowed_for(:quux, :bif)
now in the spec, I'd like to say something like
obj.stub!(:allowed_for? => false)
that is, if allowed_for? is called with varargs containing :foo it
should return true, false otherwise.
At the moment the only way I can make the spec to run is to create
exact expectation, which is a bit too tightly coupled to the
obj.should_receive(:allowed_for?).with(:foo, :bar).and_return ...
another solution would wrap allow_for?(*args) into a single method
call without parameter names and stubbing the wrapper methods:
but I don't like it - the rules are simple and the whole method is now
quite readable as it is. Creating one-line private methods would IMO
add superfluous cruft and reduce legibility.
More information about the rspec-users