diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/hashie/array_spec.rb | 32 | ||||
-rw-r--r-- | spec/hashie/extensions/coercion_spec.rb | 16 | ||||
-rw-r--r-- | spec/hashie/mash_spec.rb | 53 | ||||
-rw-r--r-- | spec/integration/omniauth/Rakefile | 3 | ||||
-rw-r--r-- | spec/support/integration_specs.rb | 9 |
5 files changed, 52 insertions, 61 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 diff --git a/spec/integration/omniauth/Rakefile b/spec/integration/omniauth/Rakefile index 9c220f7..c611f39 100644 --- a/spec/integration/omniauth/Rakefile +++ b/spec/integration/omniauth/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :perf do task :setup do require 'omniauth' @@ -12,6 +14,7 @@ namespace :perf do def call_app(path = ENV['GET_PATH'] || '/') result = @app.get(path) raise "Did not succeed #{result.body}" unless result.status == 200 + result end end diff --git a/spec/support/integration_specs.rb b/spec/support/integration_specs.rb index ea0da53..431167d 100644 --- a/spec/support/integration_specs.rb +++ b/spec/support/integration_specs.rb @@ -1,10 +1,17 @@ +require File.expand_path('../../../lib/hashie/extensions/ruby_version', __FILE__) + # Generates the bundle command for running an integration test # # @param [String] integration the integration folder to run # @param [String] command the command to run # @return [String] def integration_command(integration, command) - "#{integration_gemfile(integration)} #{command}" + if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= + Hashie::Extensions::RubyVersion.new('3.1.0') + ruby_opts = "RUBYOPT=--disable-error_highlight " + end + + "#{ruby_opts}#{integration_gemfile(integration)} #{command}" end # Generates the Gemfile for an integration |