class Guard::Test::Runner

Attributes

options[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/guard/test/runner.rb, line 9
def initialize(opts = {})
  @options = {
    bundler:  File.exist?("#{Dir.pwd}/Gemfile"),
    rubygems: false,
    rvm:      [],
    include:  %w[lib:test],
    drb:      false,
    zeus:     false,
    spring:   false,
    cli:      ''
  }.merge(opts)
end

Public Instance Methods

bundler?() click to toggle source
# File lib/guard/test/runner.rb, line 30
def bundler?
  if @bundler.nil?
    @bundler = options[:bundler] && !drb? && !zeus? && !spring?
  end
  @bundler
end
drb?() click to toggle source
# File lib/guard/test/runner.rb, line 41
def drb?
  if @drb.nil?
    @drb = options[:drb]
    begin
      require 'spork-testunit'
    rescue LoadError
    end
    Compat::UI.info('Using testdrb to run the tests') if @drb
  end
  @drb
end
rubygems?() click to toggle source
# File lib/guard/test/runner.rb, line 37
def rubygems?
  !bundler? && !zeus? && !spring? && options[:rubygems]
end
run(paths, opts = {}) click to toggle source
# File lib/guard/test/runner.rb, line 22
def run(paths, opts = {})
  return true if paths.empty?

  Compat::UI.info(opts[:message] || "Running: #{paths.join(' ')}", reset: true)

  system(test_unit_command(paths))
end
spring?() click to toggle source
# File lib/guard/test/runner.rb, line 61
def spring?
  if @spring.nil?
    @spring = options[:spring]
    Compat::UI.info('Using spring to run the tests') if @spring
  end
  @spring
end
zeus?() click to toggle source
# File lib/guard/test/runner.rb, line 53
def zeus?
  if @zeus.nil?
    @zeus = options[:zeus]
    Compat::UI.info('Using zeus to run the tests') if @zeus
  end
  @zeus
end

Private Instance Methods

command_options() click to toggle source
# File lib/guard/test/runner.rb, line 115
def command_options
  if drb? || zeus? || spring?
    []
  else
    ['--', '--use-color', '--runner=guard_test']
  end
end
executables() click to toggle source
# File lib/guard/test/runner.rb, line 80
def executables
  parts = []
  parts << "rvm #{options[:rvm].join(',')} exec" unless options[:rvm].empty?
  parts << 'bundle exec' if bundler?
  parts << case true
           when drb? then 'testdrb'
           when zeus? then 'zeus test'
           when spring? then spring_command
           else 'ruby'; end
end
includes_and_requires(paths) click to toggle source
# File lib/guard/test/runner.rb, line 100
def includes_and_requires(paths)
  parts = []
  parts << Array(options[:include]).map { |path| "-I\"#{path}\"" } unless zeus? || spring?
  parts << paths if zeus? || spring? || drb?
  parts << '-r bundler/setup' if bundler?
  parts << '-r rubygems' if rubygems?

  unless drb? || zeus? || spring?
    parts << "-r #{File.expand_path("../guard_test_runner", __FILE__)}"
    parts << "-e \"%w[#{paths.join(' ')}].each { |p| load p }\""
  end

  parts
end
spring_command() click to toggle source
# File lib/guard/test/runner.rb, line 91
def spring_command
  if Gem.loaded_specs["rails"] && Gem.loaded_specs["rails"].version < Gem::Version.create('4.0')
    'spring testunit'
  else
    # rails > 4.0 supports passing a path to rake test
    'spring rake test'
  end
end
test_unit_command(paths) click to toggle source
# File lib/guard/test/runner.rb, line 71
def test_unit_command(paths)
  cmd_parts = executables
  cmd_parts.concat(includes_and_requires(paths))
  cmd_parts.concat(command_options)
  cmd_parts << options[:cli]

  cmd_parts.compact.join(' ').strip
end