spec/acfs/resource/attributes/uuid_spec.rb in acfs-1.0.0.dev.1.b305 vs spec/acfs/resource/attributes/uuid_spec.rb in acfs-1.0.0
- old
+ new
@@ -1,63 +1,40 @@
require 'spec_helper'
describe Acfs::Resource::Attributes::UUID do
- let(:model) { Class.new Acfs::Resource }
- let(:params) { {} }
- let(:instance) { described_class.new params }
- subject { instance }
+ let(:type) { Acfs::Resource::Attributes::UUID.new }
- describe '#cast_type' do
- let(:param) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
- let(:action) { instance.cast param }
- subject { action }
+ describe '#cast' do
+ subject { -> { type.cast(value) } }
- context 'with String as param' do
- context 'with valid UUID' do
- let(:param) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
- it { should be_a String }
- it { should eq param }
- end
+ context 'with nil' do
+ let(:value) { nil }
+ it { expect(subject.call).to eq nil }
+ end
- context 'with invalid UUID' do
- subject { -> { action } }
+ context 'with empty string' do
+ let(:value) { '' }
+ it { expect(subject.call).to eq nil }
+ end
- context 'with random non-empty string' do
- let(:param) { 'invalid string' }
- it { should raise_error ArgumentError }
- end
+ context 'with blank string' do
+ let(:value) { " \t" }
+ it { expect(subject.call).to eq nil }
+ end
- context 'with UUID string containing invalid characters' do
- let(:param) { 'xxxxxxxx-yyyy-11e3-baa8-0800200c9a66' }
- it { should raise_error ArgumentError }
- end
+ context 'with string UUID' do
+ let(:value) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
+ it { expect(subject.call).to be_a String }
+ it { expect(subject.call).to eq value }
+ end
- context 'with empty string' do
- let(:param) { '' }
-
- context 'with allow_nil option' do
- let(:params) { {allow_nil: true} }
- subject { action }
- it { should eq nil }
- end
-
- context 'without allow_nil option' do
- let(:params) { {allow_nil: false} }
- it { should raise_error ArgumentError }
- end
- end
- end
+ context 'with invalid string' do
+ let(:value) { 'invalid string' }
+ it { is_expected.to raise_error TypeError, /invalid UUID/i }
end
- context 'with non-String as param' do
- subject { -> { action } }
-
- invalid_params = {fixnum: 1, float: 3.2, symbol: :invalid, boolean: true}
- invalid_params.each do |type, incorrect_param|
- context "with #{type} as param" do
- let(:param) { incorrect_param }
- it { should raise_error ArgumentError }
- end
- end
+ context 'with invalid UUID' do
+ let(:value) { 'xxxxxxxx-yyyy-11e3-baa8-0800200c9a66' }
+ it { is_expected.to raise_error TypeError, /invalid UUID/i }
end
end
end