Sha256: b662d999f2d199b73359fb7600f75f13bb940de5c6bd7f7be6e38b558d36cb87
Contents?: true
Size: 1.96 KB
Versions: 15
Compression:
Stored size: 1.96 KB
Contents
require 'spec_helper' describe Virtus::AttributeSet, '#each' do subject(:attribute_set) { described_class.new(parent, attributes) } let(:name) { :name } let(:attribute) { Virtus::Attribute.build(String, :name => :name) } let(:attributes) { [ attribute ] } let(:parent) { described_class.new } let(:yields) { Set[] } context 'with no block' do it 'returns an enumerator when block is not provided' do expect(attribute_set.each).to be_kind_of(Enumerator) end it 'yields the expected attributes' do result = [] attribute_set.each { |attribute| result << attribute } expect(result).to eql(attributes) end end context 'with a block' do subject { attribute_set.each { |attribute| yields << attribute } } context 'when the parent has no attributes' do it { is_expected.to equal(attribute_set) } it 'yields the expected attributes' do expect { subject }.to change { yields.dup }. from(Set[]). to(attributes.to_set) end end context 'when the parent has attributes that are not duplicates' do let(:parent_attribute) { Virtus::Attribute.build(String, :name => :parent_name) } let(:parent) { described_class.new([ parent_attribute ]) } it { is_expected.to equal(attribute_set) } it 'yields the expected attributes' do result = [] attribute_set.each { |attribute| result << attribute } expect(result).to eql([parent_attribute, attribute]) end end context 'when the parent has attributes that are duplicates' do let(:parent_attribute) { Virtus::Attribute.build(String, :name => name) } let(:parent) { described_class.new([ parent_attribute ]) } it { is_expected.to equal(attribute_set) } it 'yields the expected attributes' do expect { subject }.to change { yields.dup }. from(Set[]). to(Set[ attribute ]) end end end end
Version data entries
15 entries across 13 versions & 5 rubygems