Sha256: f4598e3daf1f681d6bc9299c0da477d07d3bf37528fc19197d4c0c1feeba22fb

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

module InfinityTest
  class Command
    attr_accessor :command, :results, :line, :ruby_version

    # Create new Command object that receive the ruby_version and the command string
    #
    def initialize(options={})
      @command = options[:command]
      @ruby_version = options[:ruby_version]
      @current_ruby_string = RVM::Environment.current_ruby_string
      @results = []
      @line = []
    end

    # Code taken in Autotest gem and change a little
    #
    def run!
      old_sync = $stdout.sync
      $stdout.sync = true      
      begin
        open("| #{@command}", "r") do |file|
          until file.eof? do
            test_line = file.getc or break
            if yarv?
              print(test_line)
            else
              putc(test_line)
            end
            @line.push(test_line)
            push_in_the_results(test_line)
          end
        end
      ensure
        $stdout.sync = old_sync      
      end
      @results = @results.join
      self
    end

    # Push in the results the test line
    # If have in the Ruby Enterpise Edition or Ruby 1.8.* pack the numbers returned.
    # Join otherwise.
    #
    def push_in_the_results(test_line)
      if test_line == ?\n
        @results.push(yarv? ? @line.join : @line.pack('c*'))
        @line.clear
      end
    end

    # Using yarv?
    #
    def yarv?
      @current_ruby_string =~ /ruby-1.9/
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
infinity_test-1.0.3 lib/infinity_test/command.rb
infinity_test-1.0.2 lib/infinity_test/command.rb
infinity_test-1.0.1 lib/infinity_test/command.rb
infinity_test-1.0.0 lib/infinity_test/command.rb