James Mead
2007-Feb-02 13:12 UTC
[mocha-developer] Fwd: [ mocha-Bugs-7834 ] infinte_range.rb makes incorrect assumption about to_f
Thanks for reporting the bug below. You''re absolutely right. Renamed Range#to_s implementation to #mocha_inspect and checked first and last respond_to?(:to_f) as you suggested. Sorry for the delay - I wasn''t monitoring the rubyforge trackers. I am now! Should be fixed in revision 99 of trunk. -- James. http://blog.floehopper.org ---------- Forwarded message ---------- From: noreply at rubyforge.org <noreply at rubyforge.org> Date: 02-Feb-2007 13:07 Subject: [ mocha-Bugs-7834 ] infinte_range.rb makes incorrect assumption about to_f To: noreply at rubyforge.org Bugs item #7834, was opened at 2007-01-15 04:21 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=7477&aid=7834&group_id=1917 Category: None Group: None>Status: ClosedResolution: None Priority: 3 Submitted By: James Moore (banshee) Assigned to: Nobody (None) Summary: infinte_range.rb makes incorrect assumption about to_f Initial Comment: infinite_range.rb assumes that first and last elements of a Range respond to to_f: def to_s if first.to_f.infinite? then return "at most #{last}" elsif last.to_f.infinite? then return "at least #{first}" else __to_s__ end end This is incorrect - Ranges can include any objects that implement <=> and succ; converting objects to float values isn''t a safe assumption. (I hit this with a range of Date objects) The simple fix is to see if the object responds to to_f: def to_s if first.respond_to?(:to_f) && first.to_f.infinite? return "at most #{last}" elsif last.respond_to?(:to_f) && last.to_f.infinite? return "at least #{first}" else __to_s__ end end But it''s suprising to me that mocha would do something like change the behavior of to_s for a widely-used class like Range. My real fix would be to remove to_s completely. ---------------------------------------------------------------------->Comment By: James Mead (jamesmead)Date: 2007-02-02 13:07 Message: You''re absolutely right. Renamed Range#to_s implementation to #mocha_inspect and checked first and last respond_to?(:to_f) as you suggested. Sorry for the delay - I wasn''t monitoring these trackers. Should be fixed in revision 99 of trunk. ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=7477&aid=7834&group_id=1917
Reasonably Related Threads
- Fwd: [ mocha-Feature Requests-15021 ] without or not params matcher
- Fwd: [ mocha-Bugs-16523 ] Ruby 1.9 gives warning
- Fwd: [ mocha-Bugs-12001 ] Method call count is not reported correctly on error
- Fwd: [ mocha-Bugs-11885 ] never doesn''t work with stub_everything
- Fwd: [ mocha-Bugs-6416 ] Mock objects shouldn''t define #to_s