Class: Runner

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

Class Method Summary collapse

Class Method Details

.extract_spec_root(file) ⇒ Object



57
58
59
# File 'lib/runner.rb', line 57

def self.extract_spec_root(file)
  file[0..file.index("spec") + 4]
end

.initial_spec_run_abortObject



69
70
71
# File 'lib/runner.rb', line 69

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

.loadObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/runner.rb', line 3

def self.load
  @inspector  = Inspector.new
  @interactor = Interactor.new

  puts "** RSpactor is now watching at '#{Dir.pwd}'"
  
  if initial_spec_run_abort   
    @interactor.start_termination_handler
  else
    @interactor.start_termination_handler
    run_all_specs 
  end
  
  Listener.new do |files|
    files_to_spec = []
    files.each do |file|
      spec_file = @inspector.find_spec_file(file)
      if spec_file
        puts spec_file
        files_to_spec << spec_file 
      end
    end  
    run_spec_command(files_to_spec) unless files_to_spec.empty?
  end
end

.run_all_specsObject



29
30
31
# File 'lib/runner.rb', line 29

def self.run_all_specs
  run_spec_command([@inspector.inner_spec_directory(Dir.pwd)])
end

.run_spec_command(locations) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/runner.rb', line 45

def self.run_spec_command(locations)
  base_spec_root  = extract_spec_root(locations.first)
  spec_runner_bin = script_runner(locations.first)
  locations = locations.join(" ")
  cmd =   "RAILS_ENV=test; "
  cmd <<  "#{spec_runner_bin} "
  cmd <<  "#{locations} #{spec_opts(base_spec_root)} "
  cmd <<  "-r #{File.dirname(__FILE__)}/../lib/resulting.rb -f RSpactorFormatter:STDOUT"
  #puts cmd
  system(cmd)
end

.run_specs_for_files(files, verbose = false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/runner.rb', line 33

def self.run_specs_for_files(files, verbose = false)
  files_to_spec = []
  files.each do |file|
    spec_file = @inspector.find_spec_file(file)
    if spec_file
      puts spec_file if verbose
      files_to_spec << spec_file 
    end
  end  
  run_spec_command(files_to_spec) unless files_to_spec.empty?
end

.script_runner(file) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/runner.rb', line 73

def self.script_runner(file)
  root = file[0..file.index("spec") - 1]
  if File.exist?(root + "script/spec")
    return root + "script/spec"
  else
    "spec"
  end
end

.spec_opts(base_spec_root) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/runner.rb', line 61

def self.spec_opts(base_spec_root)
  if File.exist?("#{base_spec_root}spec.opts")
    return "-O #{base_spec_root}spec.opts"
  else
    return "-c -f progress"
  end
end