Sha256: b930f8e9cb816cb62925d60ea44e1e4ddc5aa312c04cdd8c957205f02eb23bee

Contents?: true

Size: 1.06 KB

Versions: 11

Compression:

Stored size: 1.06 KB

Contents

require "jstdutil/test_runner"
require "jstdutil/hooks"
require "watchr"

module Jstdutil
  class Autotest
    attr_reader :runner
    AVAILABLE_HOOKS = [:initialize, :died, :quit, :ran_command, :run_command, :waiting]
    include Hooks

    def initialize(args)
      absolute_path = Pathname(File.join(Jstdutil.install_dir, "watchr_script"))
      script = Watchr::Script.new(absolute_path)
      @watchr_controller = Watchr::Controller.new(script, Watchr.handler.new)
      @runner = Jstdutil::TestRunner.new(args)
      $jstestdriver_test_runner = @runner
      @interrupted_at = nil
    rescue StandardError => err
      raise err
    end

    def run
      hook(:initialize)

      trap("INT") do
        if @interrupted_at && Time.now - @interrupted_at < 2
          puts "No more testing today, shutting down"
          @runner.finalize
          exit
        else
          @interrupted_at = Time.now
          puts "Running all tests, hit Ctrl-c again to exit"
          @runner.run
        end
      end

      @runner.run
      @watchr_controller.run
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
jstdutil-0.3.4 lib/jstdutil/autotest.rb
jstdutil-0.3.3 lib/jstdutil/autotest.rb
jstdutil-0.3.2 lib/jstdutil/autotest.rb
jstdutil-0.3.1 lib/jstdutil/autotest.rb
jstdutil-0.3.0 lib/jstdutil/autotest.rb
jstdutil-0.2.2 lib/jstdutil/autotest.rb
jstdutil-0.2.1 lib/jstdutil/autotest.rb
jstdutil-0.2.0 lib/jstdutil/autotest.rb
jstdutil-0.1.2 lib/jstdutil/autotest.rb
jstdutil-0.1.1 lib/jstdutil/autotest.rb
jstdutil-0.1.0 lib/jstdutil/autotest.rb