Skip to content

Commit

Permalink
Change specs to improve formatting and ensure frozen time is reset
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jan 15, 2021
1 parent 59801d5 commit ac94cfc
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions spec/unit/bar_format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

output.rewind
expect(output.read).to eq([
"\e[1G[#{unknown}#{" " * left_chars}]",
"\e[1G[#{unknown}#{" " * left_chars}]",
"\e[1G[#{unknown}#{' ' * left_chars}]",
"\e[1G[#{unknown}#{' ' * left_chars}]"
].join)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/formatter/bar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
"\e[1G[本本> 〜]",
"\e[1G[本本> 〜]",
"\e[1G[本本本> ]",
"\e[1G[本本本> ]\n",
"\e[1G[本本本> ]\n"
].join)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/formatter/elapsed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

before { Timecop.safe_mode = false }

after { Timecop.return }

it "displays elapsed time" do
time_now = Time.local(2014, 10, 5, 12, 0, 0)
Timecop.freeze(time_now)
Expand All @@ -24,7 +26,6 @@
"\e[1G 3s",
"\e[1G 4s"
].join)
Timecop.return
end

it "resets elapsed time" do
Expand Down Expand Up @@ -101,8 +102,7 @@
"\e[1G 6s",
"\e[1G 6s\n", # finished
"\e[1G 6s",
"\e[1G 7s\n",
"\e[1G 7s\n"
].join)
Timecop.return
end
end
4 changes: 2 additions & 2 deletions spec/unit/formatter/estimated_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

before { Timecop.safe_mode = false }

after { Timecop.return }

it "displays elapsed time" do
time_now = Time.local(2014, 10, 5, 12, 0, 0)
Timecop.freeze(time_now)
Expand All @@ -24,7 +26,6 @@
"\e[1G 0s",
"\e[1G 0s\n"
].join)
Timecop.return
end

it "displays unknown elapsed time when no total" do
Expand All @@ -49,6 +50,5 @@
"\e[1G 0s",
"\e[1G 0s\n"
].join)
Timecop.return
end
end
9 changes: 5 additions & 4 deletions spec/unit/formatter/estimated_time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
RSpec.describe TTY::ProgressBar, ":eta_time token" do
let(:output) { StringIO.new }

before { Timecop.safe_mode = false }

after { Timecop.return }

it "displays estimated completion time of day" do
time_now = Time.local(2020, 1, 5, 12, 0, 0)
Timecop.freeze(time_now)
Expand All @@ -22,7 +26,6 @@
"\e[1G 12:00:03",
"\e[1G 12:00:04\n"
].join)
Timecop.return
end

it "displays estimated completion time of day with date after 24 hours" do
Expand All @@ -39,9 +42,8 @@
output.rewind
expect(output.read).to eq([
"\e[1G 12:00:00",
"\e[1G 2020-01-09 00:00:00",
"\e[1G 2020-01-09 00:00:00"
].join)
Timecop.return
end

it "displays unknown estimated completion time of day as --:--:--" do
Expand All @@ -66,6 +68,5 @@
"\e[1G 12:00:00",
"\e[1G 12:00:01\n"
].join)
Timecop.return
end
end
4 changes: 2 additions & 2 deletions spec/unit/formatter/mean_byte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

before { Timecop.safe_mode = false }

after { Timecop.return }

it "shows mean rate in bytes per sec" do
time_now = Time.local(2014, 10, 5, 12, 0, 0)
Timecop.freeze(time_now)
Expand All @@ -29,7 +31,6 @@
"\e[1G1000B",
"\e[1G1.22KB\n"
].join)
Timecop.return
end

it "displays mean rate in bytes per sec when no total" do
Expand All @@ -49,6 +50,5 @@
"\e[1G1000B",
"\e[1G1.22KB"
].join)
Timecop.return
end
end
4 changes: 2 additions & 2 deletions spec/unit/formatter/mean_rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

before { Timecop.safe_mode = false }

after { Timecop.return }

it "shows current rate per sec" do
time_now = Time.local(2014, 10, 5, 12, 0, 0)
Timecop.freeze(time_now)
Expand All @@ -28,7 +30,6 @@
"\e[1G10.00",
"\e[1G12.50\n"
].join)
Timecop.return
end

it "displays mean rate per sec when no total" do
Expand All @@ -48,6 +49,5 @@
"\e[1G10.00",
"\e[1G12.50"
].join)
Timecop.return
end
end
4 changes: 2 additions & 2 deletions spec/unit/formatter/rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

before { Timecop.safe_mode = false }

after { Timecop.return }

it "shows current rate per sec" do
time_now = Time.local(2014, 10, 5, 12, 0, 0)
Timecop.freeze(time_now)
Expand All @@ -28,7 +30,6 @@
"\e[1G15.00",
"\e[1G20.00\n"
].join)
Timecop.return
end

it "displays rate per sec when no total" do
Expand All @@ -48,6 +49,5 @@
"\e[1G15.00",
"\e[1G20.00"
].join)
Timecop.return
end
end
6 changes: 4 additions & 2 deletions spec/unit/head_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
end

it "exceeds 2 characters" do
progress = TTY::ProgressBar.new("[:bar]",
progress = TTY::ProgressBar.new(
"[:bar]",
output: output,
head: ">>>",
complete: "-", incomplete: ".", total: 20)
complete: "-", incomplete: ".", total: 20
)
5.times { progress.advance(4) }
output.rewind
expect(output.read).to eq([
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/multi/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
bars = TTY::ProgressBar::Multi.new("[:bar]")

expect {
bars.on(:unknown) { }
bars.on(:unknown) {}
}.to raise_error(
ArgumentError,
"The event unknown does not exist. Use :progress, :stopped, :paused or " \
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/pause_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
expect(output.read).to eq([
"\e[1G[= ]",
"\e[1G[== ]",
"\e[1G[=== ]",
"\e[1G[=== ]"
].join)
end
end
2 changes: 2 additions & 0 deletions spec/unit/resume_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"\e[1G[========= ] 12/13 92% 12B/13B 1B/s 1B/s 1.00/s 1.00/s 3s 0s",
"\e[1G[==========] 13/13 100% 13B/13B 1B/s 1B/s 1.00/s 1.00/s 4s 0s\n"
].join)
Timecop.return
end

it "resumes paused progression with all the metrics" do
Expand Down Expand Up @@ -137,5 +138,6 @@
"\e[1G[===== ] 5/10 50% 5B/10B 1B/s 1B/s 1.00/s 1.00/s 3s 3s",
"\e[1G[====== ] 6/10 60% 6B/10B 1B/s 1B/s 1.00/s 1.00/s 4s 2s"
].join)
Timecop.return
end
end

0 comments on commit ac94cfc

Please sign in to comment.