test/util_test.rb in jsi-0.2.1 vs test/util_test.rb in jsi-0.3.0
- old
+ new
@@ -9,23 +9,23 @@
actual = JSI.stringify_symbol_keys(JSI::JSON::Node.new_doc({a: 'b', 'c' => 'd', nil => 3}))
expected = JSI::JSON::Node.new_doc({'a' => 'b', 'c' => 'd', nil => 3})
assert_equal(expected, actual)
end
it 'stringifies JSI hash keys' do
- klass = JSI.class_for_schema(type: 'object')
- expected = JSI.stringify_symbol_keys(klass.new(JSI::JSON::Node.new_doc({a: 'b', 'c' => 'd', nil => 3})))
- actual = klass.new(JSI::JSON::Node.new_doc({'a' => 'b', 'c' => 'd', nil => 3}))
+ schema = JSI::Schema.new({type: 'object'})
+ expected = JSI.stringify_symbol_keys(schema.new_jsi({a: 'b', 'c' => 'd', nil => 3}))
+ actual = schema.new_jsi({'a' => 'b', 'c' => 'd', nil => 3})
assert_equal(expected, actual)
end
describe 'non-hash-like argument' do
it 'errors' do
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(nil) }
assert_equal("expected argument to be a hash; got NilClass: nil", err.message)
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(JSI::JSON::Node.new_doc(3)) }
assert_equal("expected argument to be a hash; got JSI::JSON::Node: #<JSI::JSON::Node fragment=\"#\" 3>", err.message)
- err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(JSI.class_for_schema({}).new(JSI::JSON::Node.new_doc(3))) }
- assert_match(%r(\Aexpected argument to be a hash; got JSI::SchemaClasses\["[^"]+#"\]: #<JSI::SchemaClasses\["[^"]+#"\]\n #<JSI::JSON::Node fragment="#" 3>\n>\z)m, err.message)
+ err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(JSI::Schema.new({}).new_jsi(3)) }
+ assert_equal("expected argument to be a hash; got (JSI Schema Class: #): #<JSI 3>", err.message)
end
end
end
describe '.deep_stringify_symbol_keys' do
it 'stringifies symbol hash keys' do
@@ -51,12 +51,12 @@
actual = JSI.deep_stringify_symbol_keys(JSI::JSON::Node.new_doc({a: 'b', 'c' => {d: 0}, nil => 3}))
expected = JSI::JSON::Node.new_doc({'a' => 'b', 'c' => {'d' => 0}, nil => 3})
assert_equal(expected, actual)
end
it 'deep stringifies JSI instance' do
- klass = JSI.class_for_schema(type: 'object')
- actual = JSI.deep_stringify_symbol_keys(klass.new(JSI::JSON::Node.new_doc({a: 'b', 'c' => {d: 0}, nil => 3})))
- expected = klass.new(JSI::JSON::Node.new_doc({'a' => 'b', 'c' => {'d' => 0}, nil => 3}))
+ schema = JSI::Schema.new(type: 'object')
+ actual = JSI.deep_stringify_symbol_keys(schema.new_jsi(JSI::JSON::Node.new_doc({a: 'b', 'c' => {d: 0}, nil => 3})))
+ expected = schema.new_jsi(JSI::JSON::Node.new_doc({'a' => 'b', 'c' => {'d' => 0}, nil => 3}))
assert_equal(expected, actual)
end
end
end