Class: Spork::RunStrategy::LocalProcess

Inherits:
Spork::RunStrategy
  • Object
show all
Defined in:
lib/spork/run_strategy/local_process.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.unload(*consts) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/spork/run_strategy/local_process.rb', line 57

def self.unload *consts
  consts.each do |const|
    const_str = const.to_s
    super_consts, const_to_remove = const_str.scan(/(.*)::(.*)$/).flatten
    if super_consts && Object.const_defined?(super_consts)
      Object.const_get(super_consts).send(:remove_const, const_to_remove)
    elsif Object.const_defined?(const_str)
      Object.send(:remove_const, const_str)
    end
  end
end

Instance Method Details

#run(argv, stderr, stdout) ⇒ Object



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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/spork/run_strategy/local_process.rb', line 8

def run(argv, stderr, stdout)
  $stdout, $stderr = stdout, stderr
  Spork::Ext::TabCompletion.init

  filter = argv
  additional_options = nil

  # in some libedit versions first #push into history won't add the item to
  # the history
  2.times {Readline::HISTORY.push argv.join(" ")}

  while running?
    test_framework.preload

    begin
      run_proc :each
      test_framework.additional_options = additional_options if additional_options
      test_framework.run_tests(filter, stderr, stdout)
      run_proc :after_each
    rescue Exception => e
      puts "#{e.class}: #{e.message}"
      puts e.backtrace
    ensure
      test_framework.reset
    end

    new_filter = Readline.readline("> '#{(filter + (additional_options || [])).join(" ")}' or: ").strip
    exit 0 if new_filter.downcase == "exit"

    unless new_filter.empty?
      Readline::HISTORY.push new_filter
      new_filter, *additional_options = new_filter.split(/\s+/)
      additional_options = nil if additional_options.empty?
      current_filter_without_lineno = filter_without_line_no filter[0]

      if new_filter == "*"
        filter = [current_filter_without_lineno]
      elsif new_filter =~ /^:\d+$/
        filter = [current_filter_without_lineno + new_filter]
      elsif File.exist? filter_without_line_no new_filter
        filter = [new_filter]
      else
        filter = [current_filter_without_lineno]
        additional_options = [new_filter]
      end
    end
  end
end