diff --git a/lib/ruby-measurement/definitions/us_customary/volume.rb b/lib/ruby-measurement/definitions/us_customary/volume.rb index aeae6b3..ec56938 100644 --- a/lib/ruby-measurement/definitions/us_customary/volume.rb +++ b/lib/ruby-measurement/definitions/us_customary/volume.rb @@ -8,6 +8,8 @@ unit.convert_to(:'fl oz') { |value| value * 128.0 } unit.convert_to(:tbsp) { |value| value * 256.0 } unit.convert_to(:tsp) { |value| value * 768.0 } + unit.convert_to(:ml) { |value| value * 3785.411784 } + unit.convert_to(:l) { |value| value * 3.785411784 } end Measurement.define(:'qt.') do |unit| @@ -18,6 +20,8 @@ unit.convert_to(:'fl oz') { |value| value * 32.0 } unit.convert_to(:tbsp) { |value| value * 64.0 } unit.convert_to(:tsp) { |value| value * 192.0 } + unit.convert_to(:ml) { |value| value * 946.352946 } + unit.convert_to(:l) { |value| value * 0.946352946 } end Measurement.define(:'pt.') do |unit| @@ -28,6 +32,8 @@ unit.convert_to(:'fl oz') { |value| value * 16.0 } unit.convert_to(:tbsp) { |value| value * 32.0 } unit.convert_to(:tsp) { |value| value * 96.0 } + unit.convert_to(:ml) { |value| value * 473.176473 } + unit.convert_to(:l) { |value| value * 0.473176473 } end Measurement.define(:'c.') do |unit| @@ -38,6 +44,8 @@ unit.convert_to(:'fl oz') { |value| value * 8.0 } unit.convert_to(:tbsp) { |value| value * 16.0 } unit.convert_to(:tsp) { |value| value * 48.0 } + unit.convert_to(:ml) { |value| value * 236.5882365 } + unit.convert_to(:l) { |value| value * 0.2365882365 } end Measurement.define(:'fl. oz.') do |unit| @@ -48,6 +56,8 @@ unit.convert_to(:c) { |value| value / 8.0 } unit.convert_to(:tbsp) { |value| value * 2.0 } unit.convert_to(:tsp) { |value| value * 6.0 } + unit.convert_to(:ml) { |value| value * 29.5735295625 } + unit.convert_to(:l) { |value| value * 0.0295735295625 } end Measurement.define(:'tbsp.') do |unit| @@ -58,6 +68,8 @@ unit.convert_to(:c) { |value| value / 16.0 } unit.convert_to(:'fl oz') { |value| value / 2.0 } unit.convert_to(:tsp) { |value| value * 3.0 } + unit.convert_to(:ml) { |value| value * 14.786764781 } + unit.convert_to(:l) { |value| value * 0.014786764781 } end Measurement.define(:'tsp.') do |unit| @@ -68,4 +80,6 @@ unit.convert_to(:c) { |value| value / 48.0 } unit.convert_to(:'fl oz') { |value| value / 6.0 } unit.convert_to(:tbsp) { |value| value / 3.0 } + unit.convert_to(:ml) { |value| value * 4.9289215938 } + unit.convert_to(:l) { |value| value * 0.0049289215938 } end diff --git a/spec/ruby-measurement/core_ext/string_spec.rb b/spec/ruby-measurement/core_ext/string_spec.rb index dd3adef..8b4521a 100644 --- a/spec/ruby-measurement/core_ext/string_spec.rb +++ b/spec/ruby-measurement/core_ext/string_spec.rb @@ -14,12 +14,12 @@ describe 'with valid quantity and invalid unit' do subject { '3 people' } - specify { expect { subject.to_measurement }.to raise_error } + specify { expect { subject.to_measurement }.to raise_error(ArgumentError) } end describe 'with invalid input' do subject { 'foobar' } - specify { expect { subject.to_measurement }.to raise_error } + specify { expect { subject.to_measurement }.to raise_error(ArgumentError) } end end @@ -31,7 +31,7 @@ describe 'with invalid unit' do subject { 'person' } - specify { expect { subject.to_unit }.to raise_error } + specify { expect { subject.to_unit }.to raise_error(ArgumentError) } end end end diff --git a/spec/ruby-measurement/core_ext/symbol_spec.rb b/spec/ruby-measurement/core_ext/symbol_spec.rb index 0e41e54..cb2cfed 100644 --- a/spec/ruby-measurement/core_ext/symbol_spec.rb +++ b/spec/ruby-measurement/core_ext/symbol_spec.rb @@ -9,7 +9,7 @@ describe 'with invalid unit' do subject { :person } - specify { expect { subject.to_unit }.to raise_error } + specify { expect { subject.to_unit }.to raise_error(ArgumentError) } end end end diff --git a/spec/ruby-measurement/definitions/us_customary/volume_spec.rb b/spec/ruby-measurement/definitions/us_customary/volume_spec.rb index fd78b3c..6f31e79 100644 --- a/spec/ruby-measurement/definitions/us_customary/volume_spec.rb +++ b/spec/ruby-measurement/definitions/us_customary/volume_spec.rb @@ -29,6 +29,14 @@ it 'converts to teaspoons' do expect(subject.convert_to(:tsp).quantity).to eq 768 end + + it 'converts to milliliters' do + expect(subject.convert_to(:ml).quantity).to eq 3785.411784 + end + + it 'converts to liters' do + expect(subject.convert_to(:l).quantity).to eq 3.785411784 + end end describe 'quarts' do @@ -57,6 +65,14 @@ it 'converts to teaspoons' do expect(subject.convert_to(:tsp).quantity).to eq 768 end + + it 'converts to milliliters' do + expect(subject.convert_to(:ml).quantity).to eq 3785.411784 + end + + it 'converts to liters' do + expect(subject.convert_to(:l).quantity).to eq 3.785411784 + end end describe 'pints' do @@ -85,6 +101,14 @@ it 'converts to teaspoons' do expect(subject.convert_to(:tsp).quantity).to eq 768 end + + it 'converts to milliliters' do + expect(subject.convert_to(:ml).quantity).to eq 3785.411784 + end + + it 'converts to liters' do + expect(subject.convert_to(:l).quantity).to eq 3.785411784 + end end describe 'cups' do @@ -113,6 +137,14 @@ it 'converts to teaspoons' do expect(subject.convert_to(:tsp).quantity).to eq 768 end + + it 'converts to milliliters' do + expect(subject.convert_to(:ml).quantity).to eq 3785.411784 + end + + it 'converts to liters' do + expect(subject.convert_to(:l).quantity).to eq 3.785411784 + end end describe 'fluid ounces' do @@ -141,6 +173,14 @@ it 'converts to teaspoons' do expect(subject.convert_to(:tsp).quantity).to eq 768 end + + it 'converts to milliliters' do + expect(subject.convert_to(:ml).quantity).to eq 3785.411784 + end + + it 'converts to liters' do + expect(subject.convert_to(:l).quantity).to eq 3.785411784 + end end describe 'tablespoons' do @@ -169,6 +209,14 @@ it 'converts to teaspoons' do expect(subject.convert_to(:tsp).quantity).to eq 768 end + + it 'converts to milliliters' do + expect(subject.convert_to(:ml).quantity).to eq 3785.411783936 + end + + it 'converts to liters' do + expect(subject.convert_to(:l).quantity).to eq 3.785411783936 + end end describe 'teaspoons' do @@ -197,5 +245,13 @@ it 'converts to tablespoons' do expect(subject.convert_to(:tbsp).quantity).to eq 256 end + + it 'converts to milliliters' do + expect(subject.convert_to(:ml).quantity).to eq 3785.4117840384 + end + + it 'converts to liters' do + expect(subject.convert_to(:l).quantity).to eq 3.7854117840384 + end end end diff --git a/spec/ruby-measurement/measurement_spec.rb b/spec/ruby-measurement/measurement_spec.rb index c2c16c2..846d0a2 100644 --- a/spec/ruby-measurement/measurement_spec.rb +++ b/spec/ruby-measurement/measurement_spec.rb @@ -38,13 +38,13 @@ describe 'with invalid quantity' do it 'raises exception' do - expect { subject.new('hi') }.to raise_exception + expect { subject.new('hi') }.to raise_error(ArgumentError) end end describe 'with invalid unit' do it 'raises exception' do - expect { subject.new(3, :finklebaum) }.to raise_exception + expect { subject.new(3, :finklebaum) }.to raise_error(ArgumentError) end end end @@ -146,7 +146,7 @@ end it 'raises exception when undefined' do - expect { subject.parse('3 finklebaums') }.to raise_error + expect { subject.parse('3 finklebaums') }.to raise_error(ArgumentError) end end end @@ -174,11 +174,11 @@ end it 'raises exception if unit exists and is not convertable' do - expect { measurement.convert_to(:inches) }.to raise_error + expect { measurement.convert_to(:inches) }.to raise_error(ArgumentError) end it 'raises exception if unit does not exist' do - expect { measurement.convert_to(:finklebaum) }.to raise_error + expect { measurement.convert_to(:finklebaum) }.to raise_error(ArgumentError) end end @@ -222,7 +222,7 @@ it 'raises exception for incompatible units' do other = subject.new(4, :inches) expect(other.unit).to_not eq measurement.unit - expect { measurement + other }.to raise_error + expect { measurement + other }.to raise_error(ArgumentError) end end @@ -256,7 +256,7 @@ it 'raises exception for incompatible units' do other = subject.new(4, :inches) expect(other.unit).to_not eq measurement.unit - expect { measurement - other }.to raise_error + expect { measurement - other }.to raise_error(ArgumentError) end end @@ -290,7 +290,7 @@ it 'raises exception for incompatible units' do other = subject.new(4, :inches) expect(other.unit).to_not eq measurement.unit - expect { measurement * other }.to raise_error + expect { measurement * other }.to raise_error(ArgumentError) end end @@ -324,7 +324,7 @@ it 'raises exception for incompatible units' do other = subject.new(4, :inches) expect(other.unit).to_not eq measurement.unit - expect { measurement / other }.to raise_error + expect { measurement / other }.to raise_error(ArgumentError) end end @@ -336,7 +336,7 @@ end it 'raises exception for non-numeric values' do - expect { measurement ** subject.new(3) }.to raise_error + expect { measurement ** subject.new(3) }.to raise_error(ArgumentError) end end