Closed sporto closed 10 years ago
I thought it already did this :(
Maybe using expect
syntax doesn't go through same code path as should_receive
? I'll have to poke at it.
It has nothing to do with the syntax used. (Actually, we haven't yet add an expect
based syntax to rspec-mocks, but plan to). It has to do with the fact that rspec-fire checks arity when you constrain a mocked or stubbed method using with
. rspec-fire doesn't get involved at method invocation time; that's all rspec-mocks at that point, and when you stub a method using the hash syntax (e.g. f.stub(run: true)
) it doesn't constrain the number of arguments at all.
@myronmarston right
If I do
f.stub(:run).with(1).and_return(true)
It does check the number of arguments.
Any chance it could check even without the with
?
I think that should be possible if rspec-fire converted a call like f.stub(run: true)
into:
arity = f.method(:run).arity
f.stub(:run).with([anything] * arity).and_return(true)
(Of course, there's more to it than that to handle splats, default args, etc, but you get the point).
We addressed this in RSpec 3.
If I do
test passes, but I passed the wrong number of arguments to the method. It would be great if somehow this could be prevented.