Sha256: 426745128599ed5763816c41d8d6efaa02e92647300decc79db5a5e5f6ec1433

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

module InfinityTest
  class ContinuousTesting
    attr_accessor :application, :global_commands
    
    def initialize(options)
      @application = options[:application]
      @global_commands = @application.construct_commands
    end
    
    # Start the Continuous Testing Server and begin to audit the files for changes
    #
    def start!
      run!(@global_commands)
      initialize_watchr!
    end

    def run!(commands)
      @application.run!(commands) unless commands.empty?
    end

    ##################
    # Watchr Methods #
    #################
    
    def initialize_watchr!
      script = Watchr::Script.new
      # add_rule script, :rule => @application.library_directory_pattern
      watch_lib_folder(script, @application.library_directory_pattern)
      add_rule script, :rule => @application.test_directory_pattern
      add_signal
      Watchr::Controller.new(script, Watchr.handler.new).run
    end
    
    def watch_lib_folder(script, library_directory_pattern)
      script.watch(library_directory_pattern) do |file|
        @application.run_changed_lib_file(file)
      end
    end

    def add_rule(script, options={})
      script.watch(options[:rule]) do |file|
        @application.run_changed_test_file(file)
      end
    end
    
    def add_signal
      Signal.trap 'INT' do
        if @sent_an_int then
           puts " Shutting down now"
           exit
        else
           puts " Interrupt a second time to quit"
           @sent_an_int = true
           Kernel.sleep 1.1
           run! @global_commands
           @sent_an_int = false 
        end       
      end      
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
infinity_test-0.2.0 lib/infinity_test/continuous_testing.rb
infinity_test-0.1.0 lib/infinity_test/continuous_testing.rb