Class: RSpactor::Runner

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, options = {}) ⇒ Runner

Returns a new instance of Runner.



12
13
14
15
16
17
# File 'lib/rspactor/runner.rb', line 12

def initialize(dir, options = {})
  @dir = dir
  @options = options
  @spork = Spork.new(self) if options[:spork]
  read_git_head
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



10
11
12
# File 'lib/rspactor/runner.rb', line 10

def dir
  @dir
end

#inspectorObject (readonly)

Returns the value of attribute inspector.



10
11
12
# File 'lib/rspactor/runner.rb', line 10

def inspector
  @inspector
end

#interactorObject (readonly)

Returns the value of attribute interactor.



10
11
12
# File 'lib/rspactor/runner.rb', line 10

def interactor
  @interactor
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/rspactor/runner.rb', line 10

def options
  @options
end

#sporkObject (readonly)

Returns the value of attribute spork.



10
11
12
# File 'lib/rspactor/runner.rb', line 10

def spork
  @spork
end

Class Method Details

.start(options = {}) ⇒ Object



5
6
7
8
# File 'lib/rspactor/runner.rb', line 5

def self.start(options = {})
  run_in = options.delete(:run_in) || Dir.pwd
  new(run_in, options).start
end

Instance Method Details

#cucumber?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/rspactor/runner.rb', line 84

def cucumber?
  @cucumber ||= File.exist?(File.join(dir, 'features'))
end

#last_run_failed?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/rspactor/runner.rb', line 80

def last_run_failed?
  @last_run_failed == false
end

#load_dotfileObject



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

def load_dotfile
  dotfile = File.join(ENV['HOME'], '.rspactor')
  if File.exists?(dotfile)
    begin
      Kernel.load dotfile
    rescue => e
      $stderr.puts "Error while loading #{dotfile}: #{e}"
    end
  end
end

#run_all_specsObject



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

def run_all_specs
  run_spec_command(File.join(dir, 'spec'))
end

#run_cucumber_command(tags = '@wip:2', clear = ) ⇒ Object



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

def run_cucumber_command(tags = '@wip:2', clear = @options[:clear])
  return unless cucumber?
  
  system("clear;") if clear
  puts "** Running all #{tags} tagged features..."
  cmd = [ruby_opts, cucumber_runner, cucumber_opts(tags)].flatten.join(' ')
  @last_run_failed = run_command(cmd)
end

#run_spec_command(paths) ⇒ Object



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

def run_spec_command(paths)
  paths = Array(paths)
  if paths.empty?
    @last_run_failed = nil
  else
    cmd = [ruby_opts, spec_runner, paths, spec_opts].flatten.join(' ')
    @last_run_failed = run_command(cmd)
  end
end

#spork?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/rspactor/runner.rb', line 88

def spork?
  spork != nil
end

#startObject



19
20
21
22
23
24
25
# File 'lib/rspactor/runner.rb', line 19

def start
  load_dotfile
  puts "** RSpactor, now watching at '#{dir}'"
  spork.start if spork?
  start_interactor
  start_listener
end

#start_interactorObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/rspactor/runner.rb', line 27

def start_interactor
  @interactor = Interactor.new(self)
  message = "** Hit <enter> to skip initial spec #{"& cucumber " if cucumber?}run"
  aborted = options[:skip] || @interactor.wait_for_enter_key(message, 2, false)
  @interactor.start_termination_handler
  unless aborted
    run_all_specs
    run_cucumber_command('~@wip,~@pending', false)
  end
end

#start_listenerObject



38
39
40
41
42
43
44
# File 'lib/rspactor/runner.rb', line 38

def start_listener
  @inspector = Inspector.new(self)
  
  Listener.new(Inspector::EXTENSIONS) do |files|
    changed_files(files) unless git_head_changed?
  end.run(dir)
end