Sha256: 01564457fab1073d47324bb9f5fdc140087eb20ad157e8d5885b5fac1c0d54fc
Contents?: true
Size: 1.79 KB
Versions: 3
Compression:
Stored size: 1.79 KB
Contents
# frozen_string_literal: true shared_examples 'a variable method to formated string' do |method, format| subject { described_class.new(arguments) } let(:name) { :delta } let(:value) { 10.0 } let(:arguments) { { name: name, latex: '\delta', gnuplot: 'del' } } context "when #{format} is not defined" do before { arguments.delete(format) } it 'returns name' do expect(subject.public_send(method)).to eq('delta') end context 'when value is defined' do before { arguments[:value] = value } it_behaves_like 'a method that display the numeric value', method end end context "when #{format} has been defined" do it "returns #{format}" do expect(subject.public_send(method)).to eq(arguments[format]) end end end shared_examples 'a method that display the numeric value' do |method| context 'when value should be integer' do let(:value) { 10.0 } it 'returns the value integer string' do expect(subject.public_send(method)).to eq('10') end context 'when passing the decimals argument' do it 'returns the value float string' do expect(subject.public_send(method, decimals: 4)).to eq('10') end end end context 'when value should be a float' do let(:value) { 10 / 3.0 } it 'returns the value float string' do expect(subject.public_send(method)).to eq('3.3333333333333335') end context 'when passing the decimals argument' do it 'returns the value float string' do expect(subject.public_send(method, decimals: 4)).to eq('3.3333') end end context 'when the number has less decimals' do let(:value) { 10.5 } it 'returns the value integer string' do expect(subject.public_send(method, decimals: 4)).to eq('10.5') end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
danica-2.7.7 | spec/support/shared_examples/variable.rb |
danica-2.7.6 | spec/support/shared_examples/variable.rb |
danica-2.7.5 | spec/support/shared_examples/variable.rb |