spec/lib/danica/variables_holder_spec.rb in danica-2.4.3 vs spec/lib/danica/variables_holder_spec.rb in danica-2.4.4

- old
+ new

@@ -18,10 +18,19 @@ Danica::Wrapper::Number.new(10) ]) end end +shared_examples 'an variable set that does not change the class variables' do + it 'does not change the the class variables' do + expect do + subject.variables = variables + end.not_to change { clazz.variables_hash } + end +end + + describe Danica::VariablesHolder do class Danica::VariablesHolder::Dummy include Danica::Common include Danica::VariablesHolder @@ -45,38 +54,61 @@ expect(clazz.variables_names).to eq(%i(x y z)) end end describe '#variables=' do - before do - subject.variables = variables + context 'when changing the variables of the object' do + context 'when all the variables are set with value' do + let(:variables) { [1, 2, 3] } + it_behaves_like 'an variable set that does not change the class variables' + end + + context 'setting the variables through a hash' do + let(:variables) { { x: 1, y: 2, z: 3 } } + it_behaves_like 'an variable set that does not change the class variables' + end + + context 'when none of the variables are set with values' do + let(:variables) { [] } + it_behaves_like 'an variable set that does not change the class variables' + end + + context 'when the variables are set through an empty hash' do + let(:variables) { {} } + it_behaves_like 'an variable set that does not change the class variables' + end end context 'when setting the variables using a list' do + before do + subject.variables = variables + end let(:variables) { [1, 2, 3] } it 'changes the values of the variables' do expect(subject.x).to eq(Danica::Wrapper::Number.new(1)) end context 'but the array is empty' do let(:variables) { [] } - it_behaves_like 'an object that returns the default variables hash' end end context 'when setting the variales using a hash' do + before do + subject.variables = variables + end + let(:variables) { { x: 1, y: 2, z: 3 } } it 'changes the values of the variables' do expect(subject.x).to eq(Danica::Wrapper::Number.new(1)) end context 'but the hash is empty' do let(:variables) { {} } - it_behaves_like 'an object that returns the default variables hash' end end end @@ -142,9 +174,25 @@ subject.y = 1 end it 'returns the values' do expect(subject.variables_value_hash).to eq({x: nil, y: 1, z: 10}) + end + end + end + + describe '#containers' do + it 'is an array of Containers' do + expect(subject.containers.first).to be_a(Danica::Wrapper::Container) + end + + context 'when changing the variable on the object' do + let(:containers) { subject.containers } + + it 'changes the variables in the containers' do + expect do + subject.x = 2 + end.to change { containers.map(&:content) } end end end end