topazproject/topaz — pull request #627 by gemoe100 (2013-04-17 09:33:56+00:00)
Title: Math type errors

Many files in spec/tags/core/math had a fail message that looked something like this:

fails:Math. raises a TypeError if the argument cannot be coerced with Float()

This happened although the methods in the class for the Math module were decorated like so (at least the ones taking one argument):

@moduledef.function("", value="float")

What happened was that Coerce.float delegated the conversion into a float to Float which raised an ArgumentError instead of the desired TypeError. Furthermore, a String like '1' or '2.0' was gladly accepted although ruby 1.9.3 also raises a TypeError in this case (this behaviour is not covered by rubyspec, so I wrote/modified some unittests in tests/modules/test_math.py).
In order to solve this problem I wrote a new method in Coerce, strictfloat. It will only delegate to Coerce.float if the input is an object representing a Ruby Numeric. Otherwise it will raise a TypeError. All methods in the Math module now only accept strictfloats rather than floats.
Thanks to this change a lot more specs in rubyspec/core/math now pass.