Sha256: 3d391d599dcb6439038fa8bc6c4e48e6258a98642d0bb3e6e80f19356da58cd4
Contents?: true
Size: 1.88 KB
Versions: 3
Compression:
Stored size: 1.88 KB
Contents
require 'spec_helper' describe 'Transproc / Coercions' do describe 'to_string' do it 'turns integer into a string' do expect(Transproc(:to_string)[1]).to eql('1') end end describe 'to_integer' do it 'turns string into an integer' do expect(Transproc(:to_integer)['1']).to eql(1) end end describe 'to_float' do it 'turns string into a float' do expect(Transproc(:to_float)['1']).to eql(1.0) end it 'turns integer into a float' do expect(Transproc(:to_float)[1]).to eql(1.0) end end describe 'to_decimal' do it 'turns string into a decimal' do expect(Transproc(:to_decimal)['1.251']).to eql(BigDecimal('1.251')) end it 'turns float into a decimal' do expect(Transproc(:to_decimal)[1.251]).to eql(BigDecimal('1.251')) end it 'turns integer into a decimal' do expect(Transproc(:to_decimal)[1]).to eql(BigDecimal('1.0')) end end describe 'to_date' do it 'turns string into a date' do date = Date.new(1983, 11, 18) expect(Transproc(:to_date)['18th, November 1983']).to eql(date) end end describe 'to_time' do it 'turns string into a time object' do time = Time.new(2012, 1, 23, 11, 7, 7) expect(Transproc(:to_time)['2012-01-23 11:07:07']).to eql(time) end end describe 'to_datetime' do it 'turns string into a date' do datetime = DateTime.new(2012, 1, 23, 11, 7, 7) expect(Transproc(:to_datetime)['2012-01-23 11:07:07']).to eql(datetime) end end describe 'to_boolean' do subject(:coercer) { Transproc(:to_boolean) } Transproc::TRUE_VALUES.each do |value| it "turns #{value.inspect} to true" do expect(coercer[value]).to be(true) end end Transproc::FALSE_VALUES.each do |value| it "turns #{value.inspect} to false" do expect(coercer[value]).to be(false) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
transproc-0.1.2 | spec/integration/coercions_spec.rb |
transproc-0.1.1 | spec/integration/coercions_spec.rb |
transproc-0.1.0 | spec/integration/coercions_spec.rb |