summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter M. Goldstein <peter.m.goldstein@gmail.com>2014-04-06 12:43:18 -0700
committerPeter M. Goldstein <peter.m.goldstein@gmail.com>2014-04-06 12:43:18 -0700
commit9ecda1b80e362f310e51cf103e4e3dbc89e45b51 (patch)
tree14872851ae4adc88eb6bb93524069a1f30888c85
parent20a79e5e997ad9ec1bb66b53f675c9233e1639b8 (diff)
downloadhashie-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)
-rw-r--r--spec/hashie/clash_spec.rb22
-rw-r--r--spec/hashie/dash_spec.rb129
-rw-r--r--spec/hashie/extensions/coercion_spec.rb44
-rw-r--r--spec/hashie/extensions/deep_fetch_spec.rb14
-rw-r--r--spec/hashie/extensions/deep_merge_spec.rb4
-rw-r--r--spec/hashie/extensions/indifferent_access_spec.rb48
-rw-r--r--spec/hashie/extensions/key_conversion_spec.rb28
-rw-r--r--spec/hashie/extensions/merge_initializer_spec.rb8
-rw-r--r--spec/hashie/extensions/method_access_spec.rb44
-rw-r--r--spec/hashie/hash_spec.rb14
-rw-r--r--spec/hashie/mash_spec.rb242
-rw-r--r--spec/hashie/rash_spec.rb26
-rw-r--r--spec/hashie/trash_spec.rb60
-rw-r--r--spec/hashie/version_spec.rb2
14 files changed, 347 insertions, 338 deletions
diff --git a/spec/hashie/clash_spec.rb b/spec/hashie/clash_spec.rb
index 8560532..e30dd5c 100644
--- a/spec/hashie/clash_spec.rb
+++ b/spec/hashie/clash_spec.rb
@@ -5,44 +5,44 @@ describe Hashie::Clash do
it 'is able to set an attribute via method_missing' do
subject.foo('bar')
- subject[:foo].should eq 'bar'
+ expect(subject[:foo]).to eq 'bar'
end
it 'is able to set multiple attributes' do
subject.foo('bar').baz('wok')
- subject.should eq(foo: 'bar', baz: 'wok')
+ expect(subject).to eq(foo: 'bar', baz: 'wok')
end
it 'converts multiple arguments into an array' do
subject.foo(1, 2, 3)
- subject[:foo].should eq [1, 2, 3]
+ expect(subject[:foo]).to eq [1, 2, 3]
end
it 'is able to use bang notation to create a new Clash on a key' do
subject.foo!
- subject[:foo].should be_kind_of(Hashie::Clash)
+ expect(subject[:foo]).to be_kind_of(Hashie::Clash)
end
it 'is able to chain onto the new Clash when using bang notation' do
subject.foo!.bar('abc').baz(123)
- subject.should eq(foo: { bar: 'abc', baz: 123 })
+ expect(subject).to eq(foo: { bar: 'abc', baz: 123 })
end
it 'is able to jump back up to the parent in the chain with #_end!' do
subject.foo!.bar('abc')._end!.baz(123)
- subject.should eq(foo: { bar: 'abc' }, baz: 123)
+ expect(subject).to eq(foo: { bar: 'abc' }, baz: 123)
end
it 'merges rather than replaces existing keys' do
subject.where(abc: 'def').where(hgi: 123)
- subject.should eq(where: { abc: 'def', hgi: 123 })
+ expect(subject).to eq(where: { abc: 'def', hgi: 123 })
end
it 'is able to replace all of its own keys with #replace' do
subject.foo(:bar).hello(:world)
- subject.replace(baz: 123, hgi: 123).should eq(baz: 123, hgi: 123)
- subject.should eq(baz: 123, hgi: 123)
- subject[:foo].should be_nil
- subject[:hello].should be_nil
+ expect(subject.replace(baz: 123, hgi: 123)).to eq(baz: 123, hgi: 123)
+ expect(subject).to eq(baz: 123, hgi: 123)
+ expect(subject[:foo]).to be_nil
+ expect(subject[:hello]).to be_nil
end
end
diff --git a/spec/hashie/dash_spec.rb b/spec/hashie/dash_spec.rb
index 606e38e..d651eea 100644
--- a/spec/hashie/dash_spec.rb
+++ b/spec/hashie/dash_spec.rb
@@ -40,102 +40,108 @@ describe DashTest do
it('subclasses Hashie::Hash') { should respond_to(:to_mash) }
- its(:to_s) { should eq '#<DashTest count=0 email="bob@example.com" first_name="Bob">' }
+ describe '#to_s' do
+ subject { super().to_s }
+ it { should eq '#<DashTest count=0 email="bob@example.com" first_name="Bob">' }
+ end
it 'lists all set properties in inspect' do
subject.first_name = 'Bob'
subject.email = 'bob@example.com'
- subject.inspect.should eq '#<DashTest count=0 email="bob@example.com" first_name="Bob">'
+ expect(subject.inspect).to eq '#<DashTest count=0 email="bob@example.com" first_name="Bob">'
end
- its(:count) { should be_zero }
+ describe '#count' do
+ subject { super().count }
+ it { should be_zero }
+ end
it { should respond_to(:first_name) }
it { should respond_to(:first_name=) }
it { should_not respond_to(:nonexistent) }
it 'errors out for a non-existent property' do
- lambda { subject['nonexistent'] }.should raise_error(NoMethodError)
+ expect { subject['nonexistent'] }.to raise_error(NoMethodError)
end
it 'errors out when attempting to set a required property to nil' do
- lambda { subject.first_name = nil }.should raise_error(ArgumentError)
+ expect { subject.first_name = nil }.to raise_error(ArgumentError)
end
context 'writing to properties' do
it 'fails writing a required property to nil' do
- lambda { subject.first_name = nil }.should raise_error(ArgumentError)
+ expect { subject.first_name = nil }.to raise_error(ArgumentError)
end
it 'fails writing a required property to nil using []=' do
- lambda { subject['first_name'] = nil }.should raise_error(ArgumentError)
+ expect { subject['first_name'] = nil }.to raise_error(ArgumentError)
end
it 'fails writing to a non-existent property using []=' do
- lambda { subject['nonexistent'] = 123 }.should raise_error(NoMethodError)
+ expect { subject['nonexistent'] = 123 }.to raise_error(NoMethodError)
end
it 'works for an existing property using []=' do
subject['first_name'] = 'Bob'
- subject['first_name'].should eq 'Bob'
- subject[:first_name].should eq 'Bob'
+ expect(subject['first_name']).to eq 'Bob'
+ expect(subject[:first_name]).to eq 'Bob'
end
it 'works for an existing property using a method call' do
subject.first_name = 'Franklin'
- subject.first_name.should eq 'Franklin'
+ expect(subject.first_name).to eq 'Franklin'
end
end
context 'reading from properties' do
it 'fails reading from a non-existent property using []' do
- lambda { subject['nonexistent'] }.should raise_error(NoMethodError)
+ expect { subject['nonexistent'] }.to raise_error(NoMethodError)
end
it 'is able to retrieve properties through blocks' do
subject['first_name'] = 'Aiden'
value = nil
subject.[]('first_name') { |v| value = v }
- value.should eq 'Aiden'
+ expect(value).to eq 'Aiden'
end
it 'is able to retrieve properties through blocks with method calls' do
subject['first_name'] = 'Frodo'
value = nil
subject.first_name { |v| value = v }
- value.should eq 'Frodo'
+ expect(value).to eq 'Frodo'
end
end
context 'reading from deferred properties' do
it 'evaluates proc after initial read' do
- DeferredTest.new['created_at'].should be_instance_of(Time)
+ expect(DeferredTest.new['created_at']).to be_instance_of(Time)
end
it 'does not evalute proc after subsequent reads' do
deferred = DeferredTest.new
- deferred['created_at'].object_id.should eq deferred['created_at'].object_id
+ expect(deferred['created_at'].object_id).to eq deferred['created_at'].object_id
end
end
describe '#new' do
it 'fails with non-existent properties' do
- lambda { described_class.new(bork: '') }.should raise_error(NoMethodError)
+ expect { described_class.new(bork: '') }.to raise_error(NoMethodError)
end
it 'sets properties that it is able to' do
obj = described_class.new first_name: 'Michael'
- obj.first_name.should eq 'Michael'
+ expect(obj.first_name).to eq 'Michael'
end
it 'accepts nil' do
- lambda { DashNoRequiredTest.new(nil) }.should_not raise_error
+ expect { DashNoRequiredTest.new(nil) }.not_to raise_error
end
it 'accepts block to define a global default' do
obj = described_class.new { |hash, key| key.to_s.upcase }
- obj.first_name.should eq 'FIRST_NAME'
- obj.count.should be_zero
+ expect(obj.first_name).to eq 'FIRST_NAME'
+ expect(obj.count).to be_zero
end
it 'fails when required values are missing' do
@@ -146,20 +152,20 @@ describe DashTest do
obj1 = DashDefaultTest.new
obj1.aliases << 'El Rey'
obj2 = DashDefaultTest.new
- obj2.aliases.should_not include 'El Rey'
+ expect(obj2.aliases).not_to include 'El Rey'
end
end
describe '#merge' do
it 'creates a new instance of the Dash' do
new_dash = subject.merge(first_name: 'Robert')
- subject.object_id.should_not eq new_dash.object_id
+ expect(subject.object_id).not_to eq new_dash.object_id
end
it 'merges the given hash' do
new_dash = subject.merge(first_name: 'Robert', email: 'robert@example.com')
- new_dash.first_name.should eq 'Robert'
- new_dash.email.should eq 'robert@example.com'
+ expect(new_dash.first_name).to eq 'Robert'
+ expect(new_dash.email).to eq 'robert@example.com'
end
it 'fails with non-existent properties' do
@@ -172,9 +178,9 @@ describe DashTest do
context 'given a block' do
it "sets merged key's values to the block's return value" do
- subject.merge(first_name: 'Jim') do |key, oldval, newval|
+ expect(subject.merge(first_name: 'Jim') do |key, oldval, newval|
"#{key}: #{newval} #{oldval}"
- end.first_name.should eq 'first_name: Jim Bob'
+ end.first_name).to eq 'first_name: Jim Bob'
end
end
end
@@ -182,13 +188,13 @@ describe DashTest do
describe '#merge!' do
it 'modifies the existing instance of the Dash' do
original_dash = subject.merge!(first_name: 'Robert')
- subject.object_id.should eq original_dash.object_id
+ expect(subject.object_id).to eq original_dash.object_id
end
it 'merges the given hash' do
subject.merge!(first_name: 'Robert', email: 'robert@example.com')
- subject.first_name.should eq 'Robert'
- subject.email.should eq 'robert@example.com'
+ expect(subject.first_name).to eq 'Robert'
+ expect(subject.email).to eq 'robert@example.com'
end
it 'fails with non-existent properties' do
@@ -201,38 +207,38 @@ describe DashTest do
context 'given a block' do
it "sets merged key's values to the block's return value" do
- subject.merge!(first_name: 'Jim') do |key, oldval, newval|
+ expect(subject.merge!(first_name: 'Jim') do |key, oldval, newval|
"#{key}: #{newval} #{oldval}"
- end.first_name.should eq 'first_name: Jim Bob'
+ end.first_name).to eq 'first_name: Jim Bob'
end
end
end
describe 'properties' do
it 'lists defined properties' do
- described_class.properties.should eq Set.new([:first_name, :email, :count])
+ expect(described_class.properties).to eq Set.new([:first_name, :email, :count])
end
it 'checks if a property exists' do
- described_class.property?('first_name').should be_true
- described_class.property?(:first_name).should be_true
+ expect(described_class.property?('first_name')).to be_true
+ expect(described_class.property?(:first_name)).to be_true
end
it 'checks if a property is required' do
- described_class.required?('first_name').should be_true
- described_class.required?(:first_name).should be_true
+ expect(described_class.required?('first_name')).to be_true
+ expect(described_class.required?(:first_name)).to be_true
end
it 'doesnt include property from subclass' do
- described_class.property?(:last_name).should be_false
+ expect(described_class.property?(:last_name)).to be_false
end
it 'lists declared defaults' do
- described_class.defaults.should eq(count: 0)
+ expect(described_class.defaults).to eq(count: 0)
end
it 'allows properties that end in bang' do
- PropertyBangTest.property?(:important!).should be_true
+ expect(PropertyBangTest.property?(:important!)).to be_true
end
end
@@ -240,24 +246,24 @@ describe DashTest do
before { subject.replace(first_name: 'Cain') }
it 'return self' do
- subject.replace(email: 'bar').to_hash.should eq('email' => 'bar', 'count' => 0)
+ expect(subject.replace(email: 'bar').to_hash).to eq('email' => 'bar', 'count' => 0)
end
it 'sets all specified keys to their corresponding values' do
- subject.first_name.should eq 'Cain'
+ expect(subject.first_name).to eq 'Cain'
end
it 'leaves only specified keys and keys with default values' do
- subject.keys.sort.should eq %w(count first_name)
- subject.email.should be_nil
- subject.count.should eq 0
+ expect(subject.keys.sort).to eq %w(count first_name)
+ expect(subject.email).to be_nil
+ expect(subject.count).to eq 0
end
context 'when replacing keys with default values' do
before { subject.replace(count: 3) }
it 'sets all specified keys to their corresponding values' do
- subject.count.should eq 3
+ expect(subject.count).to eq 3
end
end
end
@@ -271,40 +277,40 @@ describe Hashie::Dash, 'inheritance' do
end
it 'reports empty properties when nothing defined' do
- @top.properties.should be_empty
- @top.defaults.should be_empty
+ expect(@top.properties).to be_empty
+ expect(@top.defaults).to be_empty
end
it 'inherits properties downwards' do
@top.property :echo
- @middle.properties.should include(:echo)
- @bottom.properties.should include(:echo)
+ expect(@middle.properties).to include(:echo)
+ expect(@bottom.properties).to include(:echo)
end
it 'doesnt inherit properties upwards' do
@middle.property :echo
- @top.properties.should_not include(:echo)
- @bottom.properties.should include(:echo)
+ expect(@top.properties).not_to include(:echo)
+ expect(@bottom.properties).to include(:echo)
end
it 'allows overriding a default on an existing property' do
@top.property :echo
@middle.property :echo, default: 123
- @bottom.properties.to_a.should eq [:echo]
- @bottom.new.echo.should eq 123
+ expect(@bottom.properties.to_a).to eq [:echo]
+ expect(@bottom.new.echo).to eq 123
end
it 'allows clearing an existing default' do
@top.property :echo
@middle.property :echo, default: 123
@bottom.property :echo
- @bottom.properties.to_a.should eq [:echo]
- @bottom.new.echo.should be_nil
+ expect(@bottom.properties.to_a).to eq [:echo]
+ expect(@bottom.new.echo).to be_nil
end
it 'allows nil defaults' do
@bottom.property :echo, default: nil
- @bottom.new.should have_key('echo')
+ expect(@bottom.new).to have_key('echo')
end
end
@@ -312,7 +318,10 @@ end
describe Subclassed do
subject { Subclassed.new(first_name: 'Bob', last_name: 'McNob', email: 'bob@example.com') }
- its(:count) { should be_zero }
+ describe '#count' do
+ subject { super().count }
+ it { should be_zero }
+ end
it { should respond_to(:first_name) }
it { should respond_to(:first_name=) }
@@ -320,10 +329,10 @@ describe Subclassed do
it { should respond_to(:last_name=) }
it 'has one additional property' do
- described_class.property?(:last_name).should be_true
+ expect(described_class.property?(:last_name)).to be_true
end
it "didn't override superclass inheritance logic" do
- described_class.instance_variable_get('@inheritance_test').should be_true
+ expect(described_class.instance_variable_get('@inheritance_test')).to be_true
end
end
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
diff --git a/spec/hashie/hash_spec.rb b/spec/hashie/hash_spec.rb
index 47aa511..df1e557 100644
--- a/spec/hashie/hash_spec.rb
+++ b/spec/hashie/hash_spec.rb
@@ -3,32 +3,32 @@ require 'spec_helper'
describe Hash do
it 'is convertible to a Hashie::Mash' do
mash = Hashie::Hash[some: 'hash'].to_mash
- mash.is_a?(Hashie::Mash).should be_true
- mash.some.should eq 'hash'
+ expect(mash.is_a?(Hashie::Mash)).to be_true
+ expect(mash.some).to eq 'hash'
end
it '#stringify_keys! turns all keys into strings' do
hash = Hashie::Hash[:a => 'hey', 123 => 'bob']
hash.stringify_keys!
- hash.should eq Hashie::Hash['a' => 'hey', '123' => 'bob']
+ expect(hash).to eq Hashie::Hash['a' => 'hey', '123' => 'bob']
end
it '#stringify_keys returns a hash with stringified keys' do
hash = Hashie::Hash[:a => 'hey', 123 => 'bob']
stringified_hash = hash.stringify_keys
- hash.should eq Hashie::Hash[:a => 'hey', 123 => 'bob']
- stringified_hash.should eq Hashie::Hash['a' => 'hey', '123' => 'bob']
+ expect(hash).to eq Hashie::Hash[:a => 'hey', 123 => 'bob']
+ expect(stringified_hash).to eq Hashie::Hash['a' => 'hey', '123' => 'bob']
end
it '#to_hash returns a hash with stringified keys' do
hash = Hashie::Hash['a' => 'hey', 123 => 'bob', 'array' => [1, 2, 3]]
stringified_hash = hash.to_hash
- stringified_hash.should eq('a' => 'hey', '123' => 'bob', 'array' => [1, 2, 3])
+ expect(stringified_hash).to eq('a' => 'hey', '123' => 'bob', 'array' => [1, 2, 3])
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]]
symbolized_hash = hash.to_hash(symbolize_keys: true)
- symbolized_hash.should eq(:a => 'hey', :"123" => 'bob', :array => [1, 2, 3])
+ expect(symbolized_hash).to eq(:a => 'hey', :"123" => 'bob', :array => [1, 2, 3])
end
end
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index 210abed..1129e64 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -5,123 +5,123 @@ describe Hashie::Mash do
subject { Hashie::Mash.new }
it 'inherits from Hash' do
- subject.is_a?(Hash).should be_true
+ expect(subject.is_a?(Hash)).to be_true
end
it 'sets hash values through method= calls' do
subject.test = 'abc'
- subject['test'].should eq 'abc'
+ expect(subject['test']).to eq 'abc'
end
it 'retrieves set values through method calls' do
subject['test'] = 'abc'
- subject.test.should eq 'abc'
+ expect(subject.test).to eq 'abc'
end
it 'retrieves set values through blocks' do
subject['test'] = 'abc'
value = nil
subject.[]('test') { |v| value = v }
- value.should eq 'abc'
+ expect(value).to eq 'abc'
end
it 'retrieves set values through blocks with method calls' do
subject['test'] = 'abc'
value = nil
subject.test { |v| value = v }
- value.should eq 'abc'
+ expect(value).to eq 'abc'
end
it 'tests for already set values when passed a ? method' do
- subject.test?.should be_false
+ expect(subject.test?).to be_false
subject.test = 'abc'
- subject.test?.should be_true
+ expect(subject.test?).to be_true
end
it 'returns false on a ? method if a value has been set to nil or false' do
subject.test = nil
- subject.should_not be_test
+ expect(subject).not_to be_test
subject.test = false
- subject.should_not be_test
+ expect(subject).not_to be_test
end
it 'makes all [] and []= into strings for consistency' do
subject['abc'] = 123
- subject.key?('abc').should be_true
- subject['abc'].should eq 123
+ expect(subject.key?('abc')).to be_true
+ expect(subject['abc']).to eq 123
end
it 'has a to_s that is identical to its inspect' do
subject.abc = 123
- subject.to_s.should eq subject.inspect
+ expect(subject.to_s).to eq subject.inspect
end
it 'returns nil instead of raising an error for attribute-esque method calls' do
- subject.abc.should be_nil
+ expect(subject.abc).to be_nil
end
it 'returns the default value if set like Hash' do
subject.default = 123
- subject.abc.should eq 123
+ expect(subject.abc).to eq 123
end
it 'gracefully handles being accessed with arguments' do
- subject.abc('foobar').should eq nil
+ expect(subject.abc('foobar')).to eq nil
subject.abc = 123
- subject.abc('foobar').should eq 123
+ expect(subject.abc('foobar')).to eq 123
end
it 'returns a Hashie::Mash when passed a bang method to a non-existenct key' do
- subject.abc!.is_a?(Hashie::Mash).should be_true
+ expect(subject.abc!.is_a?(Hashie::Mash)).to be_true
end
it 'returns the existing value when passed a bang method for an existing key' do
subject.name = 'Bob'
- subject.name!.should eq 'Bob'
+ expect(subject.name!).to eq 'Bob'
end
it 'returns a Hashie::Mash when passed an under bang method to a non-existenct key' do
- subject.abc_.is_a?(Hashie::Mash).should be_true
+ expect(subject.abc_.is_a?(Hashie::Mash)).to be_true
end
it 'returns the existing value when passed an under bang method for an existing key' do
subject.name = 'Bob'
- subject.name_.should eq 'Bob'
+ expect(subject.name_).to eq 'Bob'
end
it '#initializing_reader returns a Hashie::Mash when passed a non-existent key' do
- subject.initializing_reader(:abc).is_a?(Hashie::Mash).should be_true
+ expect(subject.initializing_reader(:abc).is_a?(Hashie::Mash)).to be_true
end
it 'allows for multi-level assignment through bang methods' do
subject.author!.name = 'Michael Bleigh'
- subject.author.should eq Hashie::Mash.new(name: 'Michael Bleigh')
+ expect(subject.author).to eq Hashie::Mash.new(name: 'Michael Bleigh')
subject.author!.website!.url = 'http://www.mbleigh.com/'
- subject.author.website.should eq Hashie::Mash.new(url: 'http://www.mbleigh.com/')
+ expect(subject.author.website).to eq Hashie::Mash.new(url: 'http://www.mbleigh.com/')
end
it 'allows for multi-level under bang testing' do
- subject.author_.website_.url.should be_nil
- subject.author_.website_.url?.should eq false
- subject.author.should be_nil
+ expect(subject.author_.website_.url).to be_nil
+ expect(subject.author_.website_.url?).to eq false
+ expect(subject.author).to be_nil
end
it 'does not call super if id is not a key' do
- subject.id.should eq nil
+ expect(subject.id).to eq nil
end
it 'returns the value if id is a key' do
subject.id = 'Steve'
- subject.id.should eq 'Steve'
+ expect(subject.id).to eq 'Steve'
end
it 'does not call super if type is not a key' do
- subject.type.should eq nil
+ expect(subject.type).to eq nil
end
it 'returns the value if type is a key' do
subject.type = 'Steve'
- subject.type.should eq 'Steve'
+ expect(subject.type).to eq 'Steve'
end
context 'updating' do
@@ -138,10 +138,10 @@ describe Hashie::Mash do
describe '#deep_update' do
it 'recursively Hashie::Mash Hashie::Mashes and hashes together' do
subject.deep_update(details: { email: 'michael@intridea.com', city: 'Imagineton' })
- subject.first_name.should eq 'Michael'
- subject.details.email.should eq 'michael@intridea.com'
- subject.details.address.should eq 'Nowhere road'
- subject.details.city.should eq 'Imagineton'
+ expect(subject.first_name).to eq 'Michael'
+ expect(subject.details.email).to eq 'michael@intridea.com'
+ expect(subject.details.address).to eq 'Nowhere road'
+ expect(subject.details.city).to eq 'Imagineton'
end
it 'converts values only once' do
@@ -149,60 +149,60 @@ describe Hashie::Mash do
end
rhs = ConvertedMash.new(email: 'foo@bar.com')
- subject.should_receive(:convert_value).exactly(1).times
+ expect(subject).to receive(:convert_value).exactly(1).times
subject.deep_update(rhs)
end
it 'makes #update deep by default' do
- subject.update(details: { address: 'Fake street' }).should eql(subject)
- subject.details.address.should eq 'Fake street'
- subject.details.email.should eq 'michael@asf.com'
+ expect(subject.update(details: { address: 'Fake street' })).to eql(subject)
+ expect(subject.details.address).to eq 'Fake street'
+ expect(subject.details.email).to eq 'michael@asf.com'
end
it 'clones before a #deep_merge' do
duped = subject.deep_merge(details: { address: 'Fake street' })
- duped.should_not eql(subject)
- duped.details.address.should eq 'Fake street'
- subject.details.address.should eq 'Nowhere road'
- duped.details.email.should eq 'michael@asf.com'
+ expect(duped).not_to eql(subject)
+ expect(duped.details.address).to eq 'Fake street'
+ expect(subject.details.address).to eq 'Nowhere road'
+ expect(duped.details.email).to eq 'michael@asf.com'
end
it 'default #merge is deep' do
duped = subject.merge(details: { email: 'michael@intridea.com' })
- duped.should_not eql(subject)
- duped.details.email.should eq 'michael@intridea.com'
- duped.details.address.should eq 'Nowhere road'
+ expect(duped).not_to eql(subject)
+ expect(duped.details.email).to eq 'michael@intridea.com'
+ expect(duped.details.address).to eq 'Nowhere road'
end
# 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' }) { |key, oldv, newv| [oldv, newv].join(', ') }
- duped.details.address.should eq 'Nowhere road, Pasadena CA'
+ expect(duped.details.address).to eq 'Nowhere road, Pasadena CA'
end
end
describe 'shallow update' do
it 'shallowly Hashie::Mash Hashie::Mashes and hashes together' do
- subject.shallow_update(details: {
+ expect(subject.shallow_update(details: {
email: 'michael@intridea.com', city: 'Imagineton'
- }).should eql(subject)
+ })).to eql(subject)
- subject.first_name.should eq 'Michael'
- subject.details.email.should eq 'michael@intridea.com'
- subject.details.address.should be_nil
- subject.details.city.should eq 'Imagineton'
+ expect(subject.first_name).to eq 'Michael'
+ expect(subject.details.email).to eq 'michael@intridea.com'
+ expect(subject.details.address).to be_nil
+ expect(subject.details.city).to eq 'Imagineton'
end
it 'clones before a #regular_merge' do
duped = subject.shallow_merge(details: { address: 'Fake street' })
- duped.should_not eql(subject)
+ expect(duped).not_to eql(subject)
end
it 'default #merge is shallow' do
duped = subject.shallow_merge(details: { address: 'Fake street' })
- duped.details.address.should eq 'Fake street'
- subject.details.address.should eq 'Nowhere road'
- duped.details.email.should be_nil
+ expect(duped.details.address).to eq 'Fake street'
+ expect(subject.details.address).to eq 'Nowhere road'
+ expect(duped.details.email).to be_nil
end
end
@@ -215,45 +215,45 @@ describe Hashie::Mash do
end
it 'returns self' do
- subject.replace(foo: 'bar').to_hash.should eq('foo' => 'bar')
+ expect(subject.replace(foo: 'bar').to_hash).to eq('foo' => 'bar')
end
it 'sets all specified keys to their corresponding values' do
- subject.middle_name?.should be_true
- subject.details?.should be_true
- subject.middle_name.should eq 'Cain'
- subject.details.city?.should be_true
- subject.details.city.should eq 'Imagination'
+ expect(subject.middle_name?).to be_true
+ expect(subject.details?).to be_true
+ expect(subject.middle_name).to eq 'Cain'
+ expect(subject.details.city?).to be_true
+ expect(subject.details.city).to eq 'Imagination'
end
it 'leaves only specified keys' do
- subject.keys.sort.should eq %w(details middle_name)
- subject.first_name?.should be_false
- subject.should_not respond_to(:first_name)
- subject.last_name?.should be_false
- subject.should_not respond_to(:last_name)
+ expect(subject.keys.sort).to eq %w(details middle_name)
+ expect(subject.first_name?).to be_false
+ expect(subject).not_to respond_to(:first_name)
+ expect(subject.last_name?).to be_false
+ expect(subject).not_to respond_to(:last_name)
end
end
describe 'delete' do
it 'deletes with String key' do
subject.delete('details')
- subject.details.should be_nil
- subject.should_not be_respond_to :details
+ expect(subject.details).to be_nil
+ expect(subject).not_to be_respond_to :details
end
it 'deletes with Symbol key' do
subject.delete(:details)
- subject.details.should be_nil
- subject.should_not be_respond_to :details
+ expect(subject.details).to be_nil
+ expect(subject).not_to be_respond_to :details
end
end
end
it 'converts hash assignments into Hashie::Mashes' do
subject.details = { email: 'randy@asf.com', address: { state: 'TX' } }
- subject.details.email.should eq 'randy@asf.com'
- subject.details.address.state.should eq 'TX'
+ expect(subject.details.email).to eq 'randy@asf.com'
+ expect(subject.details.address.state).to eq 'TX'
end
it 'does not convert the type of Hashie::Mashes childs to Hashie::Mash' do
@@ -262,7 +262,7 @@ describe Hashie::Mash do
record = MyMash.new
record.son = MyMash.new
- record.son.class.should eq MyMash
+ expect(record.son.class).to eq MyMash
end
it 'does not change the class of Mashes when converted' do
@@ -272,35 +272,35 @@ describe Hashie::Mash do
record = Hashie::Mash.new
son = SubMash.new
record['submash'] = son
- record['submash'].should be_kind_of(SubMash)
+ expect(record['submash']).to be_kind_of(SubMash)
end
it 'respects the class when passed a bang method for a non-existent key' do
record = Hashie::Mash.new
- record.non_existent!.should be_kind_of(Hashie::Mash)
+ expect(record.non_existent!).to be_kind_of(Hashie::Mash)
class SubMash < Hashie::Mash
end
son = SubMash.new
- son.non_existent!.should be_kind_of(SubMash)
+ expect(son.non_existent!).to be_kind_of(SubMash)
end
it 'respects the class when passed an under bang method for a non-existent key' do
record = Hashie::Mash.new
- record.non_existent_.should be_kind_of(Hashie::Mash)
+ expect(record.non_existent_).to be_kind_of(Hashie::Mash)
class SubMash < Hashie::Mash
end
son = SubMash.new
- son.non_existent_.should be_kind_of(SubMash)
+ expect(son.non_existent_).to be_kind_of(SubMash)
end
it 'respects the class when converting the value' do
record = Hashie::Mash.new
record.details = Hashie::Mash.new(email: 'randy@asf.com')
- record.details.should be_kind_of(Hashie::Mash)
+ expect(record.details).to be_kind_of(Hashie::Mash)
end
it 'respects another subclass when converting the value' do
@@ -311,84 +311,84 @@ describe Hashie::Mash do
son = SubMash.new(email: 'foo@bar.com')
record.details = son
- record.details.should be_kind_of(SubMash)
+ expect(record.details).to be_kind_of(SubMash)
end
describe '#respond_to?' do
it 'responds to a normal method' do
- Hashie::Mash.new.should be_respond_to(:key?)
+ expect(Hashie::Mash.new).to be_respond_to(:key?)
end
it 'responds to a set key' do
- Hashie::Mash.new(abc: 'def').should be_respond_to(:abc)
+ expect(Hashie::Mash.new(abc: 'def')).to be_respond_to(:abc)
end
it 'responds to a set key with a suffix' do
%w(= ? ! _).each do |suffix|
- Hashie::Mash.new(abc: 'def').should be_respond_to(:"abc#{suffix}")
+ expect(Hashie::Mash.new(abc: 'def')).to be_respond_to(:"abc#{suffix}")
end
end
it 'does not respond to an unknown key with a suffix' do
%w(= ? ! _).each do |suffix|
- Hashie::Mash.new(abc: 'def').should_not be_respond_to(:"xyz#{suffix}")
+ expect(Hashie::Mash.new(abc: 'def')).not_to be_respond_to(:"xyz#{suffix}")
end
end
it 'does not respond to an unknown key without a suffix' do
- Hashie::Mash.new(abc: 'def').should_not be_respond_to(:xyz)
+ expect(Hashie::Mash.new(abc: 'def')).not_to be_respond_to(:xyz)
end
it 'does not respond to permitted?' do
- Hashie::Mash.new.should_not be_respond_to(:permitted?)
+ expect(Hashie::Mash.new).not_to be_respond_to(:permitted?)
end
end
context '#initialize' do
it 'converts an existing hash to a Hashie::Mash' do
converted = Hashie::Mash.new(abc: 123, name: 'Bob')
- converted.abc.should eq 123
- converted.name.should eq 'Bob'
+ expect(converted.abc).to eq 123
+ expect(converted.name).to eq 'Bob'
end
it 'converts hashes recursively into Hashie::Mashes' do
converted = Hashie::Mash.new(a: { b: 1, c: { d: 23 } })
- converted.a.is_a?(Hashie::Mash).should be_true
- converted.a.b.should eq 1
- converted.a.c.d.should eq 23
+ expect(converted.a.is_a?(Hashie::Mash)).to be_true
+ expect(converted.a.b).to eq 1
+ expect(converted.a.c.d).to eq 23
end
it 'converts hashes in arrays into Hashie::Mashes' do
converted = Hashie::Mash.new(a: [{ b: 12 }, 23])
- converted.a.first.b.should eq 12
- converted.a.last.should eq 23
+ expect(converted.a.first.b).to eq 12
+ expect(converted.a.last).to eq 23
end
it 'converts an existing Hashie::Mash into a Hashie::Mash' do
initial = Hashie::Mash.new(name: 'randy', address: { state: 'TX' })
copy = Hashie::Mash.new(initial)
- initial.name.should eq copy.name
- initial.__id__.should_not eq copy.__id__
- copy.address.state.should eq 'TX'
+ expect(initial.name).to eq copy.name
+ expect(initial.__id__).not_to eq copy.__id__
+ expect(copy.address.state).to eq 'TX'
copy.address.state = 'MI'
- initial.address.state.should eq 'TX'
- copy.address.__id__.should_not eq initial.address.__id__
+ expect(initial.address.state).to eq 'TX'
+ expect(copy.address.__id__).not_to eq initial.address.__id__
end
it 'accepts a default block' do
initial = Hashie::Mash.new { |h, i| h[i] = [] }
- initial.default_proc.should_not be_nil
- initial.default.should be_nil
- initial.test.should eq []
- initial.test?.should be_true
+ expect(initial.default_proc).not_to be_nil
+ expect(initial.default).to be_nil
+ expect(initial.test).to eq []
+ expect(initial.test?).to be_true
end
it 'converts Hashie::Mashes within Arrays back to Hashes' do
initial_hash = { 'a' => [{ 'b' => 12, 'c' => ['d' => 50, 'e' => 51] }, 23] }
converted = Hashie::Mash.new(initial_hash)
- converted.to_hash['a'].first.is_a?(Hashie::Mash).should be_false
- converted.to_hash['a'].first.is_a?(Hash).should be_true
- converted.to_hash['a'].first['c'].first.is_a?(Hashie::Mash).should be_false
+ expect(converted.to_hash['a'].first.is_a?(Hashie::Mash)).to be_false
+ expect(converted.to_hash['a'].first.is_a?(Hash)).to be_true
+ expect(converted.to_hash['a'].first['c'].first.is_a?(Hashie::Mash)).to be_false
end
end
@@ -398,16 +398,16 @@ describe Hashie::Mash do
context 'when key exists' do
it 'returns the value' do
- mash.fetch(:one).should eql(1)
+ expect(mash.fetch(:one)).to eql(1)
end
it 'returns the value even if the value is falsy' do
- mash.fetch(:other).should eql(false)
+ expect(mash.fetch(:other)).to eql(false)
end
context 'when key has other than original but acceptable type' do
it 'returns the value' do
- mash.fetch('one').should eql(1)
+ expect(mash.fetch('one')).to eql(1)
end
end
end
@@ -420,19 +420,19 @@ describe Hashie::Mash do
context 'with default value given' do
it 'returns default value' do
- mash.fetch(:two, 8).should eql(8)
+ expect(mash.fetch(:two, 8)).to eql(8)
end
it 'returns default value even if it is falsy' do
- mash.fetch(:two, false).should eql(false)
+ expect(mash.fetch(:two, false)).to eql(false)
end
end
context 'with block given' do
it 'returns default value' do
- mash.fetch(:two) do |key|
+ expect(mash.fetch(:two) do |key|
'block default value'
- end.should eql('block default value')
+ end).to eql('block default value')
end
end
end
@@ -443,26 +443,26 @@ describe Hashie::Mash do
let(:mash) { Hashie::Mash.new(hash) }
it 'returns a standard Hash' do
- mash.to_hash.should be_a(::Hash)
+ expect(mash.to_hash).to be_a(::Hash)
end
it 'includes all keys' do
- mash.to_hash.keys.should eql(%w(outer testing))
+ expect(mash.to_hash.keys).to eql(%w(outer testing))
end
it 'converts keys to symbols when symbolize_keys option is true' do
- mash.to_hash(symbolize_keys: true).keys.should include(:outer)
- mash.to_hash(symbolize_keys: true).keys.should_not include('outer')
+ expect(mash.to_hash(symbolize_keys: true).keys).to include(:outer)
+ expect(mash.to_hash(symbolize_keys: true).keys).not_to include('outer')
end
it 'leaves keys as strings when symbolize_keys option is false' do
- mash.to_hash(symbolize_keys: false).keys.should include('outer')
- mash.to_hash(symbolize_keys: false).keys.should_not include(:outer)
+ expect(mash.to_hash(symbolize_keys: false).keys).to include('outer')
+ expect(mash.to_hash(symbolize_keys: false).keys).not_to include(:outer)
end
it 'symbolizes keys recursively' do
- mash.to_hash(symbolize_keys: true)[:outer].keys.should include(:inner)
- mash.to_hash(symbolize_keys: true)[:outer].keys.should_not include('inner')
+ expect(mash.to_hash(symbolize_keys: true)[:outer].keys).to include(:inner)
+ expect(mash.to_hash(symbolize_keys: true)[:outer].keys).not_to include('inner')
end
end
end
diff --git a/spec/hashie/rash_spec.rb b/spec/hashie/rash_spec.rb
index b79fe44..68072ef 100644
--- a/spec/hashie/rash_spec.rb
+++ b/spec/hashie/rash_spec.rb
@@ -15,30 +15,30 @@ describe Hashie::Rash do
end
it 'finds strings' do
- subject['other'].should eq 'whee'
- subject['well hello there'].should eq 'hello'
- subject['the world is round'].should eq 'world'
- subject.all('hello world').sort.should eq %w(hello world)
+ expect(subject['other']).to eq 'whee'
+ expect(subject['well hello there']).to eq 'hello'
+ expect(subject['the world is round']).to eq 'world'
+ expect(subject.all('hello world').sort).to eq %w(hello world)
end
it 'finds regexps' do
- subject[/other/].should eq 'whee'
+ expect(subject[/other/]).to eq 'whee'
end
it 'finds other objects' do
- subject[true].should eq false
- subject[1].should eq 'awesome'
+ expect(subject[true]).to eq false
+ expect(subject[1]).to eq 'awesome'
end
it 'finds numbers from ranges' do
- subject[250].should eq 'rangey'
- subject[999].should eq 'rangey'
- subject[1000].should eq 'rangey'
- subject[1001].should be_nil
+ expect(subject[250]).to eq 'rangey'
+ expect(subject[999]).to eq 'rangey'
+ expect(subject[1000]).to eq 'rangey'
+ expect(subject[1001]).to be_nil
end
it 'evaluates proc values' do
- subject['abcdef'].should eq 'bcd'
- subject['ffffff'].should be_nil
+ expect(subject['abcdef']).to eq 'bcd'
+ expect(subject['ffffff']).to be_nil
end
end
diff --git a/spec/hashie/trash_spec.rb b/spec/hashie/trash_spec.rb
index 4bf4e45..91a5138 100644
--- a/spec/hashie/trash_spec.rb
+++ b/spec/hashie/trash_spec.rb
@@ -9,35 +9,35 @@ describe Hashie::Trash do
describe 'translating properties' do
it 'adds the property to the list' do
- TrashTest.properties.should include(:first_name)
+ expect(TrashTest.properties).to include(:first_name)
end
it 'creates a method for reading the property' do
- trash.should respond_to(:first_name)
+ expect(trash).to respond_to(:first_name)
end
it 'creates a method for writing the property' do
- trash.should respond_to(:first_name=)
+ expect(trash).to respond_to(:first_name=)
end
it 'creates a method for writing the translated property' do
- trash.should respond_to(:firstName=)
+ expect(trash).to respond_to(:firstName=)
end
it 'does not create a method for reading the translated property' do
- trash.should_not respond_to(:firstName)
+ expect(trash).not_to respond_to(:firstName)
end
it 'maintains translations hash mapping from the original to the translated name' do
- TrashTest.translations[:firstName].should eq :first_name
+ expect(TrashTest.translations[:firstName]).to eq :first_name
end
it 'maintains inverse translations hash mapping from the translated to the original name' do
- TrashTest.inverse_translations[:first_name].should eq :firstName
+ expect(TrashTest.inverse_translations[:first_name]).to eq :firstName
end
it '#permitted_input_keys contain the :from key of properties with translations' do
- TrashTest.permitted_input_keys.should include :firstName
+ expect(TrashTest.permitted_input_keys).to include :firstName
end
end
@@ -47,61 +47,61 @@ describe Hashie::Trash do
end
it '#permitted_input_keys contain names of properties without translations' do
- TrashTestPermitted.permitted_input_keys.should include :id
+ expect(TrashTestPermitted.permitted_input_keys).to include :id
end
end
describe 'writing to properties' do
it 'does not write to a non-existent property using []=' do
- lambda { trash['abc'] = 123 }.should raise_error(NoMethodError)
+ expect { trash['abc'] = 123 }.to raise_error(NoMethodError)
end
it 'writes to an existing property using []=' do
- lambda { trash['first_name'] = 'Bob' }.should_not raise_error
+ expect { trash['first_name'] = 'Bob' }.not_to raise_error
end
it 'writes to a translated property using []=' do
- lambda { trash['firstName'] = 'Bob' }.should_not raise_error
+ expect { trash['firstName'] = 'Bob' }.not_to raise_error
end
it 'reads/writes to an existing property using a method call' do
trash.first_name = 'Franklin'
- trash.first_name.should eq 'Franklin'
+ expect(trash.first_name).to eq 'Franklin'
end
it 'writes to an translated property using a method call' do
trash.firstName = 'Franklin'
- trash.first_name.should eq 'Franklin'
+ expect(trash.first_name).to eq 'Franklin'
end
it 'writes to a translated property using #replace' do
trash.replace(firstName: 'Franklin')
- trash.first_name.should eq 'Franklin'
+ expect(trash.first_name).to eq 'Franklin'
end
it 'writes to a non-translated property using #replace' do
trash.replace(first_name: 'Franklin')
- trash.first_name.should eq 'Franklin'
+ expect(trash.first_name).to eq 'Franklin'
end
end
describe ' initializing with a Hash' do
it 'does not initialize non-existent properties' do
- lambda { TrashTest.new(bork: 'abc') }.should raise_error(NoMethodError)
+ expect { TrashTest.new(bork: 'abc') }.to raise_error(NoMethodError)
end
it 'sets the desired properties' do
- TrashTest.new(first_name: 'Michael').first_name.should eq 'Michael'
+ expect(TrashTest.new(first_name: 'Michael').first_name).to eq 'Michael'
end
context 'with both the translated property and the property' do
it 'sets the desired properties' do
- TrashTest.new(first_name: 'Michael', firstName: 'Maeve').first_name.should eq 'Michael'
+ expect(TrashTest.new(first_name: 'Michael', firstName: 'Maeve').first_name).to eq 'Michael'
end
end
it 'sets the translated properties' do
- TrashTest.new(firstName: 'Michael').first_name.should eq 'Michael'
+ expect(TrashTest.new(firstName: 'Michael').first_name).to eq 'Michael'
end
end
@@ -113,21 +113,21 @@ describe Hashie::Trash do
let(:lambda_trash) { TrashLambdaTest.new }
it 'translates the value given on initialization with the given lambda' do
- TrashLambdaTest.new(firstName: 'Michael').first_name.should eq 'Michael'.reverse
+ expect(TrashLambdaTest.new(firstName: 'Michael').first_name).to eq 'Michael'.reverse
end
it 'does not translate the value if given with the right property' do
- TrashTest.new(first_name: 'Michael').first_name.should eq 'Michael'
+ expect(TrashTest.new(first_name: 'Michael').first_name).to eq 'Michael'
end
it 'translates the value given as property with the given lambda' do
lambda_trash.firstName = 'Michael'
- lambda_trash.first_name.should eq 'Michael'.reverse
+ expect(lambda_trash.first_name).to eq 'Michael'.reverse
end
it 'does not translate the value given as right property' do
lambda_trash.first_name = 'Michael'
- lambda_trash.first_name.should eq 'Michael'
+ expect(lambda_trash.first_name).to eq 'Michael'
end
end
@@ -140,12 +140,12 @@ describe Hashie::Trash do
it 'translates the value given as property with the given lambda' do
lambda_trash.firstName = 'Michael'
- lambda_trash.first_name.should eq 'Michael'.reverse
+ expect(lambda_trash.first_name).to eq 'Michael'.reverse
end
it 'does not translate the value given as right property' do
lambda_trash.first_name = 'Michael'
- lambda_trash.first_name.should eq 'Michael'
+ expect(lambda_trash.first_name).to eq 'Michael'
end
end
@@ -158,11 +158,11 @@ describe Hashie::Trash do
it 'translates the value given as property with the given lambda' do
lambda_trash.first_name = 'Michael'
- lambda_trash.first_name.should eq 'Michael'.reverse
+ expect(lambda_trash.first_name).to eq 'Michael'.reverse
end
it 'transforms the value when given in constructor' do
- TrashLambdaTestWithProperties.new(first_name: 'Michael').first_name.should eq 'Michael'.reverse
+ expect(TrashLambdaTestWithProperties.new(first_name: 'Michael').first_name).to eq 'Michael'.reverse
end
context 'when :from option is given' do
@@ -171,13 +171,13 @@ describe Hashie::Trash do
end
it 'does not override the :from option in the constructor' do
- TrashLambdaTest3.new(first_name: 'Michael').first_name.should eq 'Michael'
+ expect(TrashLambdaTest3.new(first_name: 'Michael').first_name).to eq 'Michael'
end
it 'does not override the :from option when given as property' do
t = TrashLambdaTest3.new
t.first_name = 'Michael'
- t.first_name.should eq 'Michael'
+ expect(t.first_name).to eq 'Michael'
end
end
diff --git a/spec/hashie/version_spec.rb b/spec/hashie/version_spec.rb
index 11d9e0b..0208ae0 100644
--- a/spec/hashie/version_spec.rb
+++ b/spec/hashie/version_spec.rb
@@ -2,6 +2,6 @@ require 'spec_helper'
describe Hashie do
it 'has a version' do
- Hashie::VERSION.should_not be_nil
+ expect(Hashie::VERSION).not_to be_nil
end
end