| Class | Spec::Runner::BehaviourRunner |
| In: |
lib/spec/runner/behaviour_runner.rb
|
| Parent: | Object |
| FILE_SORTERS | = | { 'mtime' => lambda {|file_a, file_b| File.mtime(file_b) <=> File.mtime(file_a)} |
# File lib/spec/runner/behaviour_runner.rb, line 5 5: def initialize(options, arg=nil) 6: @behaviours = [] 7: @options = options 8: end
# File lib/spec/runner/behaviour_runner.rb, line 10
10: def add_behaviour(behaviour)
11: if !specified_examples.nil? && !specified_examples.empty?
12: behaviour.retain_examples_matching!(specified_examples)
13: end
14: @behaviours << behaviour if behaviour.number_of_examples != 0 && !behaviour.shared?
15: end
# File lib/spec/runner/behaviour_runner.rb, line 62
62: def number_of_examples
63: @behaviours.inject(0) {|sum, behaviour| sum + behaviour.number_of_examples}
64: end
# File lib/spec/runner/behaviour_runner.rb, line 45
45: def prepare!(paths)
46: unless paths.nil? # It's nil when running single specs with ruby
47: paths = find_paths(paths)
48: sorted_paths = sort_paths(paths)
49: load_specs(sorted_paths) # This will populate @behaviours via callbacks to add_behaviour
50: end
51: @options.reporter.start(number_of_examples)
52: @behaviours.reverse! if @options.reverse
53: set_sequence_numbers
54: end
# File lib/spec/runner/behaviour_runner.rb, line 41
41: def report_dump
42: @options.reporter.dump
43: end
# File lib/spec/runner/behaviour_runner.rb, line 37
37: def report_end
38: @options.reporter.end
39: end
Runs all behaviours and returns the number of failures.
# File lib/spec/runner/behaviour_runner.rb, line 18
18: def run(paths, exit_when_done)
19: prepare!(paths)
20: begin
21: run_behaviours
22: rescue Interrupt
23: ensure
24: report_end
25: end
26: failure_count = report_dump
27:
28: heckle if(failure_count == 0 && !@options.heckle_runner.nil?)
29:
30: if(exit_when_done)
31: exit_code = (failure_count == 0) ? 0 : 1
32: exit(exit_code)
33: end
34: failure_count
35: end
# File lib/spec/runner/behaviour_runner.rb, line 56
56: def run_behaviours
57: @behaviours.each do |behaviour|
58: behaviour.run(@options.reporter, @options.dry_run, @options.reverse, @options.timeout)
59: end
60: end
# File lib/spec/runner/behaviour_runner.rb, line 74
74: def sort_paths(paths)
75: sorter = sorter(paths)
76: paths = paths.sort(&sorter) unless sorter.nil?
77: paths
78: end