Sha256: e4a9102fcd81e13d74abc9b114936516905dcea02ec0d3ced066ecec09de21c0

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

describe Coercer::String, '.to_decimal' do
  subject { object.to_decimal(string) }

  let(:object) { described_class.new }

  {
    '1'       => BigDecimal('1.0'),
    '+1'      => BigDecimal('1.0'),
    '-1'      => BigDecimal('-1.0'),
    '1.0'     => BigDecimal('1.0'),
    '1.0e+1'  => BigDecimal('10.0'),
    '1.0e-1'  => BigDecimal('0.1'),
    '1.0E+1'  => BigDecimal('10.0'),
    '1.0E-1'  => BigDecimal('0.1'),
    '+1.0'    => BigDecimal('1.0'),
    '+1.0e+1' => BigDecimal('10.0'),
    '+1.0e-1' => BigDecimal('0.1'),
    '+1.0E+1' => BigDecimal('10.0'),
    '+1.0E-1' => BigDecimal('0.1'),
    '-1.0'    => BigDecimal('-1.0'),
    '-1.0e+1' => BigDecimal('-10.0'),
    '-1.0e-1' => BigDecimal('-0.1'),
    '-1.0E+1' => BigDecimal('-10.0'),
    '-1.0E-1' => BigDecimal('-0.1'),
    '.1'      => BigDecimal('0.1'),
    '.1e+1'   => BigDecimal('1.0'),
    '.1e-1'   => BigDecimal('0.01'),
    '.1E+1'   => BigDecimal('1.0'),
    '.1E-1'   => BigDecimal('0.01'),
  }.each do |value, expected|
    context "with #{value.inspect}" do
      let(:string) { value }

      it { should be_instance_of(BigDecimal) }

      it { should eql(expected) }
    end
  end

  context 'with an invalid decimal string' do
    let(:string) { 'non-decimal' }

    it { should equal(string) }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
coercible-0.2.0 spec/unit/coercible/coercer/string/to_decimal_spec.rb
coercible-0.1.0 spec/unit/coercible/coercer/string/to_decimal_spec.rb
coercible-0.0.2 spec/unit/coercible/coercer/string/to_decimal_spec.rb
coercible-0.0.1 spec/unit/coercible/coercer/string/to_decimal_spec.rb