Sha256: 7647d33cf9e2ccb807887ea97c551cfbe83292fff225a3596acfd65bb3528d27
Contents?: true
Size: 1.75 KB
Versions: 4
Compression:
Stored size: 1.75 KB
Contents
shared_examples 'a variable method to formated string' do |method, format| let(:name) { :delta } let(:value) { 10.0 } let(:arguments) { { name: name, latex: '\delta', gnuplot: 'del' } } subject { described_class.new(arguments) } 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 'and 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 'and 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 'but 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
4 entries across 4 versions & 1 rubygems