Skip to content

Commit 1bcaca6

Browse files
committed
Chore: Shore Up Tests
1 parent 22a0210 commit 1bcaca6

File tree

12 files changed

+718
-426
lines changed

12 files changed

+718
-426
lines changed

lib/ruby-progressbar/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def initialize(options = {}) # rubocop:disable Metrics/AbcSize
3333
self.timer = Timer.new(options)
3434
self.progressable = Progress.new(options)
3535

36-
options = options.merge(:progress => progressable,
37-
:timer => timer)
36+
options = options.merge(:progress => progressable,
37+
:timer => timer)
3838

3939
self.title_component = Components::Title.new(options)
4040
self.bar_component = Components::Bar.new(options)

lib/ruby-progressbar/components/bar.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@ def to_s(options = { :format => :standard })
3232
end
3333
end
3434

35-
private
36-
37-
def integrated_percentage_complete_string
38-
return standard_complete_string if completed_length < 5
39-
40-
" #{progress.percentage_completed} ".to_s.center(completed_length, progress_mark)
41-
end
42-
43-
def standard_complete_string
44-
progress_mark * completed_length
45-
end
46-
47-
def incomplete_string
48-
remainder_mark * (length - completed_length)
49-
end
50-
5135
def bar(length)
5236
self.length = length
5337

@@ -66,12 +50,6 @@ def complete_bar_with_percentage(length)
6650
to_s(:format => :integrated_percentage)
6751
end
6852

69-
def unknown_string
70-
unknown_frame_string = unknown_progress_frame * ((length / upa_steps.size) + 2)
71-
72-
unknown_frame_string[0, length]
73-
end
74-
7553
def incomplete_space(length)
7654
self.length = length
7755

@@ -88,6 +66,28 @@ def bar_with_percentage(length)
8866
integrated_percentage_complete_string
8967
end
9068

69+
private
70+
71+
def integrated_percentage_complete_string
72+
return standard_complete_string if completed_length < 5
73+
74+
" #{progress.percentage_completed} ".to_s.center(completed_length, progress_mark)
75+
end
76+
77+
def standard_complete_string
78+
progress_mark * completed_length
79+
end
80+
81+
def incomplete_string
82+
remainder_mark * (length - completed_length)
83+
end
84+
85+
def unknown_string
86+
unknown_frame_string = unknown_progress_frame * ((length / upa_steps.size) + 2)
87+
88+
unknown_frame_string[0, length]
89+
end
90+
9191
def completed_length
9292
(length * progress.percentage_completed / 100).floor
9393
end

lib/ruby-progressbar/components/percentage.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ def initialize(options = {})
77
self.progress = options[:progress]
88
end
99

10-
private
11-
1210
def percentage
13-
progress.percentage_completed
11+
progress.percentage_completed.to_s
1412
end
1513

1614
def justified_percentage

lib/ruby-progressbar/components/rate.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@ class ProgressBar
22
module Components
33
class Rate
44
attr_accessor :rate_scale,
5-
:started_at,
6-
:stopped_at,
75
:timer,
86
:progress
97

108
def initialize(options = {})
119
self.rate_scale = options[:rate_scale] || lambda { |x| x }
12-
self.started_at = nil
13-
self.stopped_at = nil
1410
self.timer = options[:timer]
1511
self.progress = options[:progress]
1612
end
1713

18-
private
19-
2014
def rate_of_change(format_string = '%i')
21-
return 0 if elapsed_seconds <= 0
15+
return '0' if elapsed_seconds <= 0
2216

2317
format_string % scaled_rate
2418
end
@@ -27,6 +21,8 @@ def rate_of_change_with_precision
2721
rate_of_change('%.2f')
2822
end
2923

24+
private
25+
3026
def scaled_rate
3127
rate_scale.call(base_rate)
3228
end

lib/ruby-progressbar/components/time.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ def elapsed_with_label
3131
"#{ELAPSED_LABEL}: #{elapsed}"
3232
end
3333

34-
protected
35-
3634
def estimated_with_no_oob
3735
estimated_with_elapsed_fallback(nil)
3836
end
@@ -56,6 +54,8 @@ def estimated_wall_clock
5654
strftime(WALL_CLOCK_FORMAT)
5755
end
5856

57+
protected
58+
5959
attr_accessor :timer,
6060
:progress
6161

@@ -84,7 +84,9 @@ def elapsed
8484
end
8585

8686
def estimated_with_elapsed_fallback(out_of_bounds_time_format)
87-
progress.finished? ? elapsed_with_label : estimated_with_label(out_of_bounds_time_format)
87+
return elapsed_with_label if progress.finished?
88+
89+
estimated_with_label(out_of_bounds_time_format)
8890
end
8991

9092
def estimated_seconds_remaining
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'spec_helper'
2+
require 'ruby-progressbar/errors/invalid_progress_error'
3+
4+
class ProgressBar
5+
describe InvalidProgressError do
6+
end
7+
end

spec/lib/ruby-progressbar/base_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,9 @@ class ProgressBar
605605
end
606606
end
607607

608-
it 'can be converted into a hash', :time_mock => ::Time.utc(2012, 7, 26, 18, 0, 0) do
608+
it 'can be converted into a hash' do
609+
::Timecop.freeze(::Time.utc(2012, 7, 26, 18, 0, 0))
610+
609611
progressbar = ProgressBar::Base.new(:output => output,
610612
:total => 33,
611613
:title => 'My Title',
@@ -646,6 +648,8 @@ class ProgressBar
646648
'stopped?' => false,
647649
'finished?' => false
648650
)
651+
652+
::Timecop.return
649653
end
650654
end
651655
end

0 commit comments

Comments
 (0)