Sha256: 68f4e59ed6cc6e01f219015a5b9cda5f0dbfd0d43866156f75f53df78deaf5b6

Contents?: true

Size: 869 Bytes

Versions: 9

Compression:

Stored size: 869 Bytes

Contents

require 'spec_helper'

describe Virtus::Coercion::TimeCoercions, '.to_time' do
  subject { object.to_time(value) }

  let(:object) { Class.new(Virtus::Coercion::Object) }
  let(:value)  { mock('value')                       }

  context 'when the value responds to #to_time' do
    before do
      object.extend Virtus::Coercion::TimeCoercions

      value.should_receive(:to_time).and_return(Time.utc(2011, 1, 1))
    end

    it { should be_instance_of(Time) }

    it { should eql(Time.utc(2011, 1, 1)) }
  end

  context 'when the value does not respond to #to_time' do
    before do
      object.extend Virtus::Coercion::TimeCoercions

      # use a string that Time.parse can handle
      value.should_receive(:to_s).and_return('Sat Jan 01 00:00:00 UTC 2011')
    end

    it { should be_instance_of(Time) }

    it { should eql(Time.utc(2011, 1, 1)) }
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
virtus-0.5.5 spec/unit/virtus/coercion/time_coercions/to_time_spec.rb
virtus-0.5.4 spec/unit/virtus/coercion/time_coercions/to_time_spec.rb
virtus-0.5.3 spec/unit/virtus/coercion/time_coercions/to_time_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/unit/virtus/coercion/time_coercions/to_time_spec.rb
virtus-0.5.2 spec/unit/virtus/coercion/time_coercions/to_time_spec.rb
virtus-0.5.1 spec/unit/virtus/coercion/time_coercions/to_time_spec.rb
virtus-0.5.0 spec/unit/virtus/coercion/time_coercions/to_time_spec.rb
virtus-0.4.2 spec/unit/virtus/coercion/time_coercions/to_time_spec.rb
virtus-0.4.1 spec/unit/virtus/coercion/time_coercions/to_time_spec.rb