diff --git a/spec/active_interaction/filters/array_filter_spec.rb b/spec/active_interaction/filters/array_filter_spec.rb index 43a27848..ac484132 100644 --- a/spec/active_interaction/filters/array_filter_spec.rb +++ b/spec/active_interaction/filters/array_filter_spec.rb @@ -36,11 +36,13 @@ end describe '#cast' do + let(:result) { filter.cast(value) } + context 'with an Array' do let(:value) { [] } it 'returns the Array' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -48,7 +50,7 @@ let(:value) { [[], false, 0.0, {}, 0, '', :''] } it 'returns the Array' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -59,7 +61,7 @@ let(:value) { [] } it 'returns the Array' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -67,7 +69,7 @@ let(:value) { [[]] } it 'returns the Array' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -76,7 +78,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end diff --git a/spec/active_interaction/filters/date_filter_spec.rb b/spec/active_interaction/filters/date_filter_spec.rb index 4642cfb5..b8decb7c 100644 --- a/spec/active_interaction/filters/date_filter_spec.rb +++ b/spec/active_interaction/filters/date_filter_spec.rb @@ -15,11 +15,13 @@ end describe '#cast' do + let(:result) { filter.cast(value) } + context 'with a Date' do let(:value) { Date.new } it 'returns the Date' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -27,7 +29,7 @@ let(:value) { '2011-12-13' } it 'returns a Date' do - expect(filter.cast(value)).to eql Date.parse(value) + expect(result).to eql Date.parse(value) end context 'with format' do @@ -36,7 +38,7 @@ let(:value) { '13/12/2011' } it 'returns a Date' do - expect(filter.cast(value)).to eql Date.strptime(value, format) + expect(result).to eql Date.strptime(value, format) end end end @@ -46,7 +48,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end @@ -55,7 +57,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end @@ -74,7 +76,7 @@ end it 'returns a Date' do - expect(filter.cast(value)).to eql Date.new(year, month, day) + expect(result).to eql Date.new(year, month, day) end end @@ -84,7 +86,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end @@ -98,7 +100,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end diff --git a/spec/active_interaction/filters/date_time_filter_spec.rb b/spec/active_interaction/filters/date_time_filter_spec.rb index 7c21a814..37ad6c61 100644 --- a/spec/active_interaction/filters/date_time_filter_spec.rb +++ b/spec/active_interaction/filters/date_time_filter_spec.rb @@ -15,11 +15,13 @@ end describe '#cast' do + let(:result) { filter.cast(value) } + context 'with a Datetime' do let(:value) { DateTime.new } it 'returns the DateTime' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -27,7 +29,7 @@ let(:value) { '2011-12-13T14:15:16+17:18' } it 'returns a DateTime' do - expect(filter.cast(value)).to eql DateTime.parse(value) + expect(result).to eql DateTime.parse(value) end context 'with format' do @@ -36,7 +38,7 @@ let(:value) { '13/12/2011 14:15:16 +17:18' } it 'returns a DateTime' do - expect(filter.cast(value)).to eql DateTime.strptime(value, format) + expect(result).to eql DateTime.strptime(value, format) end end end @@ -46,7 +48,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end @@ -55,7 +57,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end @@ -81,7 +83,7 @@ it 'returns a DateTime' do expect( - filter.cast(value) + result ).to eql DateTime.new(year, month, day, hour, min, sec) end end @@ -92,7 +94,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end @@ -106,7 +108,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end diff --git a/spec/active_interaction/filters/decimal_filter_spec.rb b/spec/active_interaction/filters/decimal_filter_spec.rb index c058ec6b..9ffd86cf 100644 --- a/spec/active_interaction/filters/decimal_filter_spec.rb +++ b/spec/active_interaction/filters/decimal_filter_spec.rb @@ -15,11 +15,13 @@ end describe '#cast' do + let(:result) { filter.cast(value) } + context 'with a Float' do let(:value) { rand } it 'returns the BigDecimal' do - expect(filter.cast(value)).to eql BigDecimal.new(value, 0) + expect(result).to eql BigDecimal.new(value, 0) end context 'with :digits option' do @@ -28,7 +30,7 @@ let(:value) { 1.23456789 } it 'returns BigDecimal with given digits' do - expect(filter.cast(value)).to eql BigDecimal.new('1.235') + expect(result).to eql BigDecimal.new('1.235') end end end @@ -37,7 +39,7 @@ let(:value) { rand(1 << 16) } it 'returns a BigDecimal' do - expect(filter.cast(value)).to eql BigDecimal.new(value) + expect(result).to eql BigDecimal.new(value) end end @@ -45,7 +47,7 @@ let(:value) { rand.to_s } it 'returns a BigDecimal' do - expect(filter.cast(value)).to eql BigDecimal.new(value) + expect(result).to eql BigDecimal.new(value) end end @@ -54,7 +56,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end diff --git a/spec/active_interaction/filters/file_filter_spec.rb b/spec/active_interaction/filters/file_filter_spec.rb index 46a6c63f..69e129fc 100644 --- a/spec/active_interaction/filters/file_filter_spec.rb +++ b/spec/active_interaction/filters/file_filter_spec.rb @@ -7,11 +7,13 @@ it_behaves_like 'a filter' describe '#cast' do + let(:result) { filter.cast(value) } + context 'with a File' do let(:value) { File.new(__FILE__) } it 'returns the File' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -19,7 +21,7 @@ let(:value) { Tempfile.new(SecureRandom.hex) } it 'returns the Tempfile' do - expect(filter.cast(value)).to eq value + expect(result).to eq value end end @@ -27,7 +29,7 @@ let(:value) { double(tempfile: Tempfile.new(SecureRandom.hex)) } it 'returns the Tempfile' do - expect(filter.cast(value)).to eq value.tempfile + expect(result).to eq value.tempfile end end end diff --git a/spec/active_interaction/filters/float_filter_spec.rb b/spec/active_interaction/filters/float_filter_spec.rb index e8794fee..e759ef3c 100644 --- a/spec/active_interaction/filters/float_filter_spec.rb +++ b/spec/active_interaction/filters/float_filter_spec.rb @@ -7,11 +7,13 @@ it_behaves_like 'a filter' describe '#cast' do + let(:result) { filter.cast(value) } + context 'with a Float' do let(:value) { rand } it 'returns the Float' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -19,7 +21,7 @@ let(:value) { rand(1 << 16) } it 'returns a Float' do - expect(filter.cast(value)).to eql value.to_f + expect(result).to eql value.to_f end end @@ -27,7 +29,7 @@ let(:value) { rand.to_s } it 'returns a Float' do - expect(filter.cast(value)).to eql Float(value) + expect(result).to eql Float(value) end end @@ -36,7 +38,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end diff --git a/spec/active_interaction/filters/hash_filter_spec.rb b/spec/active_interaction/filters/hash_filter_spec.rb index d41de9b5..492896e5 100644 --- a/spec/active_interaction/filters/hash_filter_spec.rb +++ b/spec/active_interaction/filters/hash_filter_spec.rb @@ -15,11 +15,13 @@ end describe '#cast' do + let(:result) { filter.cast(value) } + context 'with a Hash' do let(:value) { {} } it 'returns the Hash' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -27,7 +29,7 @@ let(:value) { { a: {} } } it 'returns an empty Hash' do - expect(filter.cast(value)).to eql({}) + expect(result).to eql({}) end end @@ -38,7 +40,7 @@ let(:value) { { a: {} } } it 'returns the Hash' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end context 'with String keys' do @@ -47,7 +49,7 @@ end it 'does not raise an error' do - expect { filter.cast(value) }.to_not raise_error + expect { result }.to_not raise_error end end end @@ -59,13 +61,13 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidNestedValueError end it 'populates the error' do begin - filter.cast(value) + result rescue ActiveInteraction::InvalidNestedValueError => e expect(e.filter_name).to eql k expect(e.input_value).to eql v @@ -82,11 +84,11 @@ end it 'symbolizes String keys' do - expect(filter.cast(value)).to have_key :a + expect(result).to have_key :a end it 'leaves other keys alone' do - expect(filter.cast(value)).to have_key 1 + expect(result).to have_key 1 end end end diff --git a/spec/active_interaction/filters/integer_filter_spec.rb b/spec/active_interaction/filters/integer_filter_spec.rb index 553280cc..be6ca7c2 100644 --- a/spec/active_interaction/filters/integer_filter_spec.rb +++ b/spec/active_interaction/filters/integer_filter_spec.rb @@ -7,11 +7,13 @@ it_behaves_like 'a filter' describe '#cast' do + let(:result) { filter.cast(value) } + context 'with an Integer' do let(:value) { rand(1 << 16) } it 'returns the Integer' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -19,7 +21,7 @@ let(:value) { rand(1 << 16) + rand } it 'returns an Integer' do - expect(filter.cast(value)).to eql value.to_i + expect(result).to eql value.to_i end end @@ -27,7 +29,7 @@ let(:value) { rand(1 << 16).to_s } it 'returns an Integer' do - expect(filter.cast(value)).to eql Integer(value) + expect(result).to eql Integer(value) end end @@ -36,7 +38,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end diff --git a/spec/active_interaction/filters/model_filter_spec.rb b/spec/active_interaction/filters/model_filter_spec.rb index af6268a4..37b19e16 100644 --- a/spec/active_interaction/filters/model_filter_spec.rb +++ b/spec/active_interaction/filters/model_filter_spec.rb @@ -14,14 +14,15 @@ class Model; end describe '#cast' do let(:value) { Model.new } + let(:result) { filter.cast(value) } context 'with class as a Class' do it 'returns the instance' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end it 'handles reconstantizing' do - expect(filter.cast(value)).to eql value + expect(result).to eql value Object.send(:remove_const, :Model) class Model; end @@ -69,7 +70,7 @@ def self.name end it 'returns the instance' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -79,7 +80,7 @@ def self.name end it 'returns the instance' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -90,7 +91,7 @@ def self.name it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidClassError end end diff --git a/spec/active_interaction/filters/string_filter_spec.rb b/spec/active_interaction/filters/string_filter_spec.rb index 0aecc742..bf3356dd 100644 --- a/spec/active_interaction/filters/string_filter_spec.rb +++ b/spec/active_interaction/filters/string_filter_spec.rb @@ -13,11 +13,13 @@ end describe '#cast' do + let(:result) { filter.cast(value) } + context 'with a String' do let(:value) { SecureRandom.hex } it 'returns the String' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -25,14 +27,14 @@ let(:value) { " #{SecureRandom.hex} " } it 'returns the stripped string' do - expect(filter.cast(value)).to eql value.strip + expect(result).to eql value.strip end context 'without strip' do include_context 'without strip' it 'returns the String' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end end diff --git a/spec/active_interaction/filters/symbol_filter_spec.rb b/spec/active_interaction/filters/symbol_filter_spec.rb index 3000e045..bfc9ad0f 100644 --- a/spec/active_interaction/filters/symbol_filter_spec.rb +++ b/spec/active_interaction/filters/symbol_filter_spec.rb @@ -7,11 +7,13 @@ it_behaves_like 'a filter' describe '#cast' do + let(:result) { filter.cast(value) } + context 'with a Symbol' do let(:value) { SecureRandom.hex.to_sym } it 'returns the Symbol' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -19,7 +21,7 @@ let(:value) { SecureRandom.hex } it 'returns a Symbol' do - expect(filter.cast(value)).to eql value.to_sym + expect(result).to eql value.to_sym end end end diff --git a/spec/active_interaction/filters/time_filter_spec.rb b/spec/active_interaction/filters/time_filter_spec.rb index c10c7b03..b44a6c16 100644 --- a/spec/active_interaction/filters/time_filter_spec.rb +++ b/spec/active_interaction/filters/time_filter_spec.rb @@ -15,11 +15,13 @@ end describe '#cast' do + let(:result) { filter.cast(value) } + context 'with a Time' do let(:value) { Time.new } it 'returns the Time' do - expect(filter.cast(value)).to eql value + expect(result).to eql value end end @@ -27,7 +29,7 @@ let(:value) { '2011-12-13 14:15:16 +1718' } it 'returns a Time' do - expect(filter.cast(value)).to eql Time.parse(value) + expect(result).to eql Time.parse(value) end context 'with format' do @@ -36,7 +38,7 @@ let(:value) { '13/12/2011 14:15:16 +1718' } it 'returns a Time' do - expect(filter.cast(value)).to eql Time.strptime(value, format) + expect(result).to eql Time.strptime(value, format) end end end @@ -46,7 +48,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end @@ -55,7 +57,7 @@ it do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end @@ -81,7 +83,7 @@ it 'returns a Time' do expect( - filter.cast(value) + result ).to eql Time.new(year, month, day, hour, min, sec) end end @@ -92,7 +94,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end @@ -106,7 +108,7 @@ it 'raises an error' do expect do - filter.cast(value) + result end.to raise_error ActiveInteraction::InvalidValueError end end