diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/hashie/dash_spec.rb | 17 | ||||
-rw-r--r-- | spec/hashie/extensions/coercion_spec.rb | 23 | ||||
-rw-r--r-- | spec/hashie/extensions/deep_find_spec.rb | 15 | ||||
-rw-r--r-- | spec/hashie/extensions/deep_locate_spec.rb | 3 | ||||
-rw-r--r-- | spec/hashie/extensions/deep_merge_spec.rb | 4 | ||||
-rw-r--r-- | spec/hashie/hash_spec.rb | 21 | ||||
-rw-r--r-- | spec/hashie/mash_spec.rb | 10 | ||||
-rw-r--r-- | spec/hashie/trash_spec.rb | 12 | ||||
-rw-r--r-- | spec/integration/elasticsearch/integration_spec.rb | 3 | ||||
-rw-r--r-- | spec/integration/rails/integration_spec.rb | 5 |
10 files changed, 81 insertions, 32 deletions
diff --git a/spec/hashie/dash_spec.rb b/spec/hashie/dash_spec.rb index 5c34eb5..5c49026 100644 --- a/spec/hashie/dash_spec.rb +++ b/spec/hashie/dash_spec.rb @@ -265,11 +265,13 @@ describe DashTest do end it 'fails with non-existent properties' do - expect { subject.merge(middle_name: 'James') }.to raise_error(*no_property_error('middle_name')) + expect { subject.merge(middle_name: 'James') } + .to raise_error(*no_property_error('middle_name')) end it 'errors out when attempting to set a required property to nil' do - expect { subject.merge(first_name: nil) }.to raise_error(*property_required_error('first_name')) + expect { subject.merge(first_name: nil) } + .to raise_error(*property_required_error('first_name')) end context 'given a block' do @@ -368,8 +370,12 @@ describe DashTest do let(:params) { { first_name: 'Alice', email: 'alice@example.com' } } context 'when there is coercion' do - let(:params_before) { { city: 'nyc', person: { first_name: 'Bob', email: 'bob@example.com' } } } - let(:params_after) { { city: 'sfo', person: { first_name: 'Alice', email: 'alice@example.com' } } } + let(:params_before) do + { city: 'nyc', person: { first_name: 'Bob', email: 'bob@example.com' } } + end + let(:params_after) do + { city: 'sfo', person: { first_name: 'Alice', email: 'alice@example.com' } } + end subject { DashWithCoercion.new(params_before) } @@ -516,7 +522,8 @@ describe ConditionallyRequiredTest do end it 'allows a conditionally required property to be set if required' do - expect { ConditionallyRequiredTest.new(username: 'bob.smith', password: '$ecure!') }.not_to raise_error + expect { ConditionallyRequiredTest.new(username: 'bob.smith', password: '$ecure!') } + .not_to raise_error end end diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb index da7d7c8..72265e1 100644 --- a/spec/hashie/extensions/coercion_spec.rb +++ b/spec/hashie/extensions/coercion_spec.rb @@ -459,8 +459,12 @@ describe Hashie::Extensions::Coercion do coerce_key :categories, Array[CategoryHash] end - let(:category) { CategoryHash.new(type: 'rubygem', products: [Hashie::Mash.new(name: 'Hashie')]) } - let(:product) { ProductHash.new(name: 'Hashie', categories: [Hashie::Mash.new(type: 'rubygem')]) } + let(:category) do + CategoryHash.new(type: 'rubygem', products: [Hashie::Mash.new(name: 'Hashie')]) + end + let(:product) do + ProductHash.new(name: 'Hashie', categories: [Hashie::Mash.new(type: 'rubygem')]) + end it 'coerces CategoryHash[:products] correctly' do expected = [ProductHash] @@ -560,23 +564,26 @@ describe Hashie::Extensions::Coercion do it 'raises a CoercionError when coercion is not possible' do type = - if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= Hashie::Extensions::RubyVersion.new('2.4.0') + if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= + Hashie::Extensions::RubyVersion.new('2.4.0') Integer else - Fixnum # rubocop:disable Lint/UnifiedInteger + Fixnum end subject.coerce_value type, Symbol - expect { instance[:hi] = 1 } - .to raise_error(Hashie::CoercionError, /Cannot coerce property :hi from #{type} to Symbol/) + expect { instance[:hi] = 1 }.to raise_error( + Hashie::CoercionError, /Cannot coerce property :hi from #{type} to Symbol/ + ) end it 'coerces Integer to String' do type = - if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= Hashie::Extensions::RubyVersion.new('2.4.0') + if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= + Hashie::Extensions::RubyVersion.new('2.4.0') Integer else - Fixnum # rubocop:disable Lint/UnifiedInteger + Fixnum end subject.coerce_value type, String diff --git a/spec/hashie/extensions/deep_find_spec.rb b/spec/hashie/extensions/deep_find_spec.rb index 87f8457..cd13d7f 100644 --- a/spec/hashie/extensions/deep_find_spec.rb +++ b/spec/hashie/extensions/deep_find_spec.rb @@ -36,7 +36,8 @@ describe Hashie::Extensions::DeepFind do describe '#deep_find_all' do it 'detects all values from a nested hash' do - expect(instance.deep_find_all(:title)).to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) + expect(instance.deep_find_all(:title)) + .to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) end it 'returns nil if it does not find any matches' do @@ -92,8 +93,10 @@ describe Hashie::Extensions::DeepFind do describe '#deep_find_all' do it 'indifferently detects all values from a nested hash' do - expect(instance.deep_find_all(:title)).to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) - expect(instance.deep_find_all('title')).to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) + expect(instance.deep_find_all(:title)) + .to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) + expect(instance.deep_find_all('title')) + .to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) end it 'indifferently returns nil if it does not find any matches' do @@ -126,8 +129,10 @@ describe Hashie::Extensions::DeepFind do describe '#deep_find_all' do it 'indifferently detects all values from a nested hash' do - expect(instance.deep_find_all(:title)).to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) - expect(instance.deep_find_all('title')).to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) + expect(instance.deep_find_all(:title)) + .to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) + expect(instance.deep_find_all('title')) + .to eq(['Call of the Wild', 'Moby Dick', 'Main Library']) end it 'indifferently returns nil if it does not find any matches' do diff --git a/spec/hashie/extensions/deep_locate_spec.rb b/spec/hashie/extensions/deep_locate_spec.rb index ca4b267..6c2fcf0 100644 --- a/spec/hashie/extensions/deep_locate_spec.rb +++ b/spec/hashie/extensions/deep_locate_spec.rb @@ -56,7 +56,8 @@ describe Hashie::Extensions::DeepLocate do describe '.deep_locate' do context 'if called with a non-callable comparator' do it 'creates a key comparator on-th-fly' do - expect(described_class.deep_locate(:lsr10, hash)).to eq([hash[:query][:bool][:must_not][0][:range]]) + expect(described_class.deep_locate(:lsr10, hash)) + .to eq([hash[:query][:bool][:must_not][0][:range]]) end end diff --git a/spec/hashie/extensions/deep_merge_spec.rb b/spec/hashie/extensions/deep_merge_spec.rb index 23ac255..ab79ff6 100644 --- a/spec/hashie/extensions/deep_merge_spec.rb +++ b/spec/hashie/extensions/deep_merge_spec.rb @@ -13,7 +13,9 @@ describe Hashie::Extensions::DeepMerge do end context 'without &block' do - let(:h1) { subject.new.merge(a: 'a', a1: 42, b: 'b', c: { c1: 'c1', c2: { a: 'b' }, c3: { d1: 'd1' } }) } + let(:h1) do + subject.new.merge(a: 'a', a1: 42, b: 'b', c: { c1: 'c1', c2: { a: 'b' }, c3: { d1: 'd1' } }) + end let(:h2) { { a: 1, a1: 1, c: { c1: 2, c2: 'c2', c3: { d2: 'd2' } }, e: { e1: 1 } } } let(:expected_hash) do { a: 1, a1: 1, b: 'b', c: { c1: 2, c2: 'c2', c3: { d1: 'd1', d2: 'd2' } }, e: { e1: 1 } } diff --git a/spec/hashie/hash_spec.rb b/spec/hashie/hash_spec.rb index 1f15208..0282258 100644 --- a/spec/hashie/hash_spec.rb +++ b/spec/hashie/hash_spec.rb @@ -64,7 +64,12 @@ describe Hash do end it '#to_hash returns a hash with same keys' do - hash = Hashie::Hash['a' => 'hey', 123 => 'bob', 'array' => [1, 2, 3], subhash: ClassRespondsToHash.new] + hash = Hashie::Hash[ + 'a' => 'hey', + 123 => 'bob', + 'array' => [1, 2, 3], + subhash: ClassRespondsToHash.new + ] stringified_hash = hash.to_hash expected = { @@ -78,7 +83,12 @@ describe Hash do end it '#to_hash with stringify_keys set to true returns a hash with stringified_keys' do - hash = Hashie::Hash['a' => 'hey', 123 => 'bob', 'array' => [1, 2, 3], subhash: ClassRespondsToHash.new] + hash = Hashie::Hash[ + 'a' => 'hey', + 123 => 'bob', + 'array' => [1, 2, 3], + subhash: ClassRespondsToHash.new + ] symbolized_hash = hash.to_hash(stringify_keys: true) expected = { @@ -92,7 +102,12 @@ describe Hash do end it '#to_hash with symbolize_keys set to true returns a hash with symbolized keys' do - hash = Hashie::Hash['a' => 'hey', 123 => 'bob', 'array' => [1, 2, 3], subhash: ClassRespondsToHash.new] + hash = Hashie::Hash[ + 'a' => 'hey', + 123 => 'bob', + 'array' => [1, 2, 3], + subhash: ClassRespondsToHash.new + ] symbolized_hash = hash.to_hash(symbolize_keys: true) expected = { diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index 77a1c6b..13ddef0 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -302,14 +302,16 @@ describe Hashie::Mash do # http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-update it 'accepts a block' do - duped = subject.merge(details: { address: 'Pasadena CA' }) { |_, oldv, newv| [oldv, newv].join(', ') } + duped = subject.merge(details: { address: 'Pasadena CA' }) do |_, oldv, newv| + [oldv, newv].join(', ') + end + expect(duped.details.address).to eq 'Nowhere road, Pasadena CA' end it 'copies values for non-duplicate keys when a block is supplied' do - duped = - subject - .merge(details: { address: 'Pasadena CA', state: 'West Thoughtleby' }) { |_, oldv, _| oldv } + m_hash = { details: { address: 'Pasadena CA', state: 'West Thoughtleby' } } + duped = subject.merge(m_hash) { |_, oldv, _| oldv } expect(duped.details.address).to eq 'Nowhere road' expect(duped.details.state).to eq 'West Thoughtleby' diff --git a/spec/hashie/trash_spec.rb b/spec/hashie/trash_spec.rb index 043cbfd..9998c8d 100644 --- a/spec/hashie/trash_spec.rb +++ b/spec/hashie/trash_spec.rb @@ -188,7 +188,9 @@ describe Hashie::Trash do end it 'transforms the value when given in constructor' do - expect(TrashLambdaTestWithProperties.new(first_name: 'Michael').first_name).to eq 'Michael'.reverse + expect( + TrashLambdaTestWithProperties.new(first_name: 'Michael').first_name + ).to eq 'Michael'.reverse end context 'when :from option is given' do @@ -297,7 +299,9 @@ describe Hashie::Trash do property :copy_of_id, from: :id, required: true, message: 'must be set' end - expect { with_required.new }.to raise_error(ArgumentError, "The property 'copy_of_id' must be set") + expect { with_required.new }.to raise_error( + ArgumentError, "The property 'copy_of_id' must be set" + ) end it 'does not set properties that do not exist' do @@ -308,7 +312,9 @@ describe Hashie::Trash do subject = from_non_property.new(value: 0) expect(subject).not_to respond_to(:value) - expect { subject[:value] }.to raise_error(NoMethodError, "The property 'value' is not defined for .") + expect { subject[:value] }.to raise_error( + NoMethodError, "The property 'value' is not defined for ." + ) expect(subject.to_h[:value]).to eq(nil) expect(subject.copy_of_value).to eq(0) end diff --git a/spec/integration/elasticsearch/integration_spec.rb b/spec/integration/elasticsearch/integration_spec.rb index 70689fb..e333f21 100644 --- a/spec/integration/elasticsearch/integration_spec.rb +++ b/spec/integration/elasticsearch/integration_spec.rb @@ -35,6 +35,7 @@ RSpec.describe 'elaasticsearch-model' do def stub_elasticsearch_client response = double('Response', body: '{}') - allow_any_instance_of(Elasticsearch::Transport::Client).to receive(:perform_request) { response } + allow_any_instance_of(Elasticsearch::Transport::Client).to\ + receive(:perform_request) { response } end end diff --git a/spec/integration/rails/integration_spec.rb b/spec/integration/rails/integration_spec.rb index dc1d670..cef79f0 100644 --- a/spec/integration/rails/integration_spec.rb +++ b/spec/integration/rails/integration_spec.rb @@ -14,8 +14,11 @@ RSpec.describe 'rails', type: :request do $stdout = original_stdout end - it 'does not log anything to STDOUT when initializing and sets the Hashie logger to the Rails logger' do + it 'does not log anything to STDOUT when initializing' do expect(stdout.string).to eq('') + end + + it 'sets the Hashie logger to the Rails logger' do expect(Hashie.logger).to eq(Rails.logger) end |