Class: RSpactor::Interactor

Inherits:
Object
  • Object
show all
Defined in:
lib/rspactor/interactor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ Interactor

Returns a new instance of Interactor.



8
9
10
11
# File 'lib/rspactor/interactor.rb', line 8

def initialize(runner)
  @runner = runner
  ticker
end

Instance Attribute Details

#runnerObject (readonly)

Returns the value of attribute runner.



6
7
8
# File 'lib/rspactor/interactor.rb', line 6

def runner
  @runner
end

Class Method Details

.ticker_msg(msg, seconds_to_wait = 3, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rspactor/interactor.rb', line 13

def self.ticker_msg(msg, seconds_to_wait = 3, &block)
  $stdout.print msg
  if block
    @yielding_ticker = true
    Thread.new do
      loop do
        $stdout.print('.') if @yielding_ticker == true
        $stdout.flush
        sleep 1.0
      end
    end
    
    yield
    @yielding_ticker = false
  else
    seconds_to_wait.times do
      $stdout.print('.')
      $stdout.flush
      sleep 1
    end
  end
  $stdout.puts "\n"
end

Instance Method Details

#start_termination_handlerObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rspactor/interactor.rb', line 52

def start_termination_handler
  @main_thread = Thread.current
  Thread.new do
    loop do
      sleep 0.5
      if entry = $stdin.gets
        case entry
        when "c\n" # Cucumber: current tagged feature
          runner.run_cucumber_command
        when "ca\n" # Cucumber All: ~pending tagged feature
          runner.run_cucumber_command('~@wip,~@pending')
        when "r\n"
          runner.spork.reload if runner.spork
        else
          if wait_for_enter_key("** Running all specs... Hit <enter> again to exit RSpactor", 1)
            @main_thread.exit
            exit
          end
          runner.run_all_specs
        end
      end
    end
  end
end

#wait_for_enter_key(msg, seconds_to_wait, clear = runner.options[:clear]) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspactor/interactor.rb', line 37

def wait_for_enter_key(msg, seconds_to_wait, clear = runner.options[:clear])
  begin
    Timeout::timeout(seconds_to_wait) do
      system("clear;") if clear
      ticker(:start => true, :msg => msg)
      $stdin.gets
      return true
    end
  rescue Timeout::Error
    false
  ensure
    ticker(:stop => true)
  end
end