forked from solnic/virtus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_datetime_spec.rb
50 lines (37 loc) · 1.16 KB
/
to_datetime_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'spec_helper'
describe Virtus::Typecast::String, '.to_datetime' do
subject { object.to_datetime(string) }
let(:object) { described_class }
shared_examples_for 'a correct datetime object' do
it { should be_instance_of(DateTime) }
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 date 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 datetime 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 datetime object'
end
end
context 'with an invalid date time string' do
let(:string) { 'non-datetime' }
it { should equal(string) }
end
end