spec/acfs/resource/attributes/integer_spec.rb in acfs-0.45.0 vs spec/acfs/resource/attributes/integer_spec.rb in acfs-0.46.0
- old
+ new
@@ -1,19 +1,34 @@
require 'spec_helper'
describe Acfs::Resource::Attributes::Integer do
- subject { Acfs::Resource::Attributes::Integer.new }
+ let(:type) { Acfs::Resource::Attributes::Integer.new }
- describe 'cast' do
- it 'should cast integer strings' do
- expect(subject.cast('123')).to eq 123
+ describe '#cast' do
+ subject { -> { type.cast value } }
+
+ context 'with nil' do
+ let(:value) { nil }
+ it { expect(subject.call).to eq nil }
end
- it 'should cast empty string (backward compatibility)' do
- expect(subject.cast('')).to eq 0
+ context 'with empty string' do
+ let(:value) { '' }
+ it { expect(subject.call).to eq 0 }
end
- it 'should not cast invalid integers' do
- expect { subject.cast 'abc' }.to raise_error TypeError
+ context 'with blank string' do
+ let(:value) { " \t" }
+ it { expect(subject.call).to eq 0 }
+ end
+
+ context 'with string' do
+ let(:value) { '123' }
+ it { expect(subject.call).to eq 123 }
+ end
+
+ context 'with invalid string' do
+ let(:value) { '123a' }
+ it { is_expected.to raise_error ArgumentError }
end
end
end