C0 code coverage information
Generated on Mon Aug 13 01:18:53 -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 DSL
3 class EvalModule < Module; end
4 class Behaviour
5 extend BehaviourCallbacks
6
7 class << self
8 def add_shared_behaviour(behaviour)
9 return if behaviour.equal?(found_behaviour = find_shared_behaviour(behaviour.description))
10 return if found_behaviour and File.expand_path(behaviour.description[:spec_path]) == File.expand_path(found_behaviour.description[:spec_path])
11 raise ArgumentError.new("Shared Behaviour '#{behaviour.description}' already exists") if found_behaviour
12 shared_behaviours << behaviour
13 end
14
15 def find_shared_behaviour(behaviour_description)
16 shared_behaviours.find { |b| b.description == behaviour_description }
17 end
18
19 def shared_behaviours
20 # TODO - this needs to be global, or at least accessible from
21 # from subclasses of Behaviour in a centralized place. I'm not loving
22 # this as a solution, but it works for now.
23 $shared_behaviours ||= []
24 end
25 end
26
27 def initialize(*args, &behaviour_block)
28 init_description(*args)
29 init_eval_module
30 before_eval
31 eval_behaviour(&behaviour_block)
32 end
33
34 private
35
36 def init_description(*args)
37 unless self.class == Behaviour
38 args << {} unless Hash === args.last
39 args.last[:behaviour_class] = self.class
40 end
41 @description = Description.new(*args)
42 end
43
44 def init_eval_module
45 @eval_module = EvalModule.new
46 @eval_module.extend BehaviourEval::ModuleMethods
47 @eval_module.include BehaviourEval::InstanceMethods
48 @eval_module.include described_type if described_type.class == Module
49 @eval_module.behaviour = self
50 @eval_module.description = @description
51 end
52
53 def eval_behaviour(&behaviour_block)
54 @eval_module.class_eval(&behaviour_block)
55 end
56
57 protected
58
59 def before_eval
60 end
61
62 public
63
64 def run(reporter, dry_run=false, reverse=false, timeout=nil)
65 raise "shared behaviours should never run" if shared?
66 # TODO - change add_behaviour to add_description ??????
67 reporter.add_behaviour(@description)
68 prepare_execution_context_class
69 before_all_errors = run_before_all(reporter, dry_run)
70
71 exs = reverse ? examples.reverse : examples
72 example_execution_context = nil
73
74 if before_all_errors.empty?
75 exs.each do |example|
76 example_execution_context = execution_context(example)
77 example_execution_context.copy_instance_variables_from(@before_and_after_all_context_instance) unless before_all_proc(behaviour_type).nil?
78
79 befores = before_each_proc(behaviour_type) {|e| raise e}
80 afters = after_each_proc(behaviour_type)
81 example.run(reporter, befores, afters, dry_run, example_execution_context, timeout)
82 end
83 end
84
85 @before_and_after_all_context_instance.copy_instance_variables_from(example_execution_context) unless after_all_proc(behaviour_type).nil?
86 run_after_all(reporter, dry_run)
87 end
88
89 def number_of_examples
90 examples.length
91 end
92
93 def matches?(specified_examples)
94 matcher ||= ExampleMatcher.new(description)
95
96 examples.each do |example|
97 return true if example.matches?(matcher, specified_examples)
98 end
99 return false
100 end
101
102 def shared?
103 @description[:shared]
104 end
105
106 def retain_examples_matching!(specified_examples)
107 return if specified_examples.index(description)
108 matcher = ExampleMatcher.new(description)
109 examples.reject! do |example|
110 !example.matches?(matcher, specified_examples)
111 end
112 end
113
114 def methods
115 my_methods = super
116 my_methods |= @eval_module.methods
117 my_methods
118 end
119
120 # Includes modules in the Behaviour (the <tt>describe</tt> block).
121 def include(*args)
122 @eval_module.include(*args)
123 end
124
125 def behaviour_type #:nodoc:
126 @description[:behaviour_type]
127 end
128
129 # Sets the #number on each Example and returns the next number
130 def set_sequence_numbers(number, reverse) #:nodoc:
131 exs = reverse ? examples.reverse : examples
132 exs.each do |example|
133 example.number = number
134 number += 1
135 end
136 number
137 end
138
139 protected
140
141 # Messages that this class does not understand
142 # are passed directly to the @eval_module.
143 def method_missing(sym, *args, &block)
144 @eval_module.send(sym, *args, &block)
145 end
146
147 def prepare_execution_context_class
148 plugin_mock_framework
149 weave_in_included_modules
150 define_predicate_matchers #this is in behaviour_eval
151 execution_context_class
152 end
153
154 def weave_in_included_modules
155 mods = [@eval_module]
156 mods << included_modules.dup
157 mods << Spec::Runner.configuration.modules_for(behaviour_type)
158 execution_context_class.class_eval do
159 # WARNING - the following can be executed in the context of any
160 # class, and should never pass more than one module to include
161 # even though we redefine include in this class. This is NOT
162 # tested anywhere, hence this comment.
163 mods.flatten.each {|mod| include mod}
164 end
165 end
166
167 def execution_context(example)
168 execution_context_class.new(example)
169 end
170
171 def run_before_all(reporter, dry_run)
172 errors = []
173 unless dry_run
174 begin
175 @before_and_after_all_context_instance = execution_context(nil)
176 @before_and_after_all_context_instance.instance_eval(&before_all_proc(behaviour_type))
177 rescue Exception => e
178 errors << e
179 location = "before(:all)"
180 # The easiest is to report this as an example failure. We don't have an Example
181 # at this point, so we'll just create a placeholder.
182 reporter.example_finished(Example.new(location), e, location) if reporter
183 end
184 end
185 errors
186 end
187
188 def run_after_all(reporter, dry_run)
189 unless dry_run
190 begin
191 @before_and_after_all_context_instance ||= execution_context(nil)
192 @before_and_after_all_context_instance.instance_eval(&after_all_proc(behaviour_type))
193 rescue Exception => e
194 location = "after(:all)"
195 reporter.example_finished(Example.new(location), e, location) if reporter
196 end
197 end
198 end
199
200 def plugin_mock_framework
201 case mock_framework = Spec::Runner.configuration.mock_framework
202 when Module
203 include mock_framework
204 else
205 require Spec::Runner.configuration.mock_framework
206 include Spec::Plugins::MockFramework
207 end
208 end
209
210 def description
211 @description.to_s
212 end
213
214 def described_type
215 @description.described_type
216 end
217
218 end
219 end
220 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.