spec/support/shared_examples/operator/chained.rb in danica-2.7.4 vs spec/support/shared_examples/operator/chained.rb in danica-2.7.5

- old
+ new

@@ -1,20 +1,23 @@ +# frozen_string_literal: true + shared_examples 'a operator that joins many variables with same operation' do |arguments| it_behaves_like 'a operator that knows how to calculate', arguments it_behaves_like 'a operator that knows how to write to tex', arguments it_behaves_like 'a operator that knows how to write to gnu', arguments end shared_examples 'a operator that knows how to calculate' do |arguments| - include_context 'variables are initialized', arguments, 'calculated' + include_context 'when variables are initialized', arguments, 'calculated' + subject { described_class.new(*variables) } + let(:variables) do (1..4).map do |i| - { name: "X#{i}", value: numeric_variables[i-1] } + { name: "X#{i}", value: numeric_variables[i - 1] } end end - let(:numeric_variables){ (1..4).to_a } - subject { described_class.new(*variables) } + let(:numeric_variables) { (1..4).to_a } describe 'to_f' do it 'returns the addition of variables value' do expect(subject.to_f).to eq(calculated) end @@ -44,14 +47,15 @@ shared_examples 'a operator that knows how to write to gnu' do |arguments| it_behaves_like 'a operator that knows how to write to a string', :gnu, arguments end shared_examples 'a operator that knows how to write to a string' do |format, arguments| - let(:numeric_variables) { arguments[:numeric_variables] } - include_context 'variables are initialized', arguments[format], *%w(integer_expected string_expected float_expected) subject { described_class.new(*variables) } + let(:numeric_variables) { arguments[:numeric_variables] } + include_context 'when variables are initialized', arguments[format], 'integer_expected', 'string_expected', 'float_expected' + describe "#to(#{format})" do let(:variables) do (1..4).map { |i| "X#{i}" } end @@ -61,10 +65,11 @@ end end context 'when some variables have values' do let(:numeric_variables_index) { 1 } + before do (0..numeric_variables_index).each do |i| subject.variables[i].value = numeric_variables[i] end end @@ -82,9 +87,10 @@ end end context 'when some variables are numbers' do let(:numeric_variables_index) { 1 } + before do (0..numeric_variables_index).each do |i| variables[i] = numeric_variables[i] end end