C0 code coverage information
Generated on Mon Aug 13 01:18:55 -0400 2007 with rcov 0.8.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 module Spec
2 module Runner
3 class BehaviourRunner
4
5 def initialize(options, arg=nil)
6 @behaviours = []
7 @options = options
8 end
9
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
16
17 # Runs all behaviours and returns the number of failures.
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
36
37 def report_end
38 @options.reporter.end
39 end
40
41 def report_dump
42 @options.reporter.dump
43 end
44
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
55
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
61
62 def number_of_examples
63 @behaviours.inject(0) {|sum, behaviour| sum + behaviour.number_of_examples}
64 end
65
66 FILE_SORTERS = {
67 'mtime' => lambda {|file_a, file_b| File.mtime(file_b) <=> File.mtime(file_a)}
68 }
69
70 def sorter(paths)
71 FILE_SORTERS[@options.loadby]
72 end
73
74 def sort_paths(paths)
75 sorter = sorter(paths)
76 paths = paths.sort(&sorter) unless sorter.nil?
77 paths
78 end
79
80 private
81
82 # Sets the #number on each Example
83 def set_sequence_numbers
84 number = 0
85 @behaviours.each do |behaviour|
86 number = behaviour.set_sequence_numbers(number, @options.reverse)
87 end
88 end
89
90 def find_paths(paths)
91 result = []
92 paths.each do |path|
93 if File.directory?(path)
94 result += Dir["#{path}/**/*.rb"]
95 elsif File.file?(path)
96 result << path
97 else
98 raise "File or directory not found: #{path}"
99 end
100 end
101 result
102 end
103
104 def load_specs(paths)
105 paths.each do |path|
106 load path
107 end
108 end
109
110 def specified_examples
111 @options.examples
112 end
113
114 def heckle
115 heckle_runner = @options.heckle_runner
116 @options.heckle_runner = nil
117 behaviour_runner = self.class.new(@options)
118 behaviour_runner.instance_variable_set(:@behaviours, @behaviours)
119 heckle_runner.heckle_with(behaviour_runner)
120 end
121 end
122 end
123 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.