Class: Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/runner.rb

Class Method Summary collapse

Class Method Details

.formatter_optsObject



66
67
68
# File 'lib/runner.rb', line 66

def self.formatter_opts
  "-r #{File.dirname(__FILE__)}/resulting.rb -f RSpactorFormatter:STDOUT"
end

.initial_spec_run_abortObject



34
35
36
# File 'lib/runner.rb', line 34

def self.initial_spec_run_abort
  @interactor.wait_for_enter_key("** Hit <enter> to skip initial spec run", 3)
end

.loadObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/runner.rb', line 7

def self.load
  dotfile = File.join(ENV['HOME'], '.rspactor')
  Kernel.load dotfile if File.exists?(dotfile)
    
  dir = Dir.pwd
  @inspector  = Inspector.new(dir)
  @interactor = Interactor.new
  
  puts "** RSpactor is now watching at '#{dir}'"
  
  aborted = initial_spec_run_abort   
  @interactor.start_termination_handler
  run_all_specs unless aborted
  
  Listener.new(Inspector::EXTENSIONS) do |files|
    files_to_spec = []
    files.each do |file|
      spec_files = @inspector.determine_spec_files(file)
      unless spec_files.empty?
        puts spec_files.join("\n")
        files_to_spec.concat spec_files
      end
    end  
    run_spec_command(files_to_spec)
  end.run(dir)
end

.ruby_optsObject



78
79
80
81
# File 'lib/runner.rb', line 78

def self.ruby_opts
  other = ENV['RUBYOPT'] ? " #{ENV['RUBYOPT']}" : ''
  %(RUBYOPT='-Ilib:spec#{other}')
end

.run_all_specsObject



38
39
40
# File 'lib/runner.rb', line 38

def self.run_all_specs
  run_spec_command('spec')
end

.run_command(cmd) ⇒ Object



48
49
50
# File 'lib/runner.rb', line 48

def self.run_command(cmd)
  system(cmd)
end

.run_spec_command(paths) ⇒ Object



42
43
44
45
46
# File 'lib/runner.rb', line 42

def self.run_spec_command(paths)
  paths = Array(paths)
  return if paths.empty?
  run_command [ruby_opts, spec_runner, paths, spec_opts].flatten.join(' ')
end

.spec_optsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/runner.rb', line 52

def self.spec_opts
  if File.exist?('spec/spec.opts')
    opts = File.read('spec/spec.opts').gsub("\n", ' ')
  else
    opts = "--color"
  end
  
  opts << ' ' << formatter_opts
  # only add the "progress" formatter unless no other (besides growl) is specified
  opts << ' -f progress' unless opts.scan(/\s(?:-f|--format)\b/).length > 1
  
  opts
end

.spec_runnerObject



70
71
72
73
74
75
76
# File 'lib/runner.rb', line 70

def self.spec_runner
  if File.exist?("script/spec")
    "script/spec"
  else
    "spec"
  end
end