ruby-progressbar 1.8.1 → 1.8.3

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,17 +0,0 @@
1
- require 'rspectacular'
2
- require 'ruby-progressbar/calculators/running_average'
3
-
4
- class ProgressBar
5
- module Calculators
6
- RSpec.describe Length do
7
- it 'can properly calculate the length even if IO.console is nil' do
8
- calculator = Length.new
9
-
10
- expect(IO).to receive(:console).and_return nil
11
- expect(calculator).to receive(:dynamic_width_via_system_calls).and_return 123_456
12
-
13
- expect(calculator.calculate_length).to eql 123_456
14
- end
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
1
- require 'rspectacular'
2
- require 'ruby-progressbar/calculators/running_average'
3
-
4
- class ProgressBar
5
- module Calculators
6
- RSpec.describe RunningAverage do
7
- it 'can properly calculate a running average' do
8
- first_average = RunningAverage.calculate(4.5, 12, 0.1)
9
- expect(first_average).to be_within(0.001).of 11.25
10
-
11
- second_average = RunningAverage.calculate(8.2, 51, 0.7)
12
- expect(second_average).to be_within(0.001).of 21.04
13
-
14
- third_average = RunningAverage.calculate(41.8, 100, 0.59)
15
- expect(third_average).to be_within(0.001).of 65.662
16
- end
17
- end
18
- end
19
- end
@@ -1,234 +0,0 @@
1
- require 'rspectacular'
2
- require 'ruby-progressbar/components/bar'
3
-
4
- class ProgressBar
5
- module Components
6
- RSpec.describe Bar do
7
- it 'has a default mark when a new bar is created and no parameters are passed' do
8
- expect(Bar.new.progress_mark).to eql Bar::DEFAULT_PROGRESS_MARK
9
- end
10
-
11
- it 'has a default remainder mark when a new bar is created and no parameters ' \
12
- 'are passed' do
13
-
14
- expect(Bar.new.remainder_mark).to eql Bar::DEFAULT_REMAINDER_MARK
15
- end
16
-
17
- it 'returns the overridden mark when a new bar is created and options are passed' do
18
- progressbar = Bar.new(:progress_mark => 'x')
19
-
20
- expect(progressbar.progress_mark).to eql 'x'
21
- end
22
-
23
- it 'returns the overridden remainder mark when a new bar is created and options ' \
24
- 'are passed' do
25
-
26
- progressbar = Bar.new(:remainder_mark => 'o')
27
-
28
- expect(progressbar.remainder_mark).to eql 'o'
29
- end
30
-
31
- it 'displays the bar with no indication of progress when just begun' do
32
- progress = Progress.new(:total => 50)
33
- progressbar = Bar.new(:progress => progress,
34
- :length => 100)
35
-
36
- expect(progressbar.to_s).to eql ' ' * 100
37
- end
38
-
39
- it 'displays the bar with an indication of progress when nothing has been ' \
40
- 'completed and the bar is incremented' do
41
-
42
- progress = Progress.new :total => 50
43
- progressbar = Bar.new :progress => progress,
44
- :length => 100
45
- progress.increment
46
-
47
- expect(progressbar.to_s).to eql '==' + (' ' * 98)
48
- end
49
-
50
- it 'displays the bar with no indication of progress when nothing has been ' \
51
- 'completed and the bar is incremented' do
52
-
53
- progress = Progress.new :total => 50
54
- progressbar = Bar.new :progress => progress,
55
- :length => 100
56
-
57
- expect(progressbar.to_s).to eql ' ' * 100
58
- end
59
-
60
- it 'displays the bar with no indication of progress when a fraction of a percentage ' \
61
- 'has been completed' do
62
-
63
- progress = Progress.new :total => 200
64
- progressbar = Bar.new :progress => progress,
65
- :length => 100
66
- progress.start :at => 1
67
-
68
- expect(progressbar.to_s).to eql(' ' * 100)
69
- end
70
-
71
- it 'displays the bar as 100% complete when completed' do
72
- progress = Progress.new :total => 50
73
- progressbar = Bar.new :progress => progress,
74
- :length => 100
75
- progress.start :at => 50
76
- progress.increment
77
-
78
- expect(progressbar.to_s).to eql '=' * 100
79
- end
80
-
81
- it 'displays the bar as 100% complete when completed and the bar is incremented' do
82
- progress = Progress.new :total => 50
83
- progressbar = Bar.new :progress => progress,
84
- :length => 100
85
- progress.start :at => 50
86
- progress.increment
87
-
88
- expect(progressbar.to_s).to eql '=' * 100
89
- end
90
-
91
- it 'displays the bar as 98% complete when completed and the bar is decremented' do
92
- progress = Progress.new :total => 50
93
- progressbar = Bar.new :progress => progress,
94
- :length => 100
95
- progress.start :at => 50
96
- progress.decrement
97
-
98
- expect(progressbar.to_s).to eql(('=' * 98) + (' ' * 2))
99
- end
100
-
101
- it 'is represented correctly when a bar has an unknown amount to completion' do
102
- progress = Progress.new :total => nil
103
- progressbar = Bar.new :progress => progress,
104
- :length => 80
105
-
106
- expect(progressbar.to_s).to eql('=---' * 20)
107
- end
108
-
109
- it 'is represented after being incremented once when a bar has an unknown amount ' \
110
- 'to completion' do
111
-
112
- progress = Progress.new :total => nil
113
- progressbar = Bar.new :progress => progress,
114
- :length => 80
115
-
116
- progress.increment
117
-
118
- expect(progressbar.to_s).to eql('-=--' * 20)
119
- end
120
-
121
- it 'is represented after being incremented twice when a bar has an unknown amount ' \
122
- 'to completion' do
123
-
124
- progress = Progress.new :total => nil
125
- progressbar = Bar.new :progress => progress,
126
- :length => 80
127
-
128
- 2.times { progress.increment }
129
-
130
- expect(progressbar.to_s).to eql('--=-' * 20)
131
- end
132
-
133
- it 'is represented correctly when a bar has a customized unknown animation' do
134
- progress = Progress.new :total => nil
135
- progressbar = Bar.new :progress => progress,
136
- :unknown_progress_animation_steps => ['*--', '-*-', '--*'],
137
- :length => 80
138
-
139
- expect(progressbar.to_s).to eql(('*--' * 26) + '*-')
140
- end
141
-
142
- it 'displays the bar with an integrated percentage properly when empty' do
143
- progress = Progress.new :total => 100
144
- progressbar = Bar.new :progress => progress,
145
- :length => 100
146
-
147
- bar_text = progressbar.to_s(:format => :integrated_percentage)
148
- expect(bar_text).to eql ' ' * 100
149
- end
150
-
151
- it 'displays the bar with an integrated percentage properly just before' \
152
- 'the percentage is displayed' do
153
-
154
- progress = Progress.new :total => 100
155
- progressbar = Bar.new :progress => progress,
156
- :length => 100
157
-
158
- 4.times { progress.increment }
159
-
160
- bar_text = progressbar.to_s(:format => :integrated_percentage)
161
- expect(bar_text).to eql '====' + (' ' * 96)
162
- end
163
-
164
- it 'displays the bar with an integrated percentage properly immediately after' \
165
- 'the percentage is displayed' do
166
-
167
- progress = Progress.new :total => 100
168
- progressbar = Bar.new :progress => progress,
169
- :length => 100
170
-
171
- 5.times { progress.increment }
172
-
173
- bar_text = progressbar.to_s(:format => :integrated_percentage)
174
- expect(bar_text).to eql '= 5 =' + (' ' * 95)
175
- end
176
-
177
- it 'displays the bar with an integrated percentage properly on double digit' \
178
- 'percentage' do
179
-
180
- progress = Progress.new :total => 100
181
- progressbar = Bar.new :progress => progress,
182
- :length => 100
183
-
184
- 10.times { progress.increment }
185
-
186
- bar_text = progressbar.to_s(:format => :integrated_percentage)
187
- expect(bar_text).to eql '=== 10 ===' + (' ' * 90)
188
- end
189
-
190
- it 'displays the bar with an integrated percentage properly when finished' do
191
-
192
- progress = Progress.new :total => 100
193
- progressbar = Bar.new :progress => progress,
194
- :length => 100
195
- progress.finish
196
-
197
- bar_text = progressbar.to_s(:format => :integrated_percentage)
198
- expect(bar_text).to eql(('=' * 47) + ' 100 ' + ('=' * 48))
199
- end
200
-
201
- it 'calculates the remaining negative space properly with an integrated percentage ' \
202
- 'bar of 0 percent' do
203
-
204
- progress = Progress.new :total => 200
205
- progressbar = Bar.new :progress => progress,
206
- :length => 100
207
-
208
- bar_text = progressbar.to_s(:format => :integrated_percentage)
209
- expect(bar_text).to eql ' ' * 100
210
-
211
- 9.times { progress.increment }
212
-
213
- bar_text = progressbar.to_s(:format => :integrated_percentage)
214
- expect(bar_text).to eql '====' + (' ' * 96)
215
-
216
- progress.increment
217
-
218
- bar_text = progressbar.to_s(:format => :integrated_percentage)
219
- expect(bar_text).to eql '= 5 =' + (' ' * 95)
220
- end
221
-
222
- it 'raises an error when attempting to set the current value of the bar to be ' \
223
- 'greater than the total' do
224
-
225
- progress = Progress.new :total => 10
226
- _progressbar = Bar.new :progress => progress
227
-
228
- expect { progress.start :at => 11 }.to \
229
- raise_error(InvalidProgressError,
230
- "You can't set the item's current value to be greater than the total.")
231
- end
232
- end
233
- end
234
- end
@@ -1,9 +0,0 @@
1
- require 'rspectacular'
2
- require 'ruby-progressbar/components/percentage'
3
-
4
- class ProgressBar
5
- module Components
6
- RSpec.describe Percentage do
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- require 'rspectacular'
2
- require 'ruby-progressbar/components/rate'
3
-
4
- class ProgressBar
5
- module Components
6
- RSpec.describe Rate do
7
- end
8
- end
9
- end
@@ -1,157 +0,0 @@
1
- require 'rspectacular'
2
- require 'ruby-progressbar/progress'
3
-
4
- class ProgressBar
5
- RSpec.describe Throttle do
6
- let(:timer) { ProgressBar::Timer.new(:time => ::Time) }
7
-
8
- it 'yields the first time if the throttle rate is given and the timer is not started' do
9
- throttle = ProgressBar::Throttle.new(:throttle_rate => 10,
10
- :throttle_timer => timer)
11
-
12
- yielded = false
13
-
14
- throttle.choke do
15
- yielded = true
16
- end
17
-
18
- expect(yielded).to be_a TrueClass
19
- end
20
-
21
- it 'does not yield after the initial yield if the period has not passed yet' do
22
- throttle = ProgressBar::Throttle.new(:throttle_rate => 10,
23
- :throttle_timer => timer)
24
- timer.start
25
-
26
- throttle.choke {}
27
-
28
- yielded = false
29
-
30
- (1..9).each do
31
- Timecop.freeze(1)
32
-
33
- throttle.choke do
34
- yielded = true
35
- end
36
- end
37
-
38
- Timecop.return
39
-
40
- expect(yielded).to be_a FalseClass
41
- end
42
-
43
- it 'always yields if forced to, even after the initial yield or if the period ' \
44
- 'has not passed' do
45
-
46
- throttle = ProgressBar::Throttle.new(:throttle_rate => 10,
47
- :throttle_timer => timer)
48
- timer.start
49
-
50
- throttle.choke {}
51
-
52
- yielded = 0
53
-
54
- (1..25).each do
55
- Timecop.freeze(1)
56
-
57
- throttle.choke(:force_update_if => true) do
58
- yielded += 1
59
- end
60
- end
61
-
62
- Timecop.return
63
-
64
- expect(yielded).to eql 25
65
- end
66
-
67
- it 'yields if the period has passed, even after the initial yield' do
68
- throttle = ProgressBar::Throttle.new(:throttle_rate => 10,
69
- :throttle_timer => timer)
70
- timer.start
71
-
72
- throttle.choke {}
73
-
74
- yielded = false
75
-
76
- Timecop.freeze(11)
77
-
78
- throttle.choke do
79
- yielded = true
80
- end
81
-
82
- Timecop.return
83
-
84
- expect(yielded).to eql true
85
- end
86
-
87
- it 'does not yield after a previous yield if the period has not passed yet' do
88
- throttle = ProgressBar::Throttle.new(:throttle_rate => 10,
89
- :throttle_timer => timer)
90
-
91
- Timecop.freeze(0)
92
-
93
- timer.start
94
-
95
- Timecop.freeze(15)
96
-
97
- throttle.choke {}
98
-
99
- yielded = false
100
-
101
- (16..24).each do
102
- Timecop.freeze(1)
103
-
104
- throttle.choke do
105
- yielded = true
106
- end
107
-
108
- expect(yielded).to eql false
109
- end
110
-
111
- Timecop.return
112
- end
113
-
114
- it 'yields after the period has passed, even after a previous yield' do
115
- throttle = ProgressBar::Throttle.new(:throttle_rate => 10,
116
- :throttle_timer => timer)
117
-
118
- Timecop.freeze(0)
119
-
120
- timer.start
121
-
122
- Timecop.freeze(15)
123
-
124
- throttle.choke {}
125
-
126
- yielded = false
127
-
128
- Timecop.freeze(10)
129
-
130
- throttle.choke do
131
- yielded = true
132
- end
133
-
134
- Timecop.return
135
-
136
- expect(yielded).to eql true
137
- end
138
-
139
- it 'does not throttle if no throttle rate is given' do
140
- throttle = Throttle.new(:throttle_timer => timer,
141
- :throttle_rate => nil)
142
- yield_count = 0
143
-
144
- (1..25).each do
145
- Timecop.freeze(1)
146
-
147
- throttle.choke do
148
- yield_count += 1
149
- end
150
- end
151
-
152
- Timecop.return
153
-
154
- expect(yield_count).to eql 25
155
- end
156
- end
157
- end