On Mon, Aug 24, 2009 at 12:56 PM, Alex Chaffee<[email protected]> wrote: > ...and, while I was composing that message, Brian sent me the following: > >> Rspec does provide the be_close matcher. See cheat rspec. > > @temperature.ctof(37).should be_close(98.6, 0.1) > > This will work (I'll go update the code now) but it still leaves the > problem I mentioned that if you are unfamiliar with the vagaries of > floating point math -- or even if you momentarily forget -- then using > == will occasionally mysteriously fail. So my proposal remains: can > the == matcher do be_close(x, 0.0000000001) for floats? Arguments pro > and con?
What about a helpful error message when "should ==" fails on floats: expected 98.6, got 98.6 The expected and actual may appear to be the same due to Ruby's string representation of floating point numbers. For floating point math, we recommend using the be_close() matcher instead. ??? > > --- > Alex Chaffee - [email protected] - http://alexch.github.com > Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch | > http://alexch.tumblr.com _______________________________________________ rspec-users mailing list [email protected] http://rubyforge.org/mailman/listinfo/rspec-users
