Sha256: c1a0feefd6a7d37bb67e421145c95ffa431d5ea657b3959bfab8aa046eb9d676

Contents?: true

Size: 1022 Bytes

Versions: 1

Compression:

Stored size: 1022 Bytes

Contents

require 'spec_helper'

RSpec.describe String do
  describe '#to_measurement' do
    describe 'with valid quantity' do
      subject { '3' }
      specify { expect(subject.to_measurement).to eq Measurement.new(3) }
    end
    
    describe 'with valid quantity and unit' do
      subject { '3 dozen' }
      specify { expect(subject.to_measurement).to eq Measurement.new(3, :dozen) }
    end
    
    describe 'with valid quantity and invalid unit' do
      subject { '3 people' }
      specify { expect { subject.to_measurement }.to raise_error }
    end
    
    describe 'with invalid input' do
      subject { 'foobar' }
      specify { expect { subject.to_measurement }.to raise_error }
    end
  end
  
  describe '#to_unit' do
    describe 'with valid unit' do
      subject { 'dozen' }
      specify { expect(subject.to_unit).to eq Measurement::Unit[:dozen] }
    end
    
    describe 'with invalid unit' do
      subject { 'person' }
      specify { expect { subject.to_unit }.to raise_error }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-measurement-1.2.2 spec/ruby-measurement/core_ext/string_spec.rb