ruby-progressbar 1.4.2 → 1.5.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.
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rspectacular'
2
2
 
3
3
  describe ProgressBar::Components::Bar do
4
4
  context 'when a new bar is created' do
@@ -7,26 +7,26 @@ describe ProgressBar::Components::Bar do
7
7
 
8
8
  describe '#total' do
9
9
  it 'returns the default total' do
10
- @progressbar.total.should eql ProgressBar::Components::Bar::DEFAULT_TOTAL
10
+ expect(@progressbar.total).to eql ProgressBar::Components::Bar::DEFAULT_TOTAL
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#progress_mark' do
15
15
  it 'returns the default mark' do
16
- @progressbar.progress_mark.should eql ProgressBar::Components::Bar::DEFAULT_PROGRESS_MARK
16
+ expect(@progressbar.progress_mark).to eql ProgressBar::Components::Bar::DEFAULT_PROGRESS_MARK
17
17
  end
18
18
  end
19
19
 
20
20
  describe '#remainder_mark' do
21
21
  it 'returns the default remainder mark' do
22
- @progressbar.remainder_mark.should eql ProgressBar::Components::Bar::DEFAULT_REMAINDER_MARK
22
+ expect(@progressbar.remainder_mark).to eql ProgressBar::Components::Bar::DEFAULT_REMAINDER_MARK
23
23
  end
24
24
  end
25
25
 
26
26
  context 'and the bar has not been started' do
27
27
  describe '#progress' do
28
28
  it 'returns the default beginning position' do
29
- @progressbar.progress.should be_zero
29
+ expect(@progressbar.progress).to be_zero
30
30
  end
31
31
  end
32
32
  end
@@ -36,7 +36,7 @@ describe ProgressBar::Components::Bar do
36
36
 
37
37
  describe '#progress' do
38
38
  it 'returns the default starting value' do
39
- @progressbar.progress.should eql ProgressBar::Components::Progressable::DEFAULT_BEGINNING_POSITION
39
+ expect(@progressbar.progress).to eql ProgressBar::Components::Progressable::DEFAULT_BEGINNING_POSITION
40
40
  end
41
41
  end
42
42
  end
@@ -46,7 +46,7 @@ describe ProgressBar::Components::Bar do
46
46
 
47
47
  describe '#progress' do
48
48
  it 'returns the given starting value' do
49
- @progressbar.progress.should eql 10
49
+ expect(@progressbar.progress).to eql 10
50
50
  end
51
51
  end
52
52
  end
@@ -57,19 +57,19 @@ describe ProgressBar::Components::Bar do
57
57
 
58
58
  describe '#total' do
59
59
  it 'returns the overridden total' do
60
- @progressbar.total.should eql 12
60
+ expect(@progressbar.total).to eql 12
61
61
  end
62
62
  end
63
63
 
64
64
  describe '#progress_mark' do
65
65
  it 'returns the overridden mark' do
66
- @progressbar.progress_mark.should eql 'x'
66
+ expect(@progressbar.progress_mark).to eql 'x'
67
67
  end
68
68
  end
69
69
 
70
70
  describe '#remainder_mark' do
71
71
  it 'returns the overridden mark' do
72
- @progressbar.remainder_mark.should eql '.'
72
+ expect(@progressbar.remainder_mark).to eql '.'
73
73
  end
74
74
  end
75
75
  end
@@ -84,13 +84,13 @@ describe ProgressBar::Components::Bar do
84
84
 
85
85
  describe '#percentage_completed' do
86
86
  it 'calculates the amount' do
87
- @progressbar.percentage_completed.should eql 0
87
+ expect(@progressbar.percentage_completed).to eql 0
88
88
  end
89
89
  end
90
90
 
91
91
  describe '#to_s' do
92
92
  it 'displays the bar with no indication of progress' do
93
- @progressbar.to_s.should eql ' '
93
+ expect(@progressbar.to_s).to eql ' '
94
94
  end
95
95
  end
96
96
  end
@@ -106,31 +106,31 @@ describe ProgressBar::Components::Bar do
106
106
  before { @progressbar.increment }
107
107
 
108
108
  it 'adds to the progress amount' do
109
- @progressbar.progress.should eql 1
109
+ expect(@progressbar.progress).to eql 1
110
110
  end
111
111
 
112
112
  describe '#percentage_completed' do
113
113
  it 'calculates the amount completed' do
114
- @progressbar.percentage_completed.should eql 2
114
+ expect(@progressbar.percentage_completed).to eql 2
115
115
  end
116
116
  end
117
117
 
118
118
  describe '#to_s' do
119
119
  it 'displays the bar with an indication of progress' do
120
- @progressbar.to_s.should eql '== '
120
+ expect(@progressbar.to_s).to eql '== '
121
121
  end
122
122
  end
123
123
  end
124
124
 
125
125
  describe '#percentage_completed' do
126
126
  it 'is zero' do
127
- @progressbar.percentage_completed.should eql 0
127
+ expect(@progressbar.percentage_completed).to eql 0
128
128
  end
129
129
  end
130
130
 
131
131
  describe '#to_s' do
132
132
  it 'displays the bar with no indication of progress' do
133
- @progressbar.to_s.should eql ' '
133
+ expect(@progressbar.to_s).to eql ' '
134
134
  end
135
135
  end
136
136
  end
@@ -144,13 +144,13 @@ describe ProgressBar::Components::Bar do
144
144
 
145
145
  describe '#percentage_completed' do
146
146
  it 'always rounds down' do
147
- @progressbar.percentage_completed.should eql 0
147
+ expect(@progressbar.percentage_completed).to eql 0
148
148
  end
149
149
  end
150
150
 
151
151
  describe '#to_s' do
152
152
  it 'displays the bar with no indication of progress' do
153
- @progressbar.to_s.should eql ' '
153
+ expect(@progressbar.to_s).to eql ' '
154
154
  end
155
155
  end
156
156
  end
@@ -166,13 +166,13 @@ describe ProgressBar::Components::Bar do
166
166
  before { @progressbar.increment }
167
167
 
168
168
  it 'does not increment past the total' do
169
- @progressbar.progress.should eql 50
170
- @progressbar.percentage_completed.should eql 100
169
+ expect(@progressbar.progress).to eql 50
170
+ expect(@progressbar.percentage_completed).to eql 100
171
171
  end
172
172
 
173
173
  describe '#to_s' do
174
174
  it 'displays the bar as 100% complete' do
175
- @progressbar.to_s.should eql '=' * 100
175
+ expect(@progressbar.to_s).to eql '=' * 100
176
176
  end
177
177
  end
178
178
  end
@@ -181,20 +181,20 @@ describe ProgressBar::Components::Bar do
181
181
  before { @progressbar.decrement }
182
182
 
183
183
  it 'removes some progress from the bar' do
184
- @progressbar.progress.should eql 49
185
- @progressbar.percentage_completed.should eql 98
184
+ expect(@progressbar.progress).to eql 49
185
+ expect(@progressbar.percentage_completed).to eql 98
186
186
  end
187
187
 
188
188
  describe '#to_s' do
189
189
  it 'displays the bar as 98% complete' do
190
- @progressbar.to_s.should eql "#{'=' * 98} "
190
+ expect(@progressbar.to_s).to eql "#{'=' * 98} "
191
191
  end
192
192
  end
193
193
  end
194
194
 
195
195
  describe '#to_s' do
196
196
  it 'displays the bar as 100% complete' do
197
- @progressbar.to_s.should eql ('=' * 100)
197
+ expect(@progressbar.to_s).to eql ('=' * 100)
198
198
  end
199
199
  end
200
200
  end
@@ -203,7 +203,7 @@ describe ProgressBar::Components::Bar do
203
203
  describe '#new' do
204
204
  it 'raises an error' do
205
205
  @progressbar = ProgressBar::Components::Bar.new(:total => 10)
206
- lambda { @progressbar.start :at => 11 }.should raise_error(ProgressBar::InvalidProgressError, "You can't set the item's current value to be greater than the total.")
206
+ expect { @progressbar.start :at => 11 }.to raise_error(ProgressBar::InvalidProgressError, "You can't set the item's current value to be greater than the total.")
207
207
  end
208
208
  end
209
209
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rspectacular'
2
2
 
3
3
  describe ProgressBar::Components::ElapsedTimer do
4
4
  before { @timer = ProgressBar::Components::ElapsedTimer.new }
@@ -6,14 +6,14 @@ describe ProgressBar::Components::ElapsedTimer do
6
6
  describe '#to_s' do
7
7
  context 'when the timer has not been started' do
8
8
  it 'displays "Time: --:--:--"' do
9
- @timer.to_s.should eql 'Time: --:--:--'
9
+ expect(@timer.to_s).to eql 'Time: --:--:--'
10
10
  end
11
11
  end
12
12
 
13
13
  context 'when it has just been started' do
14
14
  it 'displays "Time: 00:00:00"' do
15
15
  @timer.start
16
- @timer.to_s.should eql 'Time: 00:00:00'
16
+ expect(@timer.to_s).to eql 'Time: 00:00:00'
17
17
  end
18
18
  end
19
19
 
@@ -35,12 +35,12 @@ describe ProgressBar::Components::ElapsedTimer do
35
35
  before { @timer.reset }
36
36
 
37
37
  it 'displays "Time: --:--:--"' do
38
- @timer.to_s.should eql 'Time: --:--:--'
38
+ expect(@timer.to_s).to eql 'Time: --:--:--'
39
39
  end
40
40
  end
41
41
 
42
42
  it 'displays "Time: 04:27:41"' do
43
- @timer.to_s.should eql 'Time: 04:27:41'
43
+ expect(@timer.to_s).to eql 'Time: 04:27:41'
44
44
  end
45
45
  end
46
46
 
@@ -48,12 +48,12 @@ describe ProgressBar::Components::ElapsedTimer do
48
48
  before { @timer.reset }
49
49
 
50
50
  it 'displays "Time: --:--:--"' do
51
- @timer.to_s.should eql 'Time: --:--:--'
51
+ expect(@timer.to_s).to eql 'Time: --:--:--'
52
52
  end
53
53
  end
54
54
 
55
55
  it 'displays "Time: 04:28:13"' do
56
- @timer.to_s.should eql 'Time: 04:28:13'
56
+ expect(@timer.to_s).to eql 'Time: 04:28:13'
57
57
  end
58
58
  end
59
59
  end
@@ -69,7 +69,7 @@ describe ProgressBar::Components::ElapsedTimer do
69
69
  before { @timer.start }
70
70
 
71
71
  it 'is false' do
72
- @timer.should_not be_stopped
72
+ expect(@timer).not_to be_stopped
73
73
  end
74
74
  end
75
75
  end
@@ -77,14 +77,14 @@ describe ProgressBar::Components::ElapsedTimer do
77
77
 
78
78
  context "when the timer has yet to be started" do
79
79
  it 'is false' do
80
- @timer.should_not be_stopped
80
+ expect(@timer).not_to be_stopped
81
81
  end
82
82
  end
83
83
 
84
84
  context "when the timer is stopped without having been started" do
85
85
  before { @timer.stop }
86
86
  it 'is false' do
87
- @timer.should_not be_stopped
87
+ expect(@timer).not_to be_stopped
88
88
  end
89
89
  end
90
90
  end
@@ -1,10 +1,11 @@
1
- require 'spec_helper'
1
+ require 'rspectacular'
2
+ require 'support/time'
2
3
 
3
4
  describe ProgressBar::Components::EstimatedTimer do
4
5
  describe '#progress=' do
5
6
  it 'raises an error when passed a number larger than the total' do
6
7
  @estimated_time = ProgressBar::Components::EstimatedTimer.new(:total => 100)
7
- lambda{ @estimated_time.progress = 101 }.should raise_error(ProgressBar::InvalidProgressError, "You can't set the item's current value to be greater than the total.")
8
+ expect { @estimated_time.progress = 101 }.to raise_error(ProgressBar::InvalidProgressError, "You can't set the item's current value to be greater than the total.")
8
9
  end
9
10
  end
10
11
 
@@ -16,13 +17,13 @@ describe ProgressBar::Components::EstimatedTimer do
16
17
  end
17
18
 
18
19
  it 'displays an unknown time remaining' do
19
- @estimated_time.to_s.should eql ' ETA: ??:??:??'
20
+ expect(@estimated_time.to_s).to eql ' ETA: ??:??:??'
20
21
  end
21
22
 
22
23
  context 'and it is incremented' do
23
24
  it 'should not display unknown time remaining' do
24
25
  @estimated_time.increment
25
- @estimated_time.to_s.should_not eql ' ETA: ??:??:??'
26
+ expect(@estimated_time.to_s).not_to eql ' ETA: ??:??:??'
26
27
  end
27
28
  end
28
29
  end
@@ -45,7 +46,7 @@ describe ProgressBar::Components::EstimatedTimer do
45
46
  before { 20.times { @estimated_time.decrement } }
46
47
 
47
48
  it 'displays the correct time remaining' do
48
- @estimated_time.to_s.should eql ' ETA: 08:38:28'
49
+ expect(@estimated_time.to_s).to eql ' ETA: 08:38:28'
49
50
  end
50
51
  end
51
52
 
@@ -53,12 +54,12 @@ describe ProgressBar::Components::EstimatedTimer do
53
54
  before { @estimated_time.reset }
54
55
 
55
56
  it 'displays unknown time remaining' do
56
- @estimated_time.to_s.should eql ' ETA: ??:??:??'
57
+ expect(@estimated_time.to_s).to eql ' ETA: ??:??:??'
57
58
  end
58
59
  end
59
60
 
60
61
  it 'displays the correct time remaining' do
61
- @estimated_time.to_s.should eql ' ETA: 03:42:12'
62
+ expect(@estimated_time.to_s).to eql ' ETA: 03:42:12'
62
63
  end
63
64
  end
64
65
 
@@ -76,7 +77,7 @@ describe ProgressBar::Components::EstimatedTimer do
76
77
  before { @estimated_time.out_of_bounds_time_format = :friendly }
77
78
 
78
79
  it 'displays "> 4 Days" remaining' do
79
- @estimated_time.to_s.should eql ' ETA: > 4 Days'
80
+ expect(@estimated_time.to_s).to eql ' ETA: > 4 Days'
80
81
  end
81
82
  end
82
83
 
@@ -84,12 +85,12 @@ describe ProgressBar::Components::EstimatedTimer do
84
85
  before { @estimated_time.out_of_bounds_time_format = :unknown }
85
86
 
86
87
  it 'displays "??:??:??" remaining' do
87
- @estimated_time.to_s.should eql ' ETA: ??:??:??'
88
+ expect(@estimated_time.to_s).to eql ' ETA: ??:??:??'
88
89
  end
89
90
  end
90
91
 
91
92
  it 'displays the correct time remaining' do
92
- @estimated_time.to_s.should eql ' ETA: 100:00:00'
93
+ expect(@estimated_time.to_s).to eql ' ETA: 100:00:00'
93
94
  end
94
95
  end
95
96
  end
@@ -111,7 +112,7 @@ describe ProgressBar::Components::EstimatedTimer do
111
112
  before { 20.times { @estimated_time.decrement } }
112
113
 
113
114
  it 'displays the correct time remaining' do
114
- @estimated_time.to_s.should eql ' ETA: 08:14:34'
115
+ expect(@estimated_time.to_s).to eql ' ETA: 08:14:34'
115
116
  end
116
117
  end
117
118
 
@@ -119,12 +120,12 @@ describe ProgressBar::Components::EstimatedTimer do
119
120
  before { @estimated_time.reset }
120
121
 
121
122
  it 'displays unknown time remaining' do
122
- @estimated_time.to_s.should eql ' ETA: ??:??:??'
123
+ expect(@estimated_time.to_s).to eql ' ETA: ??:??:??'
123
124
  end
124
125
  end
125
126
 
126
127
  it 'displays the correct time remaining' do
127
- @estimated_time.to_s.should eql ' ETA: 03:51:16'
128
+ expect(@estimated_time.to_s).to eql ' ETA: 03:51:16'
128
129
  end
129
130
  end
130
131
 
@@ -142,7 +143,7 @@ describe ProgressBar::Components::EstimatedTimer do
142
143
  before { @estimated_time.out_of_bounds_time_format = :friendly }
143
144
 
144
145
  it 'displays "> 4 Days" remaining' do
145
- @estimated_time.to_s.should eql ' ETA: > 4 Days'
146
+ expect(@estimated_time.to_s).to eql ' ETA: > 4 Days'
146
147
  end
147
148
  end
148
149
 
@@ -150,12 +151,12 @@ describe ProgressBar::Components::EstimatedTimer do
150
151
  before { @estimated_time.out_of_bounds_time_format = :unknown }
151
152
 
152
153
  it 'displays "??:??:??" remaining' do
153
- @estimated_time.to_s.should eql ' ETA: ??:??:??'
154
+ expect(@estimated_time.to_s).to eql ' ETA: ??:??:??'
154
155
  end
155
156
  end
156
157
 
157
158
  it 'displays the correct time remaining' do
158
- @estimated_time.to_s.should eql ' ETA: 105:33:20'
159
+ expect(@estimated_time.to_s).to eql ' ETA: 105:33:20'
159
160
  end
160
161
  end
161
162
  end
@@ -172,7 +173,8 @@ describe ProgressBar::Components::EstimatedTimer do
172
173
  estimated_time.increment
173
174
  estimated_time.to_s
174
175
  end
175
- results.should == [
176
+
177
+ expect(results).to eql([
176
178
  ' ETA: 00:00:05',
177
179
  ' ETA: 00:00:04',
178
180
  ' ETA: 00:00:04',
@@ -183,7 +185,7 @@ describe ProgressBar::Components::EstimatedTimer do
183
185
  ' ETA: 00:00:01',
184
186
  ' ETA: 00:00:01',
185
187
  ' ETA: 00:00:00',
186
- ]
188
+ ])
187
189
  ensure
188
190
  Timecop.return
189
191
  end
@@ -194,7 +196,7 @@ describe ProgressBar::Components::EstimatedTimer do
194
196
  context 'when set to an invalid format' do
195
197
  it 'raises an exception' do
196
198
  @estimated_time = ProgressBar::Components::EstimatedTimer.new(:total => 100)
197
- lambda{ @estimated_time.out_of_bounds_time_format = :foo }.should raise_error('Invalid Out Of Bounds time format. Valid formats are [:unknown, :friendly, nil]')
199
+ expect { @estimated_time.out_of_bounds_time_format = :foo }.to raise_error('Invalid Out Of Bounds time format. Valid formats are [:unknown, :friendly, nil]')
198
200
  end
199
201
  end
200
202
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rspectacular'
2
2
 
3
3
  class ProgressableClass
4
4
  include ProgressBar::Components::Progressable
@@ -8,23 +8,32 @@ describe ProgressBar::Components::Progressable do
8
8
  subject { ProgressableClass.new }
9
9
 
10
10
  describe '#running_average' do
11
+ it 'is properly calculated when progress has been made' do
12
+ subject.running_average = 10
13
+ subject.start :at => 0
14
+ expect(subject.running_average).to be_zero
15
+
16
+ subject.progress += 40
17
+ expect(subject.running_average).to eql 36.0
18
+ end
19
+
11
20
  it 'is always reset when the progressable is started' do
12
21
  subject.running_average = 10
13
22
  subject.start :at => 0
14
- subject.running_average.should be_zero
23
+ expect(subject.running_average).to be_zero
15
24
 
16
25
  subject.start :at => 40
17
- subject.running_average.should eql 36.0
26
+ expect(subject.running_average).to eql 0.0
18
27
  end
19
28
  end
20
29
 
21
30
  describe '#smoothing' do
22
31
  it 'can be passed in as an option to the initializer' do
23
- ProgressableClass.new(:smoothing => 0.3).smoothing.should eql 0.3
32
+ expect(ProgressableClass.new(:smoothing => 0.3).smoothing).to eql 0.3
24
33
  end
25
34
 
26
35
  it 'does not have to be passed in as an option to the initializer' do
27
- ProgressableClass.new.smoothing.should eql 0.1
36
+ expect(ProgressableClass.new.smoothing).to eql 0.1
28
37
  end
29
38
  end
30
39
 
@@ -32,7 +41,7 @@ describe ProgressBar::Components::Progressable do
32
41
  it 'returns the default total if total is zero' do
33
42
  subject.total = 0
34
43
 
35
- subject.percentage_completed.should eql 100
44
+ expect(subject.percentage_completed).to eql 100
36
45
  end
37
46
  end
38
47
  end