edtf 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,26 +8,26 @@ module EDTF
8
8
  describe 'uncertain/approximate' do
9
9
 
10
10
  it 'is certain by default' do
11
- subject.should be_certain
12
- subject.should_not be_uncertain
11
+ expect(subject).to be_certain
12
+ expect(subject).not_to be_uncertain
13
13
  end
14
14
 
15
15
  it 'is precise by default' do
16
- subject.should be_precise
17
- subject.should_not be_approximate
16
+ expect(subject).to be_precise
17
+ expect(subject).not_to be_approximate
18
18
  end
19
19
 
20
20
  describe '#approximate!' do
21
21
  it 'makes the season approximate' do
22
- subject.approximate!.should be_approximate
23
- subject.approximate!.should_not be_precise
22
+ expect(subject.approximate!).to be_approximate
23
+ expect(subject.approximate!).not_to be_precise
24
24
  end
25
25
  end
26
26
 
27
27
  describe '#uncertain!' do
28
28
  it 'makes the season uncertain' do
29
- subject.uncertain!.should be_uncertain
30
- subject.uncertain!.should_not be_certain
29
+ expect(subject.uncertain!).to be_uncertain
30
+ expect(subject.uncertain!).not_to be_certain
31
31
  end
32
32
  end
33
33
 
@@ -36,24 +36,24 @@ module EDTF
36
36
  describe '#succ' do
37
37
 
38
38
  it 'returns a season' do
39
- summer.succ.should be_instance_of(Season)
39
+ expect(summer.succ).to be_instance_of(Season)
40
40
  end
41
41
 
42
42
  it 'it returns a season that is greater than the original one' do
43
- summer.succ.should > summer
43
+ expect(summer.succ).to be > summer
44
44
  end
45
45
 
46
46
  it 'the successor of the winter season is spring of the following year' do
47
47
  spring = winter.succ
48
- spring.should be_spring
49
- spring.year.should == winter.year + 1
48
+ expect(spring).to be_spring
49
+ expect(spring.year).to eq(winter.year + 1)
50
50
  end
51
51
 
52
52
  end
53
53
 
54
54
  describe '#season?' do
55
55
  it 'returns true by default' do
56
- subject.should be_season
56
+ expect(subject).to be_season
57
57
  end
58
58
  end
59
59
 
@@ -61,38 +61,39 @@ module EDTF
61
61
  before(:each) { subject.season = :summer }
62
62
 
63
63
  it 'returns the season code' do
64
- subject.season.should == :summer
64
+ expect(subject.season).to eq(:summer)
65
65
  end
66
66
  end
67
67
 
68
68
  describe '#season=' do
69
69
  it 'sets the season code when called with a valid season code' do
70
- lambda {
70
+ expect {
71
71
  (21..22).each do |i|
72
72
  subject.season = i
73
73
  end
74
- }.should_not raise_error
74
+ }.not_to raise_error
75
75
  end
76
76
 
77
77
  it 'throws an exception if given invalid season code' do
78
- lambda { subject.season = 13 }.should raise_error
78
+ expect { subject.season = 13 }.to raise_error
79
79
  end
80
80
  end
81
81
 
82
82
  describe '#summer!' do
83
83
  it 'sets the season to :summer' do
84
- lambda { subject.summer! }.should change { subject.season }.to(:summer)
84
+ subject.season = :spring
85
+ expect { subject.summer! }.to change { subject.season }.to(:summer)
85
86
  end
86
87
  end
87
88
 
88
89
  describe '#winter?' do
89
90
  it 'returns true if the season is set to :winter' do
90
91
  subject.season = :winter
91
- subject.should be_winter
92
+ expect(subject).to be_winter
92
93
  end
93
94
  it 'returns false if the season is not set to :winter' do
94
95
  subject.season = :summer
95
- subject.should_not be_winter
96
+ expect(subject).not_to be_winter
96
97
  end
97
98
  end
98
99
 
@@ -100,7 +101,7 @@ module EDTF
100
101
 
101
102
  context 'for summer' do
102
103
  it 'returns true for August 24' do
103
- Season.new(1980, :summer).should include(Date.new(1980,8,24))
104
+ expect(Season.new(1980, :summer)).to include(Date.new(1980,8,24))
104
105
  end
105
106
  end
106
107
 
@@ -1,73 +1,73 @@
1
1
  module EDTF
2
2
  describe 'Sets' do
3
-
4
- describe 'constructor' do
5
-
6
- it 'creates a new empty set by default' do
7
- Set.new.should be_empty
8
- end
9
-
10
- end
11
-
12
- describe '#edtf' do
13
-
14
- it 'returns {} by default' do
15
- Set.new.edtf.should == '{}'
16
- end
17
-
18
- it 'returns [] for empty choice lists' do
19
- Set.new.choice!.edtf.should == '[]'
20
- end
21
-
22
- it 'returns {1984} if the set contains the year 1984' do
23
- Set.new(Date.edtf('1984')).edtf.should == '{1984}'
24
- end
25
-
26
- it 'returns {1984, 1985-10} for the set containing these dates' do
27
- Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).edtf.should == '{1984, 1984-10}'
28
- end
29
-
30
- it 'returns {..1984, 1985-10} for the set containing these dates and earlier == true' do
31
- Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).earlier!.edtf.should == '{..1984, 1984-10}'
32
- end
33
-
34
- it 'returns {1984, 1985-10..} for the set containing these dates and later == true' do
35
- Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).later!.edtf.should == '{1984, 1984-10..}'
36
- end
37
-
38
- it 'returns [1667, 1668, 1670..1672] for the years 1667, 1668 and the interval 1670..1672' do
39
- s = Set.new.choice!
40
- s << Date.edtf('1667') << Date.edtf('1668')
41
- s << (Date.edtf('1670') .. Date.edtf('1672'))
42
- s.edtf.should == '[1667, 1668, 1670..1672]'
43
- end
44
-
45
- end
46
-
47
- describe 'the set [1667, 1668, 1670..1672]' do
48
- let(:set) { Set.new(Date.edtf('1667'), Date.edtf('1668'), Date.edtf('1670')..Date.edtf('1672')).choice! }
49
-
50
- it 'includes the year 1671' do
51
- set.should include(Date.new(1671).year_precision!)
52
- end
53
-
54
- it 'does not include the date 1671-01-01' do
55
- set.should_not include(Date.new(1671))
56
- end
57
-
58
- it 'does not include the year 1669' do
59
- set.should_not include(Date.new(1669).year_precision!)
60
- end
61
-
62
- it 'has a length of 3' do
63
- set.should have(3).elements
64
- end
65
-
66
- it 'maps to the year array [1667, 1668, 1670, 1671, 1672]' do
67
- set.map(&:year).should == [1667, 1668, 1670, 1671, 1672]
68
- end
69
-
70
- end
71
-
72
- end
73
- end
3
+
4
+ describe 'constructor' do
5
+
6
+ it 'creates a new empty set by default' do
7
+ expect(Set.new).to be_empty
8
+ end
9
+
10
+ end
11
+
12
+ describe '#edtf' do
13
+
14
+ it 'returns {} by default' do
15
+ expect(Set.new.edtf).to eq('{}')
16
+ end
17
+
18
+ it 'returns [] for empty choice lists' do
19
+ expect(Set.new.choice!.edtf).to eq('[]')
20
+ end
21
+
22
+ it 'returns {1984} if the set contains the year 1984' do
23
+ expect(Set.new(Date.edtf('1984')).edtf).to eq('{1984}')
24
+ end
25
+
26
+ it 'returns {1984, 1985-10} for the set containing these dates' do
27
+ expect(Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).edtf).to eq('{1984,1984-10}')
28
+ end
29
+
30
+ it 'returns {..1984, 1985-10} for the set containing these dates and earlier == true' do
31
+ expect(Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).earlier!.edtf).to eq('{..1984,1984-10}')
32
+ end
33
+
34
+ it 'returns {1984, 1985-10..} for the set containing these dates and later == true' do
35
+ expect(Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).later!.edtf).to eq('{1984,1984-10..}')
36
+ end
37
+
38
+ it 'returns [1667, 1668, 1670..1672] for the years 1667, 1668 and the interval 1670..1672' do
39
+ s = Set.new.choice!
40
+ s << Date.edtf('1667') << Date.edtf('1668')
41
+ s << (Date.edtf('1670') .. Date.edtf('1672'))
42
+ expect(s.edtf).to eq('[1667,1668,1670..1672]')
43
+ end
44
+
45
+ end
46
+
47
+ describe 'the set [1667, 1668, 1670..1672]' do
48
+ let(:set) { Set.new(Date.edtf('1667'), Date.edtf('1668'), Date.edtf('1670')..Date.edtf('1672')).choice! }
49
+
50
+ it 'includes the year 1671' do
51
+ expect(set).to include(Date.new(1671).year_precision!)
52
+ end
53
+
54
+ it 'does not include the date 1671-01-01' do
55
+ expect(set.include?(Date.new(1671))).to be false
56
+ end
57
+
58
+ it 'does not include the year 1669' do
59
+ expect(set.include?(Date.new(1669).year_precision!)).to be false
60
+ end
61
+
62
+ it 'has a length of 3' do
63
+ expect(set.size).to eq(3)
64
+ end
65
+
66
+ it 'maps to the year array [1667,1668,1670,1671,1672]' do
67
+ expect(set.map(&:year)).to eq([1667, 1668, 1670, 1671, 1672])
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+ end
@@ -6,36 +6,36 @@ module EDTF
6
6
 
7
7
  describe '#uncertain?' do
8
8
 
9
- it { should be_certain }
9
+ it { is_expected.to be_certain }
10
10
 
11
11
  it 'should be uncertain if at least one part is uncertain' do
12
- Uncertainty.new(false, false, true).should be_uncertain
12
+ expect(Uncertainty.new(false, false, true)).to be_uncertain
13
13
  end
14
14
 
15
15
  it 'should not be uncertain if all parts are certain' do
16
- Uncertainty.new(false, false, false).should be_certain
16
+ expect(Uncertainty.new(false, false, false)).to be_certain
17
17
  end
18
18
 
19
19
  it 'should be uncertain if all parts are uncertain' do
20
- Uncertainty.new(true, true, true).should be_uncertain
20
+ expect(Uncertainty.new(true, true, true)).to be_uncertain
21
21
  end
22
22
 
23
23
  # [:year, :month, :day, :hour, :minute, :second].each do |part|
24
24
  [:year, :month, :day].each do |part|
25
25
  it "#{ part } should not be uncertain by default" do
26
- uncertainty.uncertain?(part).should be false
26
+ expect(uncertainty.uncertain?(part)).to be false
27
27
  end
28
28
 
29
29
  it "#{ part } should be uncertain if set to uncertain" do
30
30
  uncertainty.send("#{part}=", true)
31
- uncertainty.uncertain?(part).should be true
31
+ expect(uncertainty.uncertain?(part)).to be true
32
32
  end
33
33
 
34
34
  # ([:year, :month, :day, :hour, :minute, :second] - [part]).each do |other|
35
35
  ([:year, :month, :day] - [part]).each do |other|
36
36
  it "#{other} should not be uncertain if #{part} is uncertain" do
37
37
  uncertainty.send("#{part}=", true)
38
- uncertainty.uncertain?(other).should be false
38
+ expect(uncertainty.uncertain?(other)).to be false
39
39
  end
40
40
  end
41
41
 
@@ -46,35 +46,35 @@ module EDTF
46
46
  describe 'with the default hash base (1)' do
47
47
 
48
48
  it 'returns 0 by default' do
49
- Uncertainty.new.hash.should == 0
49
+ expect(Uncertainty.new.hash).to eq(0)
50
50
  end
51
51
 
52
52
  it 'returns 1 for uncertain year' do
53
- Uncertainty.new.hash.should == 0
53
+ expect(Uncertainty.new.hash).to eq(0)
54
54
  end
55
55
 
56
56
  it 'returns 2 for uncertain month' do
57
- Uncertainty.new.hash.should == 0
57
+ expect(Uncertainty.new.hash).to eq(0)
58
58
  end
59
59
 
60
60
  it 'returns 4 for uncertain day' do
61
- Uncertainty.new.hash.should == 0
61
+ expect(Uncertainty.new.hash).to eq(0)
62
62
  end
63
63
 
64
64
  it 'returns 3 for uncertain year, month' do
65
- Uncertainty.new(true, true).hash.should == 3
65
+ expect(Uncertainty.new(true, true).hash).to eq(3)
66
66
  end
67
67
 
68
68
  it 'returns 7 for uncertain year, month, day' do
69
- Uncertainty.new(true, true, true).hash.should == 7
69
+ expect(Uncertainty.new(true, true, true).hash).to eq(7)
70
70
  end
71
71
 
72
72
  it 'returns 5 for uncertain year, day' do
73
- Uncertainty.new(true, nil, true).hash.should == 5
73
+ expect(Uncertainty.new(true, nil, true).hash).to eq(5)
74
74
  end
75
75
 
76
76
  it 'returns 6 for uncertain month, day' do
77
- Uncertainty.new(nil, true, true).hash.should == 6
77
+ expect(Uncertainty.new(nil, true, true).hash).to eq(6)
78
78
  end
79
79
 
80
80
  end
@@ -85,7 +85,7 @@ module EDTF
85
85
 
86
86
  describe '#uncertain!' do
87
87
  it 'should make all parts certain when no part given' do
88
- lambda { uncertainty.uncertain! }.should change { uncertainty.certain? }
88
+ expect { uncertainty.uncertain! }.to change { uncertainty.certain? }
89
89
  end
90
90
  end
91
91
 
@@ -97,56 +97,56 @@ module EDTF
97
97
 
98
98
  describe '#unspecified?' do
99
99
  it 'should return false by default' do
100
- u.should_not be_unspecified
100
+ expect(u).not_to be_unspecified
101
101
  end
102
102
 
103
103
  it 'should return true if the day is unspecified' do
104
- u.unspecified!(:day).should be_unspecified
104
+ expect(u.unspecified!(:day)).to be_unspecified
105
105
  end
106
106
 
107
107
  it 'should return true if the month is unspecified' do
108
- u.unspecified!(:month).should be_unspecified
108
+ expect(u.unspecified!(:month)).to be_unspecified
109
109
  end
110
110
 
111
111
  it 'should return true if the year is unspecified' do
112
- u.unspecified!(:year).should be_unspecified
112
+ expect(u.unspecified!(:year)).to be_unspecified
113
113
  end
114
114
  end
115
115
 
116
116
  describe '#year' do
117
117
  it 'returns the year values' do
118
- u.year.should == [nil,nil,nil,nil]
118
+ expect(u.year).to eq([nil,nil,nil,nil])
119
119
  end
120
120
 
121
121
  it 'allows you to set individual offsets' do
122
122
  u.year[1] = true
123
- u.to_s.should == 'suss-ss-ss'
123
+ expect(u.to_s).to eq('suss-ss-ss')
124
124
  end
125
125
  end
126
126
 
127
127
  describe '#to_s' do
128
128
  it 'should be return "ssss-ss-ss" by default' do
129
- u.to_s.should == 'ssss-ss-ss'
129
+ expect(u.to_s).to eq('ssss-ss-ss')
130
130
  end
131
131
 
132
132
  it 'should return "ssss-ss-uu" if the day is unspecified' do
133
- u.unspecified!(:day).to_s.should == 'ssss-ss-uu'
133
+ expect(u.unspecified!(:day).to_s).to eq('ssss-ss-uu')
134
134
  end
135
135
 
136
136
  it 'should return "ssss-uu-ss" if the month is unspecified' do
137
- u.unspecified!(:month).to_s.should == 'ssss-uu-ss'
137
+ expect(u.unspecified!(:month).to_s).to eq('ssss-uu-ss')
138
138
  end
139
139
 
140
140
  it 'should return "ssss-uu-uu" if month and day are unspecified' do
141
- u.unspecified!([:day, :month]).to_s.should == 'ssss-uu-uu'
141
+ expect(u.unspecified!([:day, :month]).to_s).to eq('ssss-uu-uu')
142
142
  end
143
143
 
144
144
  it 'should return "uuuu-ss-ss" if the year is unspecified' do
145
- u.unspecified!(:year).to_s.should == 'uuuu-ss-ss'
145
+ expect(u.unspecified!(:year).to_s).to eq('uuuu-ss-ss')
146
146
  end
147
147
 
148
148
  it 'should return "uuuu-uu-uu" if the date is unspecified' do
149
- u.unspecified!.to_s.should == 'uuuu-uu-uu'
149
+ expect(u.unspecified!.to_s).to eq('uuuu-uu-uu')
150
150
  end
151
151
 
152
152
  end
@@ -155,7 +155,7 @@ module EDTF
155
155
 
156
156
  context 'when passed an empty array' do
157
157
  it 'should return an empty array' do
158
- u.mask([]).should == []
158
+ expect(u.mask([])).to eq([])
159
159
  end
160
160
  end
161
161
 
@@ -163,14 +163,14 @@ module EDTF
163
163
  let(:date) { ['1994'] }
164
164
 
165
165
  it 'should return the array with the year by default' do
166
- u.mask(date).should == ['1994']
166
+ expect(u.mask(date)).to eq(['1994'])
167
167
  end
168
168
 
169
169
  context 'when the year is unspecified' do
170
170
  before(:each) { u.year[3] = true }
171
171
 
172
172
  it 'should return the array with the year and the fourth digit masked' do
173
- u.mask(date).should == ['199u']
173
+ expect(u.mask(date)).to eq(['199u'])
174
174
  end
175
175
 
176
176
  end
@@ -179,7 +179,7 @@ module EDTF
179
179
  before(:each) { u.year[2,2] = [true,true] }
180
180
 
181
181
  it 'should return the array with the year and the third and fourth digit masked' do
182
- u.mask(date).should == ['19uu']
182
+ expect(u.mask(date)).to eq(['19uu'])
183
183
  end
184
184
 
185
185
  end
@@ -190,21 +190,21 @@ module EDTF
190
190
  let(:date) { ['1994', '01'] }
191
191
 
192
192
  it 'should return the array with the year by default' do
193
- u.mask(date).should == ['1994', '01']
193
+ expect(u.mask(date)).to eq(['1994', '01'])
194
194
  end
195
195
 
196
196
  context 'when the year is unspecified' do
197
197
  before(:each) { u.year[3] = true }
198
198
 
199
199
  it 'should return the array with the year and the fourth digit masked' do
200
- u.mask(date).should == ['199u', '01']
200
+ expect(u.mask(date)).to eq(['199u', '01'])
201
201
  end
202
202
 
203
203
  context 'when the month is unspecified' do
204
204
  before(:each) { u.unspecified! :month }
205
205
 
206
206
  it 'should return the array with the month masked' do
207
- u.mask(date).should == ['199u', 'uu']
207
+ expect(u.mask(date)).to eq(['199u', 'uu'])
208
208
  end
209
209
  end
210
210
  end
@@ -213,14 +213,14 @@ module EDTF
213
213
  before(:each) { u.year[2,2] = [true,true] }
214
214
 
215
215
  it 'should return the array with the year and the third and fourth digit masked' do
216
- u.mask(date).should == ['19uu', '01']
216
+ expect(u.mask(date)).to eq(['19uu', '01'])
217
217
  end
218
218
 
219
219
  context 'when the month is unspecified' do
220
220
  before(:each) { u.unspecified! :month }
221
221
 
222
222
  it 'should return the array with the month masked' do
223
- u.mask(date).should == ['19uu', 'uu']
223
+ expect(u.mask(date)).to eq(['19uu', 'uu'])
224
224
  end
225
225
  end
226
226
  end
@@ -229,7 +229,7 @@ module EDTF
229
229
  before(:each) { u.unspecified! :month }
230
230
 
231
231
  it 'should return the array with the month masked' do
232
- u.mask(date).should == ['1994', 'uu']
232
+ expect(u.mask(date)).to eq(['1994', 'uu'])
233
233
  end
234
234
  end
235
235
 
@@ -239,28 +239,28 @@ module EDTF
239
239
  let(:date) { ['1994', '01', '27'] }
240
240
 
241
241
  it 'should return the array with the date by default' do
242
- u.mask(date).should == ['1994', '01', '27']
242
+ expect(u.mask(date)).to eq(['1994', '01', '27'])
243
243
  end
244
244
 
245
245
  context 'when the year is unspecified' do
246
246
  before(:each) { u.year[3] = true }
247
247
 
248
248
  it 'should return the array with the year and the fourth digit masked' do
249
- u.mask(date).should == ['199u', '01', '27']
249
+ expect(u.mask(date)).to eq(['199u', '01', '27'])
250
250
  end
251
251
 
252
252
  context 'when the month is unspecified' do
253
253
  before(:each) { u.unspecified! :month }
254
254
 
255
255
  it 'should return the array with the month masked' do
256
- u.mask(date).should == ['199u', 'uu', '27']
256
+ expect(u.mask(date)).to eq(['199u', 'uu', '27'])
257
257
  end
258
258
 
259
259
  context 'when the day is unspecified' do
260
260
  before(:each) { u.unspecified! :day }
261
261
 
262
262
  it 'should return the array with the month masked' do
263
- u.mask(date).should == ['199u', 'uu', 'uu']
263
+ expect(u.mask(date)).to eq(['199u', 'uu', 'uu'])
264
264
  end
265
265
  end
266
266
  end