diff --git a/json-schema_builder.gemspec b/json-schema_builder.gemspec index 040ee6f..7df32fc 100644 --- a/json-schema_builder.gemspec +++ b/json-schema_builder.gemspec @@ -26,4 +26,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'appraisal' spec.add_dependency 'activesupport', '>= 4.0' spec.add_dependency 'json-schema', '>= 2.1' + spec.add_dependency 'ostruct' end diff --git a/lib/json/schema_builder/rspec_helper/deep_open_struct.rb b/lib/json/schema_builder/rspec_helper/deep_open_struct.rb index b6ceb31..166e4c4 100644 --- a/lib/json/schema_builder/rspec_helper/deep_open_struct.rb +++ b/lib/json/schema_builder/rspec_helper/deep_open_struct.rb @@ -3,12 +3,8 @@ module SchemaBuilder module RSpecHelper class DeepOpenStruct < OpenStruct def initialize(hash = { }) - @table = { } - hash.each_pair do |key, value| - key = key.to_sym - @table[key] = _transform value - new_ostruct_member key - end + transformed = hash.transform_keys(&:to_sym).transform_values { |v| _transform(v) } + super(transformed) end def ==(other) diff --git a/spec/unit/dsl_spec.rb b/spec/unit/dsl_spec.rb index 2105f13..6226ef0 100644 --- a/spec/unit/dsl_spec.rb +++ b/spec/unit/dsl_spec.rb @@ -27,12 +27,12 @@ def initialize(*args); end end it 'should dispatch to entity' do - expect(instance).to receive(:entity).with(:something, 1, foo: :bar).and_call_original + expect(instance).to receive(:entity).with(:something, 1, { foo: :bar }).and_call_original instance.something 1, foo: :bar end it 'should allow unnamed entities' do - expect(instance).to receive(:entity).with(:something, nil, foo: :bar).and_call_original + expect(instance).to receive(:entity).with(:something, nil, { foo: :bar }).and_call_original instance.something foo: :bar end end @@ -60,7 +60,7 @@ def initialize(*args); end it 'should set the parent' do expect(instance.class).to receive(:new) - .with('name', parent: kind_of(klass)).and_call_original + .with('name', { parent: kind_of(klass) }).and_call_original entity = instance.entity :something, 'name' expect(entity).to be_a klass diff --git a/spec/unit/entity_spec.rb b/spec/unit/entity_spec.rb index 8b5e45e..913a3a2 100644 --- a/spec/unit/entity_spec.rb +++ b/spec/unit/entity_spec.rb @@ -130,7 +130,7 @@ def example it "should #{ validator }" do expect(JSON::Validator).to receive(validator) - .with subject.as_json, { }, working: true, opts: true + .with subject.as_json, { }, { working: true, opts: true } subject.send validator, { }, opts: true end end diff --git a/spec/unit/schema_spec.rb b/spec/unit/schema_spec.rb index 1a9b8f3..4567d21 100644 --- a/spec/unit/schema_spec.rb +++ b/spec/unit/schema_spec.rb @@ -181,7 +181,7 @@ def example describe "##{ validator }" do it "should #{ validator }" do expect(JSON::Validator).to receive(validator) - .with schema.as_json, { }, opts: true + .with schema.as_json, { }, { opts: true } schema.send validator, { }, opts: true end end