You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error:
TestOrder#test_shipping_delay:
TypeError: nil can't be coerced into Fixnum
tester.rb:60:in +' tester.rb:60:inshipping_delay'
tester.rb:71:in `test_shipping_delay'
Apparently the stub didn't actually set things up such that @shipping_period has the value 7. The Partial Mocking example on the main page for Mocha shows something similar with stubbing an attr_accessor (the last test), so it doesn't seem like I'm doing something technically out of bounds.
I'm sure there are reasons why stubbing an attr_accessor could be considered wrong, or unadvisable, or not ideal. Setting those aside, am I doing something technically wrong to stub an attr_accessor, or is this an issue in Mocha?
Roy
The text was updated successfully, but these errors were encountered:
I'm sorry for the slow response - I've only just seen this, because my GitHub email notifications for this repo stopped working for some reason. I'll try to take a look at this as soon as I can. Cheers, James.
The problem in your example is that Order#shipping_delay is using the @shipping_period instance variable directly i.e. it is not calling the accessor "getter" method Order#shipping_period. If you remove the @ sign, I think your test will pass.
I'm going to close this issue for now, but feel free to re-open it if I haven't answered your question. If you have more questions about how to use Mocha, it might be better to use the mailing list.
Thanks, James. I believe you're right. Silly mistake on my part there. I'll try your suggestion. Odds are good it'll be a-okay. And thanks for the mailing list pointer. I'll ask future usage questions over there.
I'm new to Ruby and Mocha, so what I'm about to report could be user error. If so, please let me know.
I'm using minitest. Stubbing an attr_accessor for any_instances appears to have no effect at all. A small, contrived example:
That gives me this result:
TestOrder#test_shipping_delay:
TypeError: nil can't be coerced into Fixnum
tester.rb:60:in
+' tester.rb:60:in
shipping_delay'tester.rb:71:in `test_shipping_delay'
Apparently the stub didn't actually set things up such that @shipping_period has the value 7. The Partial Mocking example on the main page for Mocha shows something similar with stubbing an attr_accessor (the last test), so it doesn't seem like I'm doing something technically out of bounds.
I'm sure there are reasons why stubbing an attr_accessor could be considered wrong, or unadvisable, or not ideal. Setting those aside, am I doing something technically wrong to stub an attr_accessor, or is this an issue in Mocha?
Roy
The text was updated successfully, but these errors were encountered: