[rspec-users] Can't use #exactly when #and_return influences it.
pangel.neu at gmail.com
Thu Nov 1 08:54:45 EDT 2007
Yes this would make sense, or the mock could just stop sending the values as
soon as it does not receive messages anymore.
Obviously I prefer this second behaviour because it would, I think, make my
specs work correctly. But from a logical point of view as well, this works
for me. If the mock complains when there's more return values than expected
calls, it would reduce the amount of errors, but it's usually a one-liner so
the risk is not that great. On the other hand the second possibility (just
stop sending values) would introduce a flexibility that might be handy in
I'm quite a beginner in both ruby and TDD/BDD concepts so I feel like
there's a lot I just don't have a full grasp on anyway.
Regarding my specs do you think I should structure the whole thing
David Chelimsky-2 wrote:
> On Nov 1, 2007 5:26 AM, pangel <pangel.neu at gmail.com> wrote:
>> I want my class Reader to loop on the content of its Stack until false is
>> returned. I also want an optional argument to exist that limits how many
>> times the stack will be read, even if some elements are left. I was
>> to spec this last bit but ended up on a false positive.
>> Hope the example will be clear enough:
>> describe Reader do
>> it "should stop reading items when called with a limit" do
>> @stack = mock(Stack)
> This should probably not be allowed.
>> @reader = Reader.new
>> # reader.rb
>> class Reader
>> def initialize
>> @stack = Stack.new
>> def read_stack(limit = 0) #0 = read until false is returned
>> while val = @stack.read
>> # Not implemented on purpose!
>> # return if limit == 0
>> # limit -= limit
>> So the test should fail, because the use of the limit argument has not
>> implemented yet and #read gets called 7 times. But the test actually
>> I looked into it a bit and it seems that number of arguments in
>> overrides the arguments of #exactly.
>> Did I misunderstand the point of #exactly or should I build my code
>> differently so that the value returned by #and_return does not influence
>> many times #read is called?
> I think this is a bug, but the question is - what is the bug? I think
> the mock should complain when you set exactly(n).times and then give
> it a different number of return values.
> rspec-users mailing list
> rspec-users at rubyforge.org
View this message in context: http://www.nabble.com/Can%27t-use--exactly-when--and_return-influences-it.-tf4730412.html#a13528094
Sent from the rspec-users mailing list archive at Nabble.com.
More information about the rspec-users