diff options
author | Peter M. Goldstein <peter.m.goldstein@gmail.com> | 2014-04-06 12:43:18 -0700 |
---|---|---|
committer | Peter M. Goldstein <peter.m.goldstein@gmail.com> | 2014-04-06 12:43:18 -0700 |
commit | 9ecda1b80e362f310e51cf103e4e3dbc89e45b51 (patch) | |
tree | 14872851ae4adc88eb6bb93524069a1f30888c85 /spec/hashie/extensions | |
parent | 20a79e5e997ad9ec1bb66b53f675c9233e1639b8 (diff) | |
download | hashie-9ecda1b80e362f310e51cf103e4e3dbc89e45b51.tar.gz |
Convert specs to RSpec 2.14.7 syntax with Transpec
This conversion is done by Transpec 1.10.4 with the following command:
transpec
* 278 conversions
from: obj.should
to: expect(obj).to
* 32 conversions
from: obj.should_not
to: expect(obj).not_to
* 14 conversions
from: lambda { }.should
to: expect { }.to
* 3 conversions
from: its(:attr) { }
to: describe '#attr' do subject { super().attr }; it { } end
* 3 conversions
from: lambda { }.should_not
to: expect { }.not_to
* 1 conversion
from: obj.stub!(:message)
to: allow(obj).to receive(:message)
* 1 conversion
from: obj.should_receive(:message)
to: expect(obj).to receive(:message)
Diffstat (limited to 'spec/hashie/extensions')
-rw-r--r-- | spec/hashie/extensions/coercion_spec.rb | 44 | ||||
-rw-r--r-- | spec/hashie/extensions/deep_fetch_spec.rb | 14 | ||||
-rw-r--r-- | spec/hashie/extensions/deep_merge_spec.rb | 4 | ||||
-rw-r--r-- | spec/hashie/extensions/indifferent_access_spec.rb | 48 | ||||
-rw-r--r-- | spec/hashie/extensions/key_conversion_spec.rb | 28 | ||||
-rw-r--r-- | spec/hashie/extensions/merge_initializer_spec.rb | 8 | ||||
-rw-r--r-- | spec/hashie/extensions/method_access_spec.rb | 44 |
7 files changed, 95 insertions, 95 deletions
diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb index 3781b23..4aab298 100644 --- a/spec/hashie/extensions/coercion_spec.rb +++ b/spec/hashie/extensions/coercion_spec.rb @@ -32,13 +32,13 @@ describe Hashie::Extensions::Coercion do let(:instance) { subject.new } describe '#coerce_key' do - it { subject.should be_respond_to(:coerce_key) } + it { expect(subject).to be_respond_to(:coerce_key) } it 'runs through coerce on a specified key' do subject.coerce_key :foo, Coercable instance[:foo] = 'bar' - instance[:foo].should be_coerced + expect(instance[:foo]).to be_coerced end it 'supports an array of keys' do @@ -46,23 +46,23 @@ describe Hashie::Extensions::Coercion do instance[:foo] = 'bar' instance[:bar] = 'bax' - instance[:foo].should be_coerced - instance[:bar].should be_coerced + expect(instance[:foo]).to be_coerced + expect(instance[:bar]).to be_coerced end it 'calls #new if no coerce method is available' do subject.coerce_key :foo, Initializable instance[:foo] = 'bar' - instance[:foo].value.should eq 'String' - instance[:foo].should_not be_coerced + expect(instance[:foo].value).to eq 'String' + expect(instance[:foo]).not_to be_coerced end it 'coerces when the merge initializer is used' do subject.coerce_key :foo, Coercable instance = subject.new(foo: 'bar') - instance[:foo].should be_coerced + expect(instance[:foo]).to be_coerced end context 'when #replace is used' do @@ -73,13 +73,13 @@ describe Hashie::Extensions::Coercion do end it 'coerces relevant keys' do - instance[:foo].should be_coerced - instance[:bar].should be_coerced - instance[:hi].should_not respond_to(:coerced?) + expect(instance[:foo]).to be_coerced + expect(instance[:bar]).to be_coerced + expect(instance[:hi]).not_to respond_to(:coerced?) end it 'sets correct values' do - instance[:hi].should eq 'bye' + expect(instance[:hi]).to eq 'bye' end end @@ -93,25 +93,25 @@ describe Hashie::Extensions::Coercion do it 'coerces with instance initialization' do tweet = TweetMash.new(user: { email: 'foo@bar.com' }) - tweet[:user].should be_a(UserMash) + expect(tweet[:user]).to be_a(UserMash) end it 'coerces when setting with attribute style' do tweet = TweetMash.new tweet.user = { email: 'foo@bar.com' } - tweet[:user].should be_a(UserMash) + expect(tweet[:user]).to be_a(UserMash) end it 'coerces when setting with string index' do tweet = TweetMash.new tweet['user'] = { email: 'foo@bar.com' } - tweet[:user].should be_a(UserMash) + expect(tweet[:user]).to be_a(UserMash) end it 'coerces when setting with symbol index' do tweet = TweetMash.new tweet[:user] = { email: 'foo@bar.com' } - tweet[:user].should be_a(UserMash) + expect(tweet[:user]).to be_a(UserMash) end end end @@ -124,9 +124,9 @@ describe Hashie::Extensions::Coercion do instance[:foo] = 'bar' instance[:bar] = 'bax' instance[:hi] = :bye - instance[:foo].should be_coerced - instance[:bar].should be_coerced - instance[:hi].should_not respond_to(:coerced?) + expect(instance[:foo]).to be_coerced + expect(instance[:bar]).to be_coerced + expect(instance[:hi]).not_to respond_to(:coerced?) end it 'coerces values from a #replace call' do @@ -134,8 +134,8 @@ describe Hashie::Extensions::Coercion do instance[:foo] = :bar instance.replace(foo: 'bar', bar: 'bax') - instance[:foo].should be_coerced - instance[:bar].should be_coerced + expect(instance[:foo]).to be_coerced + expect(instance[:bar]).to be_coerced end it 'does not coerce superclasses' do @@ -143,9 +143,9 @@ describe Hashie::Extensions::Coercion do subject.coerce_value klass, Coercable instance[:foo] = 'bar' - instance[:foo].should_not be_kind_of(Coercable) + expect(instance[:foo]).not_to be_kind_of(Coercable) instance[:foo] = klass.new - instance[:foo].should be_kind_of(Coercable) + expect(instance[:foo]).to be_kind_of(Coercable) end end end diff --git a/spec/hashie/extensions/deep_fetch_spec.rb b/spec/hashie/extensions/deep_fetch_spec.rb index 7026020..3459042 100644 --- a/spec/hashie/extensions/deep_fetch_spec.rb +++ b/spec/hashie/extensions/deep_fetch_spec.rb @@ -21,27 +21,27 @@ module Hashie describe '#deep_fetch' do it 'extracts a value from a nested hash' do - instance.deep_fetch(:library, :location, :address).should eq('123 Library St.') + expect(instance.deep_fetch(:library, :location, :address)).to eq('123 Library St.') end it 'extracts a value from a nested array' do - instance.deep_fetch(:library, :books, 1, :title).should eq('Moby Dick') + expect(instance.deep_fetch(:library, :books, 1, :title)).to eq('Moby Dick') end context 'when one of the keys is not present' do context 'when a block is provided' do it 'returns the value of the block' do value = instance.deep_fetch(:library, :unknown_key, :location) { 'block value' } - value.should eq('block value') + expect(value).to eq('block value') end end context 'when a block is not provided' do context 'when the nested object is an array' do it 'raises an UndefinedPathError' do - lambda do + expect do instance.deep_fetch(:library, :books, 2) - end.should( + end.to( raise_error( DeepFetch::UndefinedPathError, 'Could not fetch path (library > books > 2) at 2' @@ -52,9 +52,9 @@ module Hashie context 'when the nested object is a hash' do it 'raises a UndefinedPathError' do - lambda do + expect do instance.deep_fetch(:library, :location, :unknown_key) - end.should( + end.to( raise_error( DeepFetch::UndefinedPathError, 'Could not fetch path (library > location > unknown_key) at unknown_key' diff --git a/spec/hashie/extensions/deep_merge_spec.rb b/spec/hashie/extensions/deep_merge_spec.rb index eff604d..fd56562 100644 --- a/spec/hashie/extensions/deep_merge_spec.rb +++ b/spec/hashie/extensions/deep_merge_spec.rb @@ -12,11 +12,11 @@ describe Hashie::Extensions::DeepMerge do let(:expected_hash) { { a: 1, a1: 1, b: 'b', c: { c1: 2, c2: 'c2', c3: { d1: 'd1', d2: 'd2' } } } } it 'deep merges two hashes' do - h1.deep_merge(h2).should eq expected_hash + expect(h1.deep_merge(h2)).to eq expected_hash end it 'deep merges another hash in place via bang method' do h1.deep_merge!(h2) - h1.should eq expected_hash + expect(h1).to eq expected_hash end end diff --git a/spec/hashie/extensions/indifferent_access_spec.rb b/spec/hashie/extensions/indifferent_access_spec.rb index 54337d5..d50f083 100644 --- a/spec/hashie/extensions/indifferent_access_spec.rb +++ b/spec/hashie/extensions/indifferent_access_spec.rb @@ -29,22 +29,22 @@ describe Hashie::Extensions::IndifferentAccess do shared_examples_for 'hash with indifferent access' do it 'is able to access via string or symbol' do h = subject.build(abc: 123) - h[:abc].should eq 123 - h['abc'].should eq 123 + expect(h[:abc]).to eq 123 + expect(h['abc']).to eq 123 end describe '#values_at' do it 'indifferently finds values' do h = subject.build(:foo => 'bar', 'baz' => 'qux') - h.values_at('foo', :baz).should eq %w(bar qux) + expect(h.values_at('foo', :baz)).to eq %w(bar qux) end end describe '#fetch' do it 'works like normal fetch, but indifferent' do h = subject.build(foo: 'bar') - h.fetch(:foo).should eq h.fetch('foo') - h.fetch(:foo).should eq 'bar' + expect(h.fetch(:foo)).to eq h.fetch('foo') + expect(h.fetch(:foo)).to eq 'bar' end end @@ -53,7 +53,7 @@ describe Hashie::Extensions::IndifferentAccess do h = subject.build(:foo => 'bar', 'baz' => 'qux') h.delete('foo') h.delete(:baz) - h.should be_empty + expect(h).to be_empty end end @@ -61,14 +61,14 @@ describe Hashie::Extensions::IndifferentAccess do let(:h) { subject.build(foo: 'bar') } it 'finds it indifferently' do - h.should be_key(:foo) - h.should be_key('foo') + expect(h).to be_key(:foo) + expect(h).to be_key('foo') end %w(include? member? has_key?).each do |key_alias| it "is aliased as #{key_alias}" do - h.send(key_alias.to_sym, :foo).should be(true) - h.send(key_alias.to_sym, 'foo').should be(true) + expect(h.send(key_alias.to_sym, :foo)).to be(true) + expect(h.send(key_alias.to_sym, 'foo')).to be(true) end end end @@ -78,18 +78,18 @@ describe Hashie::Extensions::IndifferentAccess do it 'allows keys to be indifferent still' do h.update(baz: 'qux') - h['foo'].should eq 'bar' - h['baz'].should eq 'qux' + expect(h['foo']).to eq 'bar' + expect(h['baz']).to eq 'qux' end it 'recursively injects indifference into sub-hashes' do h.update(baz: { qux: 'abc' }) - h['baz']['qux'].should eq 'abc' + expect(h['baz']['qux']).to eq 'abc' end it 'does not change the ancestors of the injected object class' do h.update(baz: { qux: 'abc' }) - Hash.new.should_not be_respond_to(:indifferent_access?) + expect(Hash.new).not_to be_respond_to(:indifferent_access?) end end @@ -97,22 +97,22 @@ describe Hashie::Extensions::IndifferentAccess do let(:h) { subject.build(foo: 'bar').replace(bar: 'baz', hi: 'bye') } it 'returns self' do - h.should be_a(subject) + expect(h).to be_a(subject) end it 'removes old keys' do [:foo, 'foo'].each do |k| - h[k].should be_nil - h.key?(k).should be_false + expect(h[k]).to be_nil + expect(h.key?(k)).to be_false end end it 'creates new keys with indifferent access' do - [:bar, 'bar', :hi, 'hi'].each { |k| h.key?(k).should be_true } - h[:bar].should eq 'baz' - h['bar'].should eq 'baz' - h[:hi].should eq 'bye' - h['hi'].should eq 'bye' + [:bar, 'bar', :hi, 'hi'].each { |k| expect(h.key?(k)).to be_true } + expect(h[:bar]).to eq 'baz' + expect(h['bar']).to eq 'baz' + expect(h[:hi]).to eq 'bye' + expect(h['hi']).to eq 'bye' end end @@ -121,7 +121,7 @@ describe Hashie::Extensions::IndifferentAccess do let(:h) { subject.try_convert(foo: 'bar') } it 'is a subject' do - h.should be_a(subject) + expect(h).to be_a(subject) end end @@ -129,7 +129,7 @@ describe Hashie::Extensions::IndifferentAccess do let(:h) { subject.try_convert('{ :foo => bar }') } it 'is nil' do - h.should be_nil + expect(h).to be_nil end end end diff --git a/spec/hashie/extensions/key_conversion_spec.rb b/spec/hashie/extensions/key_conversion_spec.rb index a7fe6a7..b5e0911 100644 --- a/spec/hashie/extensions/key_conversion_spec.rb +++ b/spec/hashie/extensions/key_conversion_spec.rb @@ -14,7 +14,7 @@ describe Hashie::Extensions::KeyConversion do instance[:abc] = 'abc' instance[123] = '123' instance.stringify_keys! - (instance.keys & %w(abc 123)).size.should eq 2 + expect((instance.keys & %w(abc 123)).size).to eq 2 end it 'performs deep conversion within nested hashes' do @@ -22,7 +22,7 @@ describe Hashie::Extensions::KeyConversion do instance[:ab][:cd] = subject.new instance[:ab][:cd][:ef] = 'abcdef' instance.stringify_keys! - instance.should eq('ab' => { 'cd' => { 'ef' => 'abcdef' } }) + expect(instance).to eq('ab' => { 'cd' => { 'ef' => 'abcdef' } }) end it 'performs deep conversion within nested arrays' do @@ -32,11 +32,11 @@ describe Hashie::Extensions::KeyConversion do instance[:ab][0][:cd] = 'abcd' instance[:ab][1][:ef] = 'abef' instance.stringify_keys! - instance.should eq('ab' => [{ 'cd' => 'abcd' }, { 'ef' => 'abef' }]) + expect(instance).to eq('ab' => [{ 'cd' => 'abcd' }, { 'ef' => 'abef' }]) end it 'returns itself' do - instance.stringify_keys!.should eq instance + expect(instance.stringify_keys!).to eq instance end end @@ -44,14 +44,14 @@ describe Hashie::Extensions::KeyConversion do it 'converts keys to strings' do instance[:abc] = 'def' copy = instance.stringify_keys - copy['abc'].should eq 'def' + expect(copy['abc']).to eq 'def' end it 'does not alter the original' do instance[:abc] = 'def' copy = instance.stringify_keys - instance.keys.should eq [:abc] - copy.keys.should eq %w(abc) + expect(instance.keys).to eq [:abc] + expect(copy.keys).to eq %w(abc) end end @@ -60,7 +60,7 @@ describe Hashie::Extensions::KeyConversion do instance['abc'] = 'abc' instance['def'] = 'def' instance.symbolize_keys! - (instance.keys & [:abc, :def]).size.should eq 2 + expect((instance.keys & [:abc, :def]).size).to eq 2 end it 'performs deep conversion within nested hashes' do @@ -68,7 +68,7 @@ describe Hashie::Extensions::KeyConversion do instance['ab']['cd'] = subject.new instance['ab']['cd']['ef'] = 'abcdef' instance.symbolize_keys! - instance.should eq(ab: { cd: { ef: 'abcdef' } }) + expect(instance).to eq(ab: { cd: { ef: 'abcdef' } }) end it 'performs deep conversion within nested arrays' do @@ -78,11 +78,11 @@ describe Hashie::Extensions::KeyConversion do instance['ab'][0]['cd'] = 'abcd' instance['ab'][1]['ef'] = 'abef' instance.symbolize_keys! - instance.should eq(ab: [{ cd: 'abcd' }, { ef: 'abef' }]) + expect(instance).to eq(ab: [{ cd: 'abcd' }, { ef: 'abef' }]) end it 'returns itself' do - instance.symbolize_keys!.should eq instance + expect(instance.symbolize_keys!).to eq instance end end @@ -90,14 +90,14 @@ describe Hashie::Extensions::KeyConversion do it 'converts keys to symbols' do instance['abc'] = 'def' copy = instance.symbolize_keys - copy[:abc].should eq 'def' + expect(copy[:abc]).to eq 'def' end it 'does not alter the original' do instance['abc'] = 'def' copy = instance.symbolize_keys - instance.keys.should eq ['abc'] - copy.keys.should eq [:abc] + expect(instance.keys).to eq ['abc'] + expect(copy.keys).to eq [:abc] end end end diff --git a/spec/hashie/extensions/merge_initializer_spec.rb b/spec/hashie/extensions/merge_initializer_spec.rb index 42dc1da..66a1488 100644 --- a/spec/hashie/extensions/merge_initializer_spec.rb +++ b/spec/hashie/extensions/merge_initializer_spec.rb @@ -8,16 +8,16 @@ describe Hashie::Extensions::MergeInitializer do subject { MergeInitializerHash } it 'initializes with no arguments' do - subject.new.should eq({}) + expect(subject.new).to eq({}) end it 'initializes with a hash' do - subject.new(abc: 'def').should eq(abc: 'def') + expect(subject.new(abc: 'def')).to eq(abc: 'def') end it 'initializes with a hash and a default' do h = subject.new({ abc: 'def' }, 'bar') - h[:foo].should eq 'bar' - h[:abc].should eq 'def' + expect(h[:foo]).to eq 'bar' + expect(h[:abc]).to eq 'def' end end diff --git a/spec/hashie/extensions/method_access_spec.rb b/spec/hashie/extensions/method_access_spec.rb index 8268430..6034cef 100644 --- a/spec/hashie/extensions/method_access_spec.rb +++ b/spec/hashie/extensions/method_access_spec.rb @@ -12,34 +12,34 @@ describe Hashie::Extensions::MethodReader do subject { ReaderHash } it 'reads string keys from the method' do - subject.new('awesome' => 'sauce').awesome.should eq 'sauce' + expect(subject.new('awesome' => 'sauce').awesome).to eq 'sauce' end it 'reads symbol keys from the method' do - subject.new(awesome: 'sauce').awesome.should eq 'sauce' + expect(subject.new(awesome: 'sauce').awesome).to eq 'sauce' end it 'reads nil and false values out properly' do h = subject.new(nil: nil, false: false) - h.nil.should eq nil - h.false.should eq false + expect(h.nil).to eq nil + expect(h.false).to eq false end it 'raises a NoMethodError for undefined keys' do - lambda { subject.new.awesome }.should raise_error(NoMethodError) + expect { subject.new.awesome }.to raise_error(NoMethodError) end describe '#respond_to?' do it 'is true for string keys' do - subject.new('awesome' => 'sauce').should be_respond_to(:awesome) + expect(subject.new('awesome' => 'sauce')).to be_respond_to(:awesome) end it 'is true for symbol keys' do - subject.new(awesome: 'sauce').should be_respond_to(:awesome) + expect(subject.new(awesome: 'sauce')).to be_respond_to(:awesome) end it 'is false for non-keys' do - subject.new.should_not be_respond_to(:awesome) + expect(subject.new).not_to be_respond_to(:awesome) end end end @@ -53,22 +53,22 @@ describe Hashie::Extensions::MethodWriter do it 'writes from a method call' do subject.awesome = 'sauce' - subject['awesome'].should eq 'sauce' + expect(subject['awesome']).to eq 'sauce' end it 'converts the key using the #convert_key method' do - subject.stub!(:convert_key).and_return(:awesome) + allow(subject).to receive(:convert_key).and_return(:awesome) subject.awesome = 'sauce' - subject[:awesome].should eq 'sauce' + expect(subject[:awesome]).to eq 'sauce' end it 'raises NoMethodError on non equals-ending methods' do - lambda { subject.awesome }.should raise_error(NoMethodError) + expect { subject.awesome }.to raise_error(NoMethodError) end it '#respond_to? correctly' do - subject.should be_respond_to(:abc=) - subject.should_not be_respond_to(:abc) + expect(subject).to be_respond_to(:abc=) + expect(subject).not_to be_respond_to(:abc) end end @@ -84,31 +84,31 @@ describe Hashie::Extensions::MethodQuery do subject { QueryHash } it 'is true for non-nil string key values' do - subject.new('abc' => 123).should be_abc + expect(subject.new('abc' => 123)).to be_abc end it 'is true for non-nil symbol key values' do - subject.new(abc: 123).should be_abc + expect(subject.new(abc: 123)).to be_abc end it 'is false for nil key values' do - subject.new(abc: false).should_not be_abc + expect(subject.new(abc: false)).not_to be_abc end it 'raises a NoMethodError for non-set keys' do - lambda { subject.new.abc? }.should raise_error(NoMethodError) + expect { subject.new.abc? }.to raise_error(NoMethodError) end it '#respond_to? for existing string keys' do - subject.new('abc' => 'def').should be_respond_to('abc?') + expect(subject.new('abc' => 'def')).to be_respond_to('abc?') end it '#respond_to? for existing symbol keys' do - subject.new(abc: 'def').should be_respond_to(:abc?) + expect(subject.new(abc: 'def')).to be_respond_to(:abc?) end it 'does not #respond_to? for non-existent keys' do - subject.new.should_not be_respond_to('abc?') + expect(subject.new).not_to be_respond_to('abc?') end end @@ -116,6 +116,6 @@ describe Hashie::Extensions::MethodAccess do it 'includes all of the other method mixins' do klass = Class.new(Hash) klass.send :include, Hashie::Extensions::MethodAccess - (klass.ancestors & [Hashie::Extensions::MethodReader, Hashie::Extensions::MethodWriter, Hashie::Extensions::MethodQuery]).size.should eq 3 + expect((klass.ancestors & [Hashie::Extensions::MethodReader, Hashie::Extensions::MethodWriter, Hashie::Extensions::MethodQuery]).size).to eq 3 end end |