Skip to content

Commit

Permalink
Add: fuubar_auto_refresh Configuration Option
Browse files Browse the repository at this point in the history
Why This Change Is Necessary
========================================================================

When using things like byebug and pry, stopping the execution for
debugging means that you'll also want to stop the bar from refreshing so
that you don't end up with bars all over the screen.

How These Changes Address the Issue
========================================================================

Add a fuubar_auto_refresh RSpec configuration setting which, if set to
`false`, will disable the refresh.

Side Effects Caused By This Change
========================================================================

None known.

------------------------------------------------------------------------
Actions:
  * Closes #105
  • Loading branch information
jfelchner committed May 28, 2019
1 parent 455ae3e commit 0cbd381
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions lib/fuubar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
require 'fuubar/output'

RSpec.configuration.add_setting :fuubar_progress_bar_options, :default => {}
RSpec.configuration.add_setting :fuubar_auto_refresh, :default => true

if Object.const_defined?('Pry')
Pry.
config.
hooks.
add_hook(:when_started, :fuubar_kill_refresh) do |_target, _opt, _|
RSpec.configuration.fuubar_auto_refresh = false
end
end

class Fuubar < RSpec::Core::Formatters::BaseTextFormatter
DEFAULT_PROGRESS_BAR_OPTIONS = { :format => ' %c/%C |%w>%i| %e ' }.freeze
Expand Down Expand Up @@ -51,16 +61,15 @@ def start(notification)
self.passed_count = 0
self.pending_count = 0
self.failed_count = 0
self.example_tick_thread = start_tick_thread(notification)

if Object.const_defined?('Pry')
Pry.
config.
hooks.
add_hook(:when_started, :fuubar_kill_refresh) do |_target, _opt, _|
example_tick_thread.kill
end
end
self.example_tick_thread = Thread.new do
loop do
sleep(1)

if configuration.fuubar_auto_refresh
example_tick(notification)
end
end
end # rubocop:disable Layout/BlockAlignment

super

Expand Down Expand Up @@ -163,14 +172,4 @@ def continuous_integration?
@continuous_integration ||= \
![nil, '', 'false'].include?(ENV['CONTINUOUS_INTEGRATION'])
end

def start_tick_thread(notification)
Thread.new do
loop do
sleep(1)

example_tick(notification)
end
end
end
end

0 comments on commit 0cbd381

Please sign in to comment.