提交 d2890f76 编写于 作者: A Andrew White

Use literal values in assertions

Using the method you're testing to generate expected
values can lead to bugs being masked.
上级 c85d305a
......@@ -434,24 +434,22 @@ def test_exception_to_json
class InfiniteNumber
def as_json(options = nil)
{ "number" => 1.0 / 0 }
{ "number" => Float::INFINITY }
end
end
def test_to_json_works_when_as_json_returns_infinite_number
expected = { number: nil }.to_json
assert_equal expected, InfiniteNumber.new.to_json
assert_equal '{"number":null}', InfiniteNumber.new.to_json
end
class NaNNumber
def as_json(options = nil)
{ "number" => 0.0 / 0 }
{ "number" => Float::INFINITY }
end
end
def test_to_json_works_when_as_json_returns_NaN_number
expected = { number: nil }.to_json
assert_equal expected, NaNNumber.new.to_json
assert_equal '{"number":null}', NaNNumber.new.to_json
end
protected
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册