summaryrefslogtreecommitdiff
path: root/spec/hashie
diff options
context:
space:
mode:
Diffstat (limited to 'spec/hashie')
-rw-r--r--spec/hashie/array_spec.rb32
-rw-r--r--spec/hashie/extensions/coercion_spec.rb16
-rw-r--r--spec/hashie/mash_spec.rb53
3 files changed, 41 insertions, 60 deletions
diff --git a/spec/hashie/array_spec.rb b/spec/hashie/array_spec.rb
index 0c35b1e..ee14a82 100644
--- a/spec/hashie/array_spec.rb
+++ b/spec/hashie/array_spec.rb
@@ -1,28 +1,26 @@
require 'spec_helper'
describe Array do
- with_minimum_ruby('2.3.0') do
- describe '#dig' do
- let(:array) { Hashie::Array.new(%i[a b c]) }
+ describe '#dig' do
+ let(:array) { Hashie::Array.new(%i[a b c]) }
- it 'works with a string index' do
- expect(array.dig('0')).to eq(:a)
- end
+ it 'works with a string index' do
+ expect(array.dig('0')).to eq(:a)
+ end
- it 'works with a numeric index' do
- expect(array.dig(1)).to eq(:b)
- end
+ it 'works with a numeric index' do
+ expect(array.dig(1)).to eq(:b)
+ end
- context 'when array is empty' do
- let(:array) { Hashie::Array.new([]) }
+ context 'when array is empty' do
+ let(:array) { Hashie::Array.new([]) }
- it 'works with a first numeric and next string index' do
- expect(array.dig(0, 'hello')).to eq(nil)
- end
+ it 'works with a first numeric and next string index' do
+ expect(array.dig(0, 'hello')).to eq(nil)
+ end
- it 'throws an error with first string and next numeric index' do
- expect { array.dig('hello', 0) }.to raise_error(TypeError)
- end
+ it 'throws an error with first string and next numeric index' do
+ expect { array.dig('hello', 0) }.to raise_error(TypeError)
end
end
end
diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb
index 72265e1..9931ed4 100644
--- a/spec/hashie/extensions/coercion_spec.rb
+++ b/spec/hashie/extensions/coercion_spec.rb
@@ -563,13 +563,7 @@ describe Hashie::Extensions::Coercion do
end
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')
- Integer
- else
- Fixnum
- end
+ type = Integer
subject.coerce_value type, Symbol
expect { instance[:hi] = 1 }.to raise_error(
@@ -578,13 +572,7 @@ describe Hashie::Extensions::Coercion do
end
it 'coerces Integer to String' do
- type =
- if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >=
- Hashie::Extensions::RubyVersion.new('2.4.0')
- Integer
- else
- Fixnum
- end
+ type = Integer
subject.coerce_value type, String
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index 84a28ea..03f5668 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -649,8 +649,7 @@ describe Hashie::Mash do
context 'when key does not exist' do
it 'raises KeyError' do
- error = RUBY_VERSION =~ /1.8/ ? IndexError : KeyError
- expect { mash.fetch(:two) }.to raise_error(error)
+ expect { mash.fetch(:two) }.to raise_error(KeyError)
end
context 'with default value given' do
@@ -980,44 +979,40 @@ describe Hashie::Mash do
end
end
- with_minimum_ruby('2.3.0') do
- describe '#dig' do
- subject { described_class.new(a: { b: 1 }) }
+ describe '#dig' do
+ subject { described_class.new(a: { b: 1 }) }
- it 'accepts both string and symbol as key' do
- expect(subject.dig(:a, :b)).to eq(1)
- expect(subject.dig('a', 'b')).to eq(1)
- end
+ it 'accepts both string and symbol as key' do
+ expect(subject.dig(:a, :b)).to eq(1)
+ expect(subject.dig('a', 'b')).to eq(1)
+ end
- context 'when the Mash wraps a Hashie::Array' do
- it 'handles digging into an array' do
- mash = described_class.new(alphabet: { first_three: Hashie::Array['a', 'b', 'c'] })
+ context 'when the Mash wraps a Hashie::Array' do
+ it 'handles digging into an array' do
+ mash = described_class.new(alphabet: { first_three: Hashie::Array['a', 'b', 'c'] })
- expect(mash.dig(:alphabet, :first_three, 0)).to eq 'a'
- end
+ expect(mash.dig(:alphabet, :first_three, 0)).to eq 'a'
end
end
end
- with_minimum_ruby('2.4.0') do
- describe '#transform_values' do
- subject(:mash) { described_class.new(a: 1) }
+ describe '#transform_values' do
+ subject(:mash) { described_class.new(a: 1) }
- it 'returns a Hashie::Mash' do
- expect(mash.transform_values(&:to_s)).to be_kind_of(described_class)
- end
+ it 'returns a Hashie::Mash' do
+ expect(mash.transform_values(&:to_s)).to be_kind_of(described_class)
+ end
- it 'transforms the value' do
- expect(mash.transform_values(&:to_s).a).to eql('1')
- end
+ it 'transforms the value' do
+ expect(mash.transform_values(&:to_s).a).to eql('1')
+ end
- context 'when using with subclass' do
- let(:subclass) { Class.new(Hashie::Mash) }
- subject(:sub_mash) { subclass.new(a: 1).transform_values { |a| a + 2 } }
+ context 'when using with subclass' do
+ let(:subclass) { Class.new(Hashie::Mash) }
+ subject(:sub_mash) { subclass.new(a: 1).transform_values { |a| a + 2 } }
- it 'creates an instance of subclass' do
- expect(sub_mash).to be_kind_of(subclass)
- end
+ it 'creates an instance of subclass' do
+ expect(sub_mash).to be_kind_of(subclass)
end
end