iso8601 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,78 +59,77 @@ describe ISO8601::DateTime do
59
59
  context 'reduced patterns' do
60
60
  it "should parse correctly reduced dates" do
61
61
  reduced_date = ISO8601::DateTime.new('20100509')
62
- reduced_date.year.should == 2010
63
- reduced_date.month.should == 5
64
- reduced_date.day.should == 9
62
+ expect(reduced_date.year).to eq(2010)
63
+ expect(reduced_date.month).to eq(5)
64
+ expect(reduced_date.day).to eq(9)
65
65
  end
66
66
  it "should parse correctly reduced times" do
67
67
  reduced_time = ISO8601::DateTime.new('T101112Z')
68
- reduced_time.hour.should == 10
69
- reduced_time.minute.should == 11
70
- reduced_time.second.should == 12
68
+ expect(reduced_time.hour).to eq(10)
69
+ expect(reduced_time.minute).to eq(11)
70
+ expect(reduced_time.second).to eq(12)
71
71
  end
72
72
  it "should parse correctly reduced date times" do
73
73
  reduced_datetime = ISO8601::DateTime.new('20140531T101112Z')
74
- reduced_datetime.year.should == 2014
75
- reduced_datetime.month.should == 5
76
- reduced_datetime.day.should == 31
77
- reduced_datetime.hour.should == 10
78
- reduced_datetime.minute.should == 11
79
- reduced_datetime.second.should == 12
74
+ expect(reduced_datetime.year).to eq(2014)
75
+ expect(reduced_datetime.month).to eq(5)
76
+ expect(reduced_datetime.day).to eq(31)
77
+ expect(reduced_datetime.hour).to eq(10)
78
+ expect(reduced_datetime.minute).to eq(11)
79
+ expect(reduced_datetime.second).to eq(12)
80
80
  end
81
81
  end
82
82
 
83
83
  it "should return each atomic value" do
84
84
  dt = ISO8601::DateTime.new('2010-05-09T12:02:01+04:00')
85
- dt.year.should == 2010
86
- dt.month.should == 5
87
- dt.day.should == 9
88
- dt.hour.should == 12
89
- dt.minute.should == 2
90
- dt.second.should == 1
91
- dt.zone.should == '+04:00'
85
+ expect(dt.year).to eq(2010)
86
+ expect(dt.month).to eq(5)
87
+ expect(dt.day).to eq(9)
88
+ expect(dt.hour).to eq(12)
89
+ expect(dt.minute).to eq(2)
90
+ expect(dt.second).to eq(1)
91
+ expect(dt.zone).to eq('+04:00')
92
92
  end
93
93
 
94
94
  it "should return the right sign for the given year" do
95
- ISO8601::DateTime.new('-2014-05-31T16:26:00Z').year.should == -2014
96
- ISO8601::DateTime.new('+2014-05-31T16:26:00Z').year.should == 2014
95
+ expect(ISO8601::DateTime.new('-2014-05-31T16:26:00Z').year).to eq(-2014)
96
+ expect(ISO8601::DateTime.new('+2014-05-31T16:26:00Z').year).to eq(2014)
97
97
  end
98
98
 
99
99
  it "should respond to delegated casting methods" do
100
100
  dt = ISO8601::DateTime.new('2014-12-11T10:09:08Z')
101
- dt.should respond_to(:to_s, :to_time, :to_date, :to_datetime)
101
+ expect(dt).to respond_to(:to_s, :to_time, :to_date, :to_datetime)
102
102
  end
103
103
 
104
104
  describe '#+' do
105
105
  it "should return the result of the addition" do
106
- (ISO8601::DateTime.new('2012-07-07T20:20:20Z') + 10).to_s.should == '2012-07-07T20:20:30+00:00'
107
- (ISO8601::DateTime.new('2012-07-07T20:20:20.5Z') + 10).to_s.should == '2012-07-07T20:20:30.50+00:00'
108
- (ISO8601::DateTime.new('2012-07-07T20:20:20+02:00') + 10).to_s.should == '2012-07-07T20:20:30+02:00'
106
+ expect((ISO8601::DateTime.new('2012-07-07T20:20:20Z') + 10).to_s).to eq('2012-07-07T20:20:30+00:00')
107
+ expect((ISO8601::DateTime.new('2012-07-07T20:20:20.5Z') + 10).to_s).to eq('2012-07-07T20:20:30.50+00:00')
108
+ expect((ISO8601::DateTime.new('2012-07-07T20:20:20+02:00') + 10).to_s).to eq('2012-07-07T20:20:30+02:00')
109
109
  end
110
110
  end
111
111
 
112
112
  describe '#-' do
113
113
  it "should return the result of the substraction" do
114
- (ISO8601::DateTime.new('2012-07-07T20:20:20Z') - 10).to_s.should == '2012-07-07T20:20:10+00:00'
114
+ expect((ISO8601::DateTime.new('2012-07-07T20:20:20Z') - 10).to_s).to eq('2012-07-07T20:20:10+00:00')
115
115
  end
116
116
  end
117
117
 
118
118
  describe '#to_a' do
119
119
  it "should return an array of atoms" do
120
120
  dt = ISO8601::DateTime.new('2014-05-31T19:29:39Z').to_a
121
- dt.should be_kind_of(Array)
122
- dt.should == [2014, 5, 31, 19, 29, 39, '+00:00']
121
+ expect(dt).to be_kind_of(Array)
122
+ expect(dt).to eq([2014, 5, 31, 19, 29, 39, '+00:00'])
123
123
  end
124
124
  end
125
125
 
126
126
  describe '#hash' do
127
127
  it "should return the datetime hash" do
128
128
  subject = ISO8601::DateTime.new('2014-08-16T20:11:10Z')
129
- contrast = ::DateTime.new(2014, 8, 16, 20, 11, 10, 'Z')
129
+ contrast = ISO8601::DateTime.new('2014-08-16T20:11:10Z')
130
130
 
131
- expect(subject).to respond_to(:hash)
131
+ expect(subject.hash == contrast.hash).to be_truthy
132
132
  expect(subject.hash).to eq(contrast.hash)
133
133
  end
134
134
  end
135
-
136
135
  end
@@ -2,8 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe ISO8601::Duration do
5
+ RSpec.describe ISO8601::Duration do
6
6
  it "should raise a ISO8601::Errors::UnknownPattern for any unknown pattern" do
7
+ expect { ISO8601::Duration.new('') }.to raise_error(ISO8601::Errors::UnknownPattern)
7
8
  expect { ISO8601::Duration.new('P') }.to raise_error(ISO8601::Errors::UnknownPattern)
8
9
  expect { ISO8601::Duration.new('PT') }.to raise_error(ISO8601::Errors::UnknownPattern)
9
10
  expect { ISO8601::Duration.new('P1YT') }.to raise_error(ISO8601::Errors::UnknownPattern)
@@ -43,33 +44,42 @@ describe ISO8601::Duration do
43
44
  end
44
45
  it "should raise a TypeError when the base is not a ISO8601::DateTime" do
45
46
  expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S', ISO8601::DateTime.new('2010-01-01')) }.to_not raise_error
46
- expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S', '2010-01-01') }.to raise_error(TypeError)
47
- expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S', 2010) }.to raise_error(TypeError)
47
+ expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S', '2010-01-01') }.to raise_error(ISO8601::Errors::TypeError)
48
+ expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S', 2010) }.to raise_error(ISO8601::Errors::TypeError)
48
49
  expect {
49
50
  d = ISO8601::Duration.new('P1Y1M1DT1H1M1S', ISO8601::DateTime.new('2010-01-01'))
50
51
  d.base = 2012
51
- }.to raise_error(TypeError)
52
+ }.to raise_error(ISO8601::Errors::TypeError)
52
53
  end
53
54
 
54
55
  it "should return a Duration instance from a Numeric input" do
55
- ISO8601::Duration.new(36993906, ISO8601::DateTime.new('2012-01-01')).should == ISO8601::Duration.new('P1Y2M3DT4H5M6S', ISO8601::DateTime.new('2012-01-01'))
56
+ subject = ISO8601::Duration.new(36993906, ISO8601::DateTime.new('2012-01-01'))
57
+ contrast = ISO8601::Duration.new('P1Y2M3DT4H5M6S', ISO8601::DateTime.new('2012-01-01'))
58
+ expect(subject.to_seconds).to eq(contrast.to_seconds)
56
59
  end
57
60
 
58
61
  describe '#base' do
59
62
  it "should return the base datetime" do
60
63
  dt = ISO8601::DateTime.new('2010-01-01')
61
64
  dt2 = ISO8601::DateTime.new('2012-01-01')
62
- ISO8601::Duration.new('P1Y1M1DT1H1M1S').base.should be_an_instance_of(NilClass)
63
- ISO8601::Duration.new('P1Y1M1DT1H1M1S', dt).base.should be_an_instance_of(ISO8601::DateTime)
64
- ISO8601::Duration.new('P1Y1M1DT1H1M1S', dt).base.should equal(dt)
65
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S').base).to be_an_instance_of(NilClass)
66
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S', dt).base).to be_an_instance_of(ISO8601::DateTime)
67
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S', dt).base).to eq(dt)
65
68
  d = ISO8601::Duration.new('P1Y1M1DT1H1M1S', dt).base = dt2
66
- d.should equal(dt2)
69
+ expect(d).to eq(dt2)
70
+ end
71
+ end
72
+
73
+ describe '#pattern' do
74
+ it "should return the duration pattern" do
75
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S').pattern).to eq('P1Y1M1DT1H1M1S')
76
+ expect(ISO8601::Duration.new(60).pattern).to eq('PT60S')
67
77
  end
68
78
  end
69
79
 
70
80
  describe '#to_s' do
71
81
  it "should return the duration as a string" do
72
- ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_s.should == 'P1Y1M1DT1H1M1S'
82
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_s).to eq('P1Y1M1DT1H1M1S')
73
83
  end
74
84
  end
75
85
 
@@ -79,165 +89,184 @@ describe ISO8601::Duration do
79
89
  end
80
90
 
81
91
  it "should return the result of the addition" do
82
- (ISO8601::Duration.new('P1Y1M1DT1H1M1S') + ISO8601::Duration.new('PT10S')).to_s.should == 'P1Y1M1DT1H1M11S'
83
- (ISO8601::Duration.new('P1Y1M1DT1H1M1S') + ISO8601::Duration.new('PT10S')).should be_an_instance_of(ISO8601::Duration)
92
+ expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') + ISO8601::Duration.new('P1Y1M1DT1H1M1S')).to_s).to eq('P12Y2M2DT2H2M2S')
93
+ expect((ISO8601::Duration.new('P1Y1M1DT1H1M1S') + ISO8601::Duration.new('PT10S')).to_s).to eq('P1Y1M1DT1H1M11S')
94
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S') + ISO8601::Duration.new('PT10S')).to be_an_instance_of(ISO8601::Duration)
84
95
  end
85
96
  end
86
97
 
87
98
  describe '#-' do
88
- it "should raise an ISO8601::Errors::DurationBaseError" do
99
+ it "should raise an ISO8601::Errors::DurationBaseError when bases mismatch" do
89
100
  expect { ISO8601::Duration.new('PT1H', ISO8601::DateTime.new('2000-01-01')) - ISO8601::Duration.new('PT1H') }.to raise_error(ISO8601::Errors::DurationBaseError)
90
101
  end
91
102
 
92
103
  it "should return the result of the substraction" do
93
- (ISO8601::Duration.new('P1Y1M1DT1H1M1S') - ISO8601::Duration.new('PT10S')).should be_an_instance_of(ISO8601::Duration)
94
- (ISO8601::Duration.new('P1Y1M1DT1H1M11S') - ISO8601::Duration.new('PT10S')).to_s.should == 'P1Y1M1DT1H1M1S'
95
- (ISO8601::Duration.new('PT12S') - ISO8601::Duration.new('PT12S')).to_s.should == 'PT0S'
96
- (ISO8601::Duration.new('PT12S') - ISO8601::Duration.new('PT1S')).to_s.should == 'PT11S'
97
- (ISO8601::Duration.new('PT1S') - ISO8601::Duration.new('PT12S')).to_s.should == '-PT11S'
98
- (ISO8601::Duration.new('PT1S') - ISO8601::Duration.new('-PT12S')).to_s.should == 'PT13S'
104
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S') - ISO8601::Duration.new('PT10S')).to be_an_instance_of(ISO8601::Duration)
105
+ expect((ISO8601::Duration.new('P1Y1M1DT1H1M11S') - ISO8601::Duration.new('PT10S')).to_s).to eq('P1Y1M1DT1H1M1S')
106
+ expect((ISO8601::Duration.new('P1Y1M1DT1H1M11S') - ISO8601::Duration.new('P1Y1M1DT1H1M11S')).to_s).to eq('PT0S')
107
+ expect((ISO8601::Duration.new('PT12S') - ISO8601::Duration.new('PT12S')).to_s).to eq('PT0S')
108
+ expect((ISO8601::Duration.new('PT12S') - ISO8601::Duration.new('PT1S')).to_s).to eq('PT11S')
109
+ expect((ISO8601::Duration.new('PT1S') - ISO8601::Duration.new('PT12S')).to_s).to eq('-PT11S')
110
+ expect((ISO8601::Duration.new('PT1S') - ISO8601::Duration.new('-PT12S')).to_s).to eq('PT13S')
99
111
  end
100
112
  end
101
113
 
102
114
  describe '#to_seconds' do
103
115
  context 'positive durations' do
104
116
  it "should return the seconds of a P[n]Y duration in a common year" do
105
- ISO8601::Duration.new('P2Y', ISO8601::DateTime.new('2010-01-01')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2010, 1))
117
+ expect(ISO8601::Duration.new('P2Y', ISO8601::DateTime.new('2010-01-01')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2010, 1))
106
118
  end
107
119
  it "should return the seconds of a P[n]Y duration in a leap year" do
108
- ISO8601::Duration.new('P2Y', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2002, 1) - Time.utc(2000, 1))
120
+ expect(ISO8601::Duration.new('P2Y', ISO8601::DateTime.new('2000-01-01')).to_seconds).to eq(Time.utc(2002, 1) - Time.utc(2000, 1))
109
121
  end
110
122
  it "should return the seconds of a P[n]Y[n]M duration in a common year" do
111
- ISO8601::Duration.new('P2Y3M', ISO8601::DateTime.new('2010-01-01')).to_seconds.should == (Time.utc(2012, 4) - Time.utc(2010, 1))
123
+ expect(ISO8601::Duration.new('P2Y3M', ISO8601::DateTime.new('2010-01-01')).to_seconds).to eq(Time.utc(2012, 4) - Time.utc(2010, 1))
112
124
  end
113
125
  it "should return the seconds of a P[n]Y[n]M duration in a leap year" do
114
- ISO8601::Duration.new('P2Y3M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2002, 4) - Time.utc(2000, 1))
126
+ expect(ISO8601::Duration.new('P2Y3M', ISO8601::DateTime.new('2000-01-01')).to_seconds).to eq(Time.utc(2002, 4) - Time.utc(2000, 1))
115
127
  end
116
128
  it "should return the seconds of a P[n]M duration in a common year" do
117
- ISO8601::Duration.new('P1M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 2) - Time.utc(2012, 1))
118
- ISO8601::Duration.new('P2M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 3) - Time.utc(2012, 1))
119
- ISO8601::Duration.new('P19M', ISO8601::DateTime.new('2012-05-01')).to_seconds.should == (Time.utc(2014, 12) - Time.utc(2012, 5))
120
- ISO8601::Duration.new('P14M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2013, 3) - Time.utc(2012, 1))
129
+ expect(ISO8601::Duration.new('P1M', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 2) - Time.utc(2012, 1))
130
+ expect(ISO8601::Duration.new('P2M', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 3) - Time.utc(2012, 1))
131
+ expect(ISO8601::Duration.new('P19M', ISO8601::DateTime.new('2012-05-01')).to_seconds).to eq(Time.utc(2014, 12) - Time.utc(2012, 5))
132
+ expect(ISO8601::Duration.new('P14M', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2013, 3) - Time.utc(2012, 1))
121
133
  end
122
134
  it "should return the seconds of a P[n]M duration in a leap year" do
123
- ISO8601::Duration.new('P1M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2000, 2) - Time.utc(2000, 1))
124
- ISO8601::Duration.new('P2M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2000, 3) - Time.utc(2000, 1))
125
- ISO8601::Duration.new('P14M', ISO8601::DateTime.new('2000-01-01')).to_seconds.should == (Time.utc(2001, 3) - Time.utc(2000, 1))
135
+ expect(ISO8601::Duration.new('P1M', ISO8601::DateTime.new('2000-01-01')).to_seconds).to eq(Time.utc(2000, 2) - Time.utc(2000, 1))
136
+ expect(ISO8601::Duration.new('P2M', ISO8601::DateTime.new('2000-01-01')).to_seconds).to eq(Time.utc(2000, 3) - Time.utc(2000, 1))
137
+ expect(ISO8601::Duration.new('P14M', ISO8601::DateTime.new('2000-01-01')).to_seconds).to eq(Time.utc(2001, 3) - Time.utc(2000, 1))
126
138
  end
127
139
  it "should return the seconds of a P[n]Y[n]M[n]D duration" do
128
- ISO8601::Duration.new('P2Y11D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2014, 1, 12) - Time.utc(2012, 1))
129
- ISO8601::Duration.new('P1Y1M1D', ISO8601::DateTime.new('2010-05-01')).to_seconds.should == (Time.utc(2011, 6, 2) - Time.utc(2010, 5))
140
+ expect(ISO8601::Duration.new('P2Y11D', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2014, 1, 12) - Time.utc(2012, 1))
141
+ expect(ISO8601::Duration.new('P1Y1M1D', ISO8601::DateTime.new('2010-05-01')).to_seconds).to eq(Time.utc(2011, 6, 2) - Time.utc(2010, 5))
130
142
  end
131
143
  it "should return the seconds of a P[n]D duration" do
132
- ISO8601::Duration.new('P1D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 2) - Time.utc(2012, 1, 1))
133
- ISO8601::Duration.new('P11D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 12) - Time.utc(2012, 1, 1))
134
- ISO8601::Duration.new('P3M11D', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 4, 12) - Time.utc(2012, 1))
144
+ expect(ISO8601::Duration.new('P1D', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 1, 2) - Time.utc(2012, 1, 1))
145
+ expect(ISO8601::Duration.new('P11D', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 1, 12) - Time.utc(2012, 1, 1))
146
+ expect(ISO8601::Duration.new('P3M11D', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 4, 12) - Time.utc(2012, 1))
135
147
  end
136
148
  it "should return the seconds of a P[n]W duration" do
137
- ISO8601::Duration.new('P2W', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 15) - Time.utc(2012, 1))
138
- ISO8601::Duration.new('P2W', ISO8601::DateTime.new('2012-02-01')).to_seconds.should == (Time.utc(2012, 2, 15) - Time.utc(2012, 2))
149
+ expect(ISO8601::Duration.new('P2W', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 1, 15) - Time.utc(2012, 1))
150
+ expect(ISO8601::Duration.new('P2W', ISO8601::DateTime.new('2012-02-01')).to_seconds).to eq(Time.utc(2012, 2, 15) - Time.utc(2012, 2))
139
151
  end
140
152
 
141
153
  it "should return the seconds of a PT[n]H duration" do
142
- ISO8601::Duration.new('PT5H', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 5) - Time.utc(2012, 1))
143
- ISO8601::Duration.new('P1YT5H', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2013, 1, 1, 5) - Time.utc(2012, 1))
154
+ expect(ISO8601::Duration.new('PT5H', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 1, 1, 5) - Time.utc(2012, 1))
155
+ expect(ISO8601::Duration.new('P1YT5H', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2013, 1, 1, 5) - Time.utc(2012, 1))
144
156
  end
145
157
 
146
158
  it "should return the seconds of a PT[n]H[n]M duration" do
147
- ISO8601::Duration.new('PT5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 0, 5) - Time.utc(2012, 1))
148
- ISO8601::Duration.new('PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 1, 5) - Time.utc(2012, 1))
149
- ISO8601::Duration.new('PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == ISO8601::Duration.new('PT65M', ISO8601::DateTime.new('2012-01-01')).to_seconds
159
+ expect(ISO8601::Duration.new('PT5M', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 1, 1, 0, 5) - Time.utc(2012, 1))
160
+ expect(ISO8601::Duration.new('PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 1, 1, 1, 5) - Time.utc(2012, 1))
161
+ expect(ISO8601::Duration.new('PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(ISO8601::Duration.new('PT65M', ISO8601::DateTime.new('2012-01-01')).to_seconds)
150
162
  end
151
163
 
152
164
  it "should return the seconds of a PT[n]H[n]M duration" do
153
- ISO8601::Duration.new('PT10S', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2012, 1, 1, 0, 0, 10) - Time.utc(2012, 1))
154
- ISO8601::Duration.new('PT10.4S', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == 10.4
165
+ expect(ISO8601::Duration.new('PT10S', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2012, 1, 1, 0, 0, 10) - Time.utc(2012, 1))
166
+ expect(ISO8601::Duration.new('PT10.4S', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(10.4)
155
167
  end
156
168
  end
157
169
 
158
170
  context 'negative durations' do
159
171
  it "should return the seconds of a -P[n]Y duration" do
160
- ISO8601::Duration.new('-P2Y', ISO8601::DateTime.new('2010-01-01')).to_seconds.should == (Time.utc(2008, 1) - Time.utc(2010, 1))
172
+ expect(ISO8601::Duration.new('-P2Y', ISO8601::DateTime.new('2010-01-01')).to_seconds).to eq(Time.utc(2008, 1) - Time.utc(2010, 1))
161
173
  end
162
174
  it "should return the seconds of a -P[n]Y duration in a leap year" do
163
- ISO8601::Duration.new('-P2Y', ISO8601::DateTime.new('2001-01-01')).to_seconds.should == (Time.utc(1999, 1) - Time.utc(2001, 1))
175
+ expect(ISO8601::Duration.new('-P2Y', ISO8601::DateTime.new('2001-01-01')).to_seconds).to eq(Time.utc(1999, 1) - Time.utc(2001, 1))
164
176
  end
165
177
  it "should return the seconds of a -P[n]Y[n]M duration in a common year" do
166
- ISO8601::Duration.new('-P2Y3M', ISO8601::DateTime.new('2010-01-01')).to_seconds.should == (Time.utc(2007, 10) - Time.utc(2010, 1))
178
+ expect(ISO8601::Duration.new('-P2Y3M', ISO8601::DateTime.new('2010-01-01')).to_seconds).to eq(Time.utc(2007, 10) - Time.utc(2010, 1))
167
179
  end
168
180
  it "should return the seconds of a -P[n]Y[n]M duration in a leap year" do
169
- ISO8601::Duration.new('-P2Y3M', ISO8601::DateTime.new('2001-01-01')).to_seconds.should == (Time.utc(1998, 10) - Time.utc(2001, 1))
181
+ expect(ISO8601::Duration.new('-P2Y3M', ISO8601::DateTime.new('2001-01-01')).to_seconds).to eq(Time.utc(1998, 10) - Time.utc(2001, 1))
170
182
  end
171
183
  it "should return the seconds of a -P[n]M duration in a common year" do
172
- ISO8601::Duration.new('-P1M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == (Time.utc(2011, 12) - Time.utc(2012, 1))
173
- ISO8601::Duration.new('-P1M', ISO8601::DateTime.new('2012-02-01')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 2))
174
- ISO8601::Duration.new('-P2M', ISO8601::DateTime.new('2012-03-01')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 3))
175
- ISO8601::Duration.new('-P36M', ISO8601::DateTime.new('2013-03-01')).to_seconds.should == (Time.utc(2010, 3) - Time.utc(2013, 3))
176
- ISO8601::Duration.new('-P39M', ISO8601::DateTime.new('2013-03-01')).to_seconds.should == (Time.utc(2009, 12) - Time.utc(2013, 3))
177
- ISO8601::Duration.new('-P156M', ISO8601::DateTime.new('2013-03-01')).to_seconds.should == (Time.utc(2000, 3) - Time.utc(2013, 3))
184
+ expect(ISO8601::Duration.new('-P1M', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(Time.utc(2011, 12) - Time.utc(2012, 1))
185
+ expect(ISO8601::Duration.new('-P1M', ISO8601::DateTime.new('2012-02-01')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2012, 2))
186
+ expect(ISO8601::Duration.new('-P2M', ISO8601::DateTime.new('2012-03-01')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2012, 3))
187
+ expect(ISO8601::Duration.new('-P36M', ISO8601::DateTime.new('2013-03-01')).to_seconds).to eq(Time.utc(2010, 3) - Time.utc(2013, 3))
188
+ expect(ISO8601::Duration.new('-P39M', ISO8601::DateTime.new('2013-03-01')).to_seconds).to eq(Time.utc(2009, 12) - Time.utc(2013, 3))
189
+ expect(ISO8601::Duration.new('-P156M', ISO8601::DateTime.new('2013-03-01')).to_seconds).to eq(Time.utc(2000, 3) - Time.utc(2013, 3))
178
190
  end
179
191
  it "should return the seconds of a -P[n]M duration in a leap year" do
180
- ISO8601::Duration.new('-P1M', ISO8601::DateTime.new('2000-02-01')).to_seconds.should == (Time.utc(2000, 1) - Time.utc(2000, 2))
181
- ISO8601::Duration.new('-P2M', ISO8601::DateTime.new('2000-03-01')).to_seconds.should == (Time.utc(2000, 1) - Time.utc(2000, 3))
182
- ISO8601::Duration.new('-P14M', ISO8601::DateTime.new('2001-03-01')).to_seconds.should == (Time.utc(2000, 1) - Time.utc(2001, 3))
192
+ expect(ISO8601::Duration.new('-P1M', ISO8601::DateTime.new('2000-02-01')).to_seconds).to eq(Time.utc(2000, 1) - Time.utc(2000, 2))
193
+ expect(ISO8601::Duration.new('-P2M', ISO8601::DateTime.new('2000-03-01')).to_seconds).to eq(Time.utc(2000, 1) - Time.utc(2000, 3))
194
+ expect(ISO8601::Duration.new('-P14M', ISO8601::DateTime.new('2001-03-01')).to_seconds).to eq(Time.utc(2000, 1) - Time.utc(2001, 3))
183
195
  end
184
196
  it "should return the seconds of a -P[n]Y[n]M[n]D duration" do
185
- ISO8601::Duration.new('-P2Y11D', ISO8601::DateTime.new('2014-01-12')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2014, 1, 12))
186
- ISO8601::Duration.new('-P1Y1M1D', ISO8601::DateTime.new('2010-05-01')).to_seconds.should == (Time.utc(2009, 3, 31) - Time.utc(2010, 5))
197
+ expect(ISO8601::Duration.new('-P2Y11D', ISO8601::DateTime.new('2014-01-12')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2014, 1, 12))
198
+ expect(ISO8601::Duration.new('-P1Y1M1D', ISO8601::DateTime.new('2010-05-01')).to_seconds).to eq(Time.utc(2009, 3, 31) - Time.utc(2010, 5))
187
199
  end
188
200
  it "should return the seconds of a -P[n]D duration" do
189
- ISO8601::Duration.new('-P1D', ISO8601::DateTime.new('2012-01-02')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 2))
190
- ISO8601::Duration.new('-P11D', ISO8601::DateTime.new('2012-01-12')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 12))
191
- ISO8601::Duration.new('-P3M11D', ISO8601::DateTime.new('2012-04-12')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 4, 12))
201
+ expect(ISO8601::Duration.new('-P1D', ISO8601::DateTime.new('2012-01-02')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 2))
202
+ expect(ISO8601::Duration.new('-P11D', ISO8601::DateTime.new('2012-01-12')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 12))
203
+ expect(ISO8601::Duration.new('-P3M11D', ISO8601::DateTime.new('2012-04-12')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2012, 4, 12))
192
204
  end
193
205
  it "should return the seconds of a -P[n]W duration" do
194
- ISO8601::Duration.new('-P2W', ISO8601::DateTime.new('2012-01-15')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 15))
195
- ISO8601::Duration.new('-P2W', ISO8601::DateTime.new('2012-02-01')).to_seconds.should == (Time.utc(2012, 2) - Time.utc(2012, 2, 15))
206
+ expect(ISO8601::Duration.new('-P2W', ISO8601::DateTime.new('2012-01-15')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 15))
207
+ expect(ISO8601::Duration.new('-P2W', ISO8601::DateTime.new('2012-02-01')).to_seconds).to eq(Time.utc(2012, 2) - Time.utc(2012, 2, 15))
196
208
  end
197
209
 
198
210
  it "should return the seconds of a -PT[n]H duration" do
199
- ISO8601::Duration.new('-PT5H', ISO8601::DateTime.new('2012-01-01T05')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 1, 5))
200
- ISO8601::Duration.new('-P1YT5H', ISO8601::DateTime.new('2013-01-01T05')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2013, 1, 1, 5))
211
+ expect(ISO8601::Duration.new('-PT5H', ISO8601::DateTime.new('2012-01-01T05')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 1, 5))
212
+ expect(ISO8601::Duration.new('-P1YT5H', ISO8601::DateTime.new('2013-01-01T05')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2013, 1, 1, 5))
201
213
  end
202
214
 
203
215
  it "should return the seconds of a -PT[n]H[n]M duration" do
204
- ISO8601::Duration.new('-PT5M', ISO8601::DateTime.new('2012-01-01T00:05')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 1, 0, 5))
205
- ISO8601::Duration.new('-PT1H5M', ISO8601::DateTime.new('2012-01-01T01:05')).to_seconds.should == (Time.utc(2012, 1) - Time.utc(2012, 1, 1, 1, 5))
206
- ISO8601::Duration.new('-PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == ISO8601::Duration.new('-PT65M', ISO8601::DateTime.new('2012-01-01')).to_seconds
216
+ expect(ISO8601::Duration.new('-PT5M', ISO8601::DateTime.new('2012-01-01T00:05')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 1, 0, 5))
217
+ expect(ISO8601::Duration.new('-PT1H5M', ISO8601::DateTime.new('2012-01-01T01:05')).to_seconds).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 1, 1, 5))
218
+ expect(ISO8601::Duration.new('-PT1H5M', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(ISO8601::Duration.new('-PT65M', ISO8601::DateTime.new('2012-01-01')).to_seconds)
207
219
  end
208
220
 
209
221
  it "should return the seconds of a -PT[n]H[n]M duration" do
210
- ISO8601::Duration.new('-PT10S', ISO8601::DateTime.new('2012-01-01T00:00:00')).to_seconds.should == (Time.utc(2011, 12, 31, 23, 59, 50) - Time.utc(2012, 1))
211
- ISO8601::Duration.new('-PT10.4S', ISO8601::DateTime.new('2012-01-01')).to_seconds.should == -10.4
222
+ expect(ISO8601::Duration.new('-PT10S', ISO8601::DateTime.new('2012-01-01T00:00:00')).to_seconds).to eq(Time.utc(2011, 12, 31, 23, 59, 50) - Time.utc(2012, 1))
223
+ expect(ISO8601::Duration.new('-PT10.4S', ISO8601::DateTime.new('2012-01-01')).to_seconds).to eq(-10.4)
212
224
  end
213
225
  end
214
226
  end
215
227
 
216
- describe '#==' do
217
- it "should raise an ISO8601::Errors::DurationBaseError" do
218
- expect { ISO8601::Duration.new('PT1H', ISO8601::DateTime.new('2000-01-01')) == ISO8601::Duration.new('PT1H') }.to raise_error(ISO8601::Errors::DurationBaseError)
228
+ describe '#abs' do
229
+ let(:positive) { ISO8601::Duration.new('PT1H') }
230
+ let(:negative) { ISO8601::Duration.new('-PT1H') }
231
+
232
+ it "should return a kind of duration" do
233
+ expect(negative.abs).to be_instance_of(ISO8601::Duration)
219
234
  end
220
- it "should return True" do
221
- ISO8601::Duration.new('PT1H').should == ISO8601::Duration.new('PT1H')
235
+ it "should return the absolute value of the duration" do
236
+ expect(negative.abs).to eq(positive)
222
237
  end
223
238
  end
224
239
 
225
- describe '#to_abs' do
226
- it "should return a kind of duration" do
227
- ISO8601::Duration.new('-PT1H').abs.should be_an_instance_of ISO8601::Duration
240
+ describe '#==' do
241
+ it "should equal by computed value" do
242
+ expect(ISO8601::Duration.new('PT1H') == ISO8601::Duration.new('PT1H')).to be_truthy
243
+ expect(ISO8601::Duration.new('PT1H') == ISO8601::Duration.new('PT60M')).to be_truthy
228
244
  end
229
- it "should return the absolute value of the duration" do
230
- ISO8601::Duration.new('-PT1H').abs.should == ISO8601::Duration.new('PT1H')
231
- (ISO8601::Duration.new('PT1H') - ISO8601::Duration.new('PT2H')).abs.should == ISO8601::Duration.new('PT1H')
232
- (ISO8601::Duration.new('PT1H') - ISO8601::Duration.new('-PT2H')).abs.should == ISO8601::Duration.new('PT3H')
245
+ end
246
+
247
+ describe '#eql?' do
248
+ it "should respond to #eql?" do
249
+ subject = ISO8601::Duration.new('PT1H')
250
+ expect(subject).to respond_to(:eql?)
233
251
  end
252
+ it "should equal by hash identity" do
253
+ expect(ISO8601::Duration.new('PT1H').eql? ISO8601::Duration.new('PT1H')).to be_truthy
254
+ expect(ISO8601::Duration.new('PT1H').eql? ISO8601::Duration.new('PT60M')).to be_falsy
255
+ end
256
+
234
257
  end
235
258
 
236
259
  describe '#hash' do
237
- it "should return the duration hash" do
260
+ it "should respond to #hash" do
238
261
  subject = ISO8601::Duration.new('PT1H')
239
262
 
240
263
  expect(subject).to respond_to(:hash)
241
264
  end
265
+ it "should build hash identity by value" do
266
+ subject = ISO8601::Duration.new('PT1H')
267
+ contrast = ISO8601::Duration.new('PT1H')
268
+
269
+ expect(subject.hash == contrast.hash).to be_truthy
270
+ end
242
271
  end
243
272
  end
@@ -32,52 +32,51 @@ describe ISO8601::Time do
32
32
  context 'reduced patterns' do
33
33
  it "should parse correctly reduced times" do
34
34
  reduced_time = ISO8601::Time.new('T101112Z')
35
- reduced_time.hour.should == 10
36
- reduced_time.minute.should == 11
37
- reduced_time.second.should == 12
35
+ expect(reduced_time.hour).to eq(10)
36
+ expect(reduced_time.minute).to eq(11)
37
+ expect(reduced_time.second).to eq(12)
38
38
  end
39
39
  end
40
40
 
41
41
  it "should return each atomic value" do
42
- dt = ISO8601::Time.new('T12:02:01+04:00', ::Date.parse('2010-05-09'))
43
- dt.hour.should == 12
44
- dt.minute.should == 2
45
- dt.second.should == 1
46
- dt.zone.should == '+04:00'
42
+ t = ISO8601::Time.new('T12:02:01+04:00', ::Date.parse('2010-05-09'))
43
+ expect(t.hour).to eq(12)
44
+ expect(t.minute).to eq(2)
45
+ expect(t.second).to eq(1)
46
+ expect(t.zone).to eq('+04:00')
47
47
  end
48
48
 
49
49
  it "should respond to delegated casting methods" do
50
- dt = ISO8601::Time.new('T10:09:08Z')
51
- dt.should respond_to(:to_s, :to_time, :to_date, :to_datetime)
50
+ expect(ISO8601::Time.new('T10:09:08Z')).to respond_to(:to_s, :to_time, :to_date, :to_datetime)
52
51
  end
53
52
 
54
53
  describe '#+' do
55
54
  it "should return the result of the addition" do
56
- (ISO8601::Time.new('T20:20:20+02:00') + 10).to_s.should == 'T20:20:30+02:00'
57
- (ISO8601::Time.new('T20:20:20.11+02:00') + 10).to_s.should == 'T20:20:30.11+02:00'
55
+ expect((ISO8601::Time.new('T20:20:20+02:00') + 10).to_s).to eq('T20:20:30+02:00')
56
+ expect((ISO8601::Time.new('T20:20:20.11+02:00') + 10).to_s).to eq('T20:20:30.11+02:00')
58
57
  end
59
58
  end
60
59
 
61
60
  describe '#-' do
62
61
  it "should return the result of the substraction" do
63
- (ISO8601::Time.new('T20:20:20+01:00') - 10).to_s.should == 'T20:20:10+01:00'
64
- (ISO8601::Time.new('T20:20:20.11+02:00') - 10).to_s.should == 'T20:20:10.11+02:00'
62
+ expect((ISO8601::Time.new('T20:20:20+01:00') - 10).to_s).to eq('T20:20:10+01:00')
63
+ expect((ISO8601::Time.new('T20:20:20.11+02:00') - 10).to_s).to eq('T20:20:10.11+02:00')
65
64
  end
66
65
  end
67
66
 
68
67
  describe '#to_a' do
69
68
  it "should return an array of atoms" do
70
- ISO8601::Time.new('T19:29:39Z').to_a.should == [19, 29, 39, '+00:00']
69
+ expect(ISO8601::Time.new('T19:29:39Z').to_a).to eq([19, 29, 39, '+00:00'])
71
70
  end
72
71
  end
73
72
 
74
73
  describe '#atoms' do
75
74
  it "should return an array of atoms" do
76
- ISO8601::Time.new('T19:29:39+04:00').atoms.should == [19, 29, 39, '+04:00']
77
- ISO8601::Time.new('T19:29:39Z').atoms.should == [19, 29, 39, 'Z']
78
- ISO8601::Time.new('T19:29:39').atoms.should == [19, 29, 39]
79
- ISO8601::Time.new('T19:29').atoms.should == [19, 29]
80
- ISO8601::Time.new('T19').atoms.should == [19]
75
+ expect(ISO8601::Time.new('T19:29:39+04:00').atoms).to eq([19, 29, 39, '+04:00'])
76
+ expect(ISO8601::Time.new('T19:29:39Z').atoms).to eq([19, 29, 39, 'Z'])
77
+ expect(ISO8601::Time.new('T19:29:39').atoms).to eq([19, 29, 39])
78
+ expect(ISO8601::Time.new('T19:29').atoms).to eq([19, 29])
79
+ expect(ISO8601::Time.new('T19').atoms).to eq([19])
81
80
  end
82
81
  end
83
82
 
@@ -87,6 +86,11 @@ describe ISO8601::Time do
87
86
 
88
87
  expect(subject).to respond_to(:hash)
89
88
  end
90
- end
89
+ it "should return the same hash" do
90
+ subject = ISO8601::Time.new('T20:11:10Z')
91
+ contrast = ISO8601::Time.new('T20:11:10Z')
91
92
 
93
+ expect(subject.hash).to eq(contrast.hash)
94
+ end
95
+ end
92
96
  end