summaryrefslogtreecommitdiff
path: root/spec/support/live_debugger.rb
blob: 9c0570bcbf73fc30fe480a768fdf0ebbf2a7db2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'io/console'

module LiveDebugger
  def live_debug
    puts "\nCurrent example is paused for live debugging."
    puts "Opening #{current_url} in your default browser..."
    puts "The current user credentials are: #{@current_user.username} / 12345678" if @current_user
    puts "Press '^C' to continue the execution of the example"

    `open #{current_url}`

    catch :unpause_test do
      trap('INT') { throw :unpause_test }
      loop do
        sleep(1)
      end
    end

    # If the command is 'DEFAULT', the Ruby's default handler will be invoked.
    # http://docs.rubydocs.org/rails-4-2-8-ruby-2-3-4/Ruby%202.3.4/classes/Kernel.html#method-i-trap
    trap('INT') { 'DEFAULT' }

    puts "Back to the example!"
  end
end