Sha256: 9e5bc08dbfa113677531c9041e2b266f4041e03c428d95ecd61036673264d0e4

Contents?: true

Size: 921 Bytes

Versions: 3

Compression:

Stored size: 921 Bytes

Contents

module Retest
  class Runner
    def self.for(test_command)
      if test_command.include? '<test>'
        VariableRunner
      else
        HardcodedRunner
      end.new test_command
    end

    class VariableRunner
      attr_reader :command

      def initialize(command)
        @command = command
        @cached_test_file = nil
      end

      def ==(obj)
        command == obj.command
      end

      def run(test_file = nil)
        if @cached_test_file = test_file || @cached_test_file
          puts "Test File Selected: #{@cached_test_file}"
          system command.gsub('<test>', @cached_test_file)
        else
          puts <<~ERROR
            404 - Test File Not Found
            Retest could not find a matching test file to run.
          ERROR
        end
      end
    end

    HardcodedRunner = Struct.new(:command) do
      def run(_ = nil)
        system command
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
retest-0.8.0.pre3 lib/retest/runner.rb
retest-0.8.0.pre2 lib/retest/runner.rb
retest-0.8.0.pre lib/retest/runner.rb