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