Sha256: 5242fb773a2f245efb2cef6b67e24e6c8f00bb542c1ec06888e4405a98b3e5f3

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

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

  let(:object) { described_class }

  shared_examples_for 'a correct time object' do
    it { should be_instance_of(Time) }

    its(:year)  { should == year  }
    its(:month) { should == month }
    its(:day)   { should == day   }
    its(:hour)  { should == hour  }
    its(:min)   { should == min   }
    its(:sec)   { should == sec   }
  end

  context 'with a valid time string' do
    let(:year)  { 2011 }
    let(:month) { 7    }
    let(:day)   { 22   }

    context 'not including time part' do
      let(:string) { "July, #{day}th, #{year}" }

      let(:hour) { 0 }
      let(:min)  { 0 }
      let(:sec)  { 0 }

      it_behaves_like 'a correct time object'
    end

    context 'including time part' do
      let(:string) { "July, #{day}, #{year}, #{hour}:#{min}:#{sec}" }

      let(:hour) { 13 }
      let(:min)  { 44 }
      let(:sec)  { 50 }

      it_behaves_like 'a correct time object'
    end
  end

  context 'with an invalid date time string' do
    let(:string) { '2999' }

    it { should equal(string) }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
virtus-0.0.10 spec/unit/virtus/coercion/string/class_methods/to_time_spec.rb
virtus-0.0.9 spec/unit/virtus/coercion/string/class_methods/to_time_spec.rb
virtus-0.0.8 spec/unit/virtus/coercion/string/class_methods/to_time_spec.rb
virtus-0.0.7 spec/unit/virtus/coercion/string/class_methods/to_time_spec.rb
virtus-0.0.6 spec/unit/virtus/coercion/string/class_methods/to_time_spec.rb