test/base_test.rb in jsi-0.0.1 vs test/base_test.rb in jsi-0.0.2

- old
+ new

@@ -49,16 +49,16 @@ assert_equal(schema.schema_id, JSI.class_for_schema(schema).schema_id) end end describe 'module for schema .inspect' do it '.inspect' do - assert_match(%r(\A#<Module for Schema: .+#>\z), JSI.module_for_schema(schema).inspect) + assert_match(%r(\A#<Module for Schema: .+#>\z), JSI::SchemaClasses.module_for_schema(schema).inspect) end end describe 'module for schema .schema' do it '.schema' do - assert_equal(schema, JSI.module_for_schema(schema).schema) + assert_equal(schema, JSI::SchemaClasses.module_for_schema(schema).schema) end end describe 'SchemaClasses[]' do it 'stores the class for the schema' do assert_equal(JSI.class_for_schema(schema), JSI::SchemaClasses[schema.schema_id]) @@ -79,24 +79,24 @@ end it 'returns a class from a Base' do assert_equal(JSI.class_for_schema(schema), JSI.class_for_schema(JSI.class_for_schema({}).new(schema.schema_node))) end end - describe '.module_for_schema' do + describe 'JSI::SchemaClasses.module_for_schema' do it 'returns a module from a schema' do - module_for_schema = JSI.module_for_schema(schema) + module_for_schema = JSI::SchemaClasses.module_for_schema(schema) # same module every time - assert_equal(JSI.module_for_schema(schema), module_for_schema) + assert_equal(JSI::SchemaClasses.module_for_schema(schema), module_for_schema) end it 'returns a module from a hash' do - assert_equal(JSI.module_for_schema(schema), JSI.module_for_schema(schema.schema_node.content)) + assert_equal(JSI::SchemaClasses.module_for_schema(schema), JSI::SchemaClasses.module_for_schema(schema.schema_node.content)) end it 'returns a module from a schema node' do - assert_equal(JSI.module_for_schema(schema), JSI.module_for_schema(schema.schema_node)) + assert_equal(JSI::SchemaClasses.module_for_schema(schema), JSI::SchemaClasses.module_for_schema(schema.schema_node)) end it 'returns a module from a Base' do - assert_equal(JSI.module_for_schema(schema), JSI.module_for_schema(JSI.class_for_schema({}).new(schema.schema_node))) + assert_equal(JSI::SchemaClasses.module_for_schema(schema), JSI::SchemaClasses.module_for_schema(JSI.class_for_schema({}).new(schema.schema_node))) end end describe 'initialization' do describe 'on Base' do it 'errors' do @@ -105,28 +105,28 @@ end end describe 'nil' do let(:instance) { nil } it 'initializes with nil instance' do - assert_equal(JSI::JSON::Node.new_by_type(nil, []), subject.instance) + assert_equal(JSI::JSON::Node.new_doc(nil), subject.instance) assert(!subject.respond_to?(:to_ary)) assert(!subject.respond_to?(:to_hash)) end end describe 'arbitrary instance' do let(:instance) { Object.new } it 'initializes' do - assert_equal(JSI::JSON::Node.new_by_type(instance, []), subject.instance) + assert_equal(JSI::JSON::Node.new_doc(instance), subject.instance) assert(!subject.respond_to?(:to_ary)) assert(!subject.respond_to?(:to_hash)) end end describe 'hash' do let(:instance) { {'foo' => 'bar'} } let(:schema_content) { {'type' => 'object'} } it 'initializes' do - assert_equal(JSI::JSON::Node.new_by_type({'foo' => 'bar'}, []), subject.instance) + assert_equal(JSI::JSON::Node.new_doc({'foo' => 'bar'}), subject.instance) assert(!subject.respond_to?(:to_ary)) assert(subject.respond_to?(:to_hash)) end end describe 'JSI::JSON::Hashnode' do @@ -140,11 +140,11 @@ end describe 'array' do let(:instance) { ['foo'] } let(:schema_content) { {'type' => 'array'} } it 'initializes' do - assert_equal(JSI::JSON::Node.new_by_type(['foo'], []), subject.instance) + assert_equal(JSI::JSON::Node.new_doc(['foo']), subject.instance) assert(subject.respond_to?(:to_ary)) assert(!subject.respond_to?(:to_hash)) end end describe 'JSI::JSON::Arraynode' do @@ -166,12 +166,12 @@ assert_equal(JSI::JSON::HashNode.new({'foo' => 'bar'}, []), subject.instance) end end end describe '#parents, #parent' do - let(:schema_content) { {properties: {foo: {properties: {bar: {properties: {baz: {}}}}}}} } - let(:document) { {foo: {bar: {baz: {}}}} } + let(:schema_content) { {'properties' => {'foo' => {'properties' => {'bar' => {'properties' => {'baz' => {}}}}}}} } + let(:document) { {'foo' => {'bar' => {'baz' => {}}}} } describe 'no parents' do it 'has none' do assert_equal([], subject.parents) assert_equal(nil, subject.parent) end @@ -315,11 +315,11 @@ 'schema' => 'hi', } end it 'does not define readers' do assert_equal('bar', subject.foo) - assert_equal(JSI.module_for_schema(subject.schema), subject.method(:foo).owner) + assert_equal(JSI::SchemaClasses.module_for_schema(subject.schema), subject.method(:foo).owner) assert_equal(JSI::Base, subject.method(:initialize).owner) assert_equal('hi', subject['initialize']) assert_match(%r(\A#\{<JSI::SchemaClasses\[".*#"\].*}\z)m, subject.inspect) assert_equal('hi', subject['inspect']) @@ -375,13 +375,13 @@ assert_match(%r(\A#<JSI::SchemaClasses\["[^"]+#"\]\n #<JSI::JSON::Node fragment="#" #<Object:[^<>]*>>\n>\z), subject.pretty_inspect.chomp) end end describe '#as_json' do it '#as_json' do - assert_equal({'a' => 'b'}, JSI.class_for_schema({}).new(JSI::JSON::Node.new_by_type({'a' => 'b'}, [])).as_json) - assert_equal({'a' => 'b'}, JSI.class_for_schema({'type' => 'object'}).new(JSI::JSON::Node.new_by_type({'a' => 'b'}, [])).as_json) - assert_equal(['a', 'b'], JSI.class_for_schema({'type' => 'array'}).new(JSI::JSON::Node.new_by_type(['a', 'b'], [])).as_json) - assert_equal(['a'], JSI::class_for_schema({}).new(['a']).as_json(some_option: true)) + assert_equal({'a' => 'b'}, JSI.class_for_schema({}).new(JSI::JSON::Node.new_doc({'a' => 'b'})).as_json) + assert_equal({'a' => 'b'}, JSI.class_for_schema({'type' => 'object'}).new(JSI::JSON::Node.new_doc({'a' => 'b'})).as_json) + assert_equal(['a', 'b'], JSI.class_for_schema({'type' => 'array'}).new(JSI::JSON::Node.new_doc(['a', 'b'])).as_json) + assert_equal(['a'], JSI.class_for_schema({}).new(['a']).as_json(some_option: true)) end end describe 'overwrite schema instance with instance=' do # this error message indicates an internal bug (hence Bug class), so there isn't an intended way to # trigger it using JSI::Base properly. we use it improperly just to test that code path. this