Skip to content

Commit

Permalink
chore: suppress whirly output during specs
Browse files Browse the repository at this point in the history
  • Loading branch information
markokajzer committed Feb 11, 2024
1 parent 800783c commit d8f7f65
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
22 changes: 21 additions & 1 deletion lib/code_review_leaderboard/spinner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,31 @@ module Spinner
def start
result = nil

Whirly.start(spinner: "dots", stop: "✔") do
Whirly.start(spinner: "dots", stop: "✔", **options) do
result = yield
end

result
end

private

# NOTE: For testing only
# Even when using rspec `expect {...}.to output`, output is not suppressed
def options
{
stream:,
non_tty: (ENV["RUBY_ENV"] == "test")
}
end

def stream
if ENV["RUBY_ENV"] == "test"
require "stringio"
StringIO.new
else
$stdout
end
end
end
end
4 changes: 3 additions & 1 deletion spec/code_review_leaderboard/spinner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
it "shows the spinner" do
described_class.start { "result" }

expect(Whirly).to have_received(:start).with(spinner: "dots", stop: "✔")
expect(Whirly).to have_received(:start).with(
hash_including(spinner: "dots", stop: "✔")
)
end

it "returns the result of the block" do
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ENV["RUBY_ENV"] = "test"

require "simplecov"
SimpleCov.start do
add_filter "spec/"
Expand Down

0 comments on commit d8f7f65

Please sign in to comment.