Sha256: 7e9b11bd2dd032b8e6a6029adb6d95f25ce99b230d46c5881fa9b7c9fb93d1ca

Contents?: true

Size: 1.29 KB

Versions: 13

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

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

  let(:object) { described_class }

  {
    '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

13 entries across 13 versions & 2 rubygems

Version Path
virtus-0.5.5 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.5.4 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.5.3 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.5.2 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.5.1 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.5.0 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.4.2 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.4.1 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.4.0 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.3.0 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.2.0 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
virtus-0.1.0 spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb