-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to listen for events on multi bar
- Loading branch information
1 parent
dc5ee5e
commit 3546e2d
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# encoding: utf-8 | ||
|
||
RSpec.describe TTY::ProgressBar::Multi, 'events' do | ||
let(:output) { StringIO.new('', 'w+') } | ||
|
||
it "emits :progress eent when any of the registerd bars advances" do | ||
events = [] | ||
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5) | ||
bars.on(:progress) { events << :progress } | ||
|
||
bar = bars.register "one [:bar]" | ||
bar.advance | ||
|
||
expect(events).to eq([:progress]) | ||
end | ||
|
||
it "emits :done event when all progress bars finished" do | ||
events = [] | ||
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5) | ||
bars.on(:done) { events << :done } | ||
|
||
bar = bars.register "one [:bar]" | ||
|
||
bar.finish | ||
|
||
expect(events).to eq([:done]) | ||
end | ||
|
||
it "emits :done event when top level bar finished" do | ||
events = [] | ||
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5) | ||
bars.on(:done) { events << :done } | ||
|
||
bars.register "one [:bar]" | ||
|
||
bars.finish | ||
|
||
expect(events).to eq([:done]) | ||
end | ||
|
||
it "emits :stopped event when all registerd bars are stopped" do | ||
events = [] | ||
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5) | ||
bars.on(:stopped) { events << :stopped } | ||
|
||
bar = bars.register "one [:bar]" | ||
|
||
bar.stop | ||
|
||
expect(events).to eq([:stopped]) | ||
end | ||
|
||
it "emits :stopped event when top level bar finished" do | ||
events = [] | ||
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5) | ||
bars.on(:stopped) { events << :stopped } | ||
|
||
bars.register "one [:bar]" | ||
|
||
bars.stop | ||
|
||
expect(events).to eq([:stopped]) | ||
end | ||
end |