Added some failing tests where the JSON encoder is not resolving as_json correctly

This commit is contained in:
Godfrey Chan 2013-11-15 10:26:12 -08:00
parent 499b602c8e
commit cfaa2aa99f

@ -18,8 +18,12 @@ def to_hash
end end
class Custom class Custom
def initialize(serialized)
@serialized = serialized
end
def as_json(options) def as_json(options)
'custom' @serialized
end end
end end
@ -81,7 +85,13 @@ def as_json(options={})
ObjectTests = [[ Foo.new(1, 2), %({\"a\":1,\"b\":2}) ]] ObjectTests = [[ Foo.new(1, 2), %({\"a\":1,\"b\":2}) ]]
HashlikeTests = [[ Hashlike.new, %({\"bar\":\"world\",\"foo\":\"hello\"}) ]] HashlikeTests = [[ Hashlike.new, %({\"bar\":\"world\",\"foo\":\"hello\"}) ]]
CustomTests = [[ Custom.new, '"custom"' ]] CustomTests = [[ Custom.new("custom"), '"custom"' ],
[ Custom.new(nil), 'null' ],
[ Custom.new(:a), '"a"' ],
[ Custom.new([ :foo, "bar" ]), '["foo","bar"]' ],
[ Custom.new({ :foo => "hello", :bar => "world" }), '{"bar":"world","foo":"hello"}' ],
[ Custom.new(Hashlike.new), '{"bar":"world","foo":"hello"}' ],
[ Custom.new(Custom.new(Custom.new(:a))), '"a"' ]]
RegexpTests = [[ /^a/, '"(?-mix:^a)"' ], [/^\w{1,2}[a-z]+/ix, '"(?ix-m:^\\\\w{1,2}[a-z]+)"']] RegexpTests = [[ /^a/, '"(?-mix:^a)"' ], [/^\w{1,2}[a-z]+/ix, '"(?ix-m:^\\\\w{1,2}[a-z]+)"']]