Rspec Steps C0 Coverage Information - RCov

rcov/ruby/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb 300 243
79.33%
76.54%

Key

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.

Coverage Details

1 module RSpec
2   module Core
3     class ExampleGroup
4       extend  Extensions::ModuleEvalWithArgs
5       include Extensions::InstanceEvalWithArgs
6       extend  Hooks
7       extend  Subject::ClassMethods
8       include Subject::InstanceMethods
9       include Let
10       include Pending
11 
12       attr_accessor :example
13 
14       def running_example
15         RSpec.deprecate("running_example", "example")
16         example
17       end
18 
19       def self.world
20         RSpec.world
21       end
22 
23       def self.register
24         RSpec::Core::Runner.autorun
25         world.register(self)
26       end
27 
28       class << self
29         def self.delegate_to_metadata(*names)
30           names.each do |name|
31             define_method name do
32               metadata[:example_group][name]
33             end
34           end
35         end
36 
37         delegate_to_metadata :description, :describes, :file_path
38         alias_method :display_name, :description
39         alias_method :described_class, :describes
40       end
41 
42       def self.define_example_method(name, extra_options={})
43         module_eval(<<-END_RUBY, __FILE__, __LINE__)
44           def self.#{name}(desc=nil, options={}, &block)
45             options.update(:pending => true) unless block
46             options.update(#{extra_options.inspect})
47             examples << RSpec::Core::Example.new(self, desc, options, block)
48             examples.last
49           end
50         END_RUBY
51       end
52 
53       define_example_method :example
54 
55       class << self
56         alias_method :alias_example_to, :define_example_method
57       end
58 
59       alias_example_to :it
60       alias_example_to :specify
61       alias_example_to :focused, :focused => true, :focus => true
62       alias_example_to :focus,   :focused => true, :focus => true
63       alias_example_to :pending, :pending => true
64       alias_example_to :xit,     :pending => true
65 
66       def self.define_shared_group_method(new_name, report_label=nil)
67         module_eval(<<-END_RUBY, __FILE__, __LINE__)
68           def self.#{new_name}(name, *args, &customization_block)
69             shared_block = world.shared_example_groups[name]
70             raise "Could not find shared example group named \#{name.inspect}" unless shared_block
71 
72             group = describe("#{report_label || "it should behave like"} \#{name}") do
73               module_eval_with_args(*args, &shared_block)
74               module_eval(&customization_block) if customization_block
75             end
76             group.metadata[:shared_group_name] = name
77             group
78           end
79         END_RUBY
80       end
81 
82       define_shared_group_method :it_should_behave_like
83 
84       class << self
85         alias_method :alias_it_should_behave_like_to, :define_shared_group_method
86       end
87 
88       alias_it_should_behave_like_to :it_behaves_like, "behaves like"
89 
90       def self.examples
91         @examples ||= []
92       end
93 
94       def self.filtered_examples
95         world.filtered_examples[self]
96       end
97 
98       def self.descendant_filtered_examples
99         @descendant_filtered_examples ||= filtered_examples + children.inject([]){|l,c| l + c.descendant_filtered_examples}
100       end
101 
102       def self.metadata
103         @metadata if defined?(@metadata)
104       end
105 
106       def self.superclass_metadata
107         @superclass_metadata ||= self.superclass.respond_to?(:metadata) ? self.superclass.metadata : nil
108       end
109 
110       def self.describe(*args, &example_group_block)
111         @_subclass_count ||= 0
112         @_subclass_count += 1
113         args << {} unless args.last.is_a?(Hash)
114         args.last.update(:example_group_block => example_group_block)
115 
116         # TODO 2010-05-05: Because we don't know if const_set is thread-safe
117         child = const_set(
118           "Nested_#{@_subclass_count}",
119           subclass(self, args, &example_group_block)
120         )
121         children << child
122         child
123       end
124 
125       class << self
126         alias_method :context, :describe
127       end
128 
129       def self.subclass(parent, args, &example_group_block)
130         subclass = Class.new(parent)
131         subclass.set_it_up(*args)
132         subclass.module_eval(&example_group_block) if example_group_block
133         subclass
134       end
135 
136       def self.children
137         @children ||= []
138       end
139 
140       def self.descendants
141         @_descendants ||= [self] + children.inject([]) {|list, c| list + c.descendants}
142       end
143 
144       def self.ancestors
145         @_ancestors ||= super().select {|a| a < RSpec::Core::ExampleGroup}
146       end
147 
148       def self.top_level?
149         @top_level ||= superclass == ExampleGroup
150       end
151 
152       def self.set_it_up(*args)
153         @metadata = RSpec::Core::Metadata.new(superclass_metadata).process(*args)
154         world.configure_group(self)
155       end
156 
157       def self.before_all_ivars
158         @before_all_ivars ||= {}
159       end
160 
161       def self.store_before_all_ivars(example_group_instance)
162         return if example_group_instance.instance_variables.empty?
163         example_group_instance.instance_variables.each { |ivar| 
164           before_all_ivars[ivar] = example_group_instance.instance_variable_get(ivar)
165         }
166       end
167 
168       def self.assign_before_all_ivars(ivars, example_group_instance)
169         return if ivars.empty?
170         ivars.each { |ivar, val| example_group_instance.instance_variable_set(ivar, val) }
171       end
172 
173       def self.eval_before_alls(example_group_instance)
174         return if descendant_filtered_examples.empty?
175         assign_before_all_ivars(superclass.before_all_ivars, example_group_instance)
176         world.run_hook_filtered(:before, :all, self, example_group_instance)
177         run_hook!(:before, :all, example_group_instance)
178         store_before_all_ivars(example_group_instance)
179       end
180 
181       def self.eval_around_eachs(example, initial_procsy)
182         example.around_hooks.reverse.inject(initial_procsy) do |procsy, around_hook|
183           Example.procsy(procsy.metadata) do
184             example.example_group_instance.instance_eval_with_args(procsy, &around_hook)
185           end
186         end
187       end
188 
189       def self.eval_before_eachs(example)
190         world.run_hook_filtered(:before, :each, self, example.example_group_instance, example)
191         ancestors.reverse.each { |ancestor| ancestor.run_hook(:before, :each, example.example_group_instance) }
192       end
193 
194       def self.eval_after_eachs(example)
195         ancestors.each { |ancestor| ancestor.run_hook(:after, :each, example.example_group_instance) }
196         world.run_hook_filtered(:after, :each, self, example.example_group_instance, example)
197       end
198 
199       def self.eval_after_alls(example_group_instance)
200         return if descendant_filtered_examples.empty?
201         assign_before_all_ivars(before_all_ivars, example_group_instance)
202 
203         begin
204           run_hook!(:after, :all, example_group_instance)
205         rescue => e
206           # TODO: come up with a better solution for this.
207           RSpec.configuration.reporter.message <<-EOS
208 
209 An error occurred in an after(:all) hook.
210   #{e.class}: #{e.message}
211   occurred at #{e.backtrace.first}
212 
213         EOS
214         end
215 
216         world.run_hook_filtered(:after, :all, self, example_group_instance)
217       end
218 
219       def self.around_hooks_for(example)
220         world.find_hook(:around, :each, self, example) + ancestors.reverse.inject([]){|l,a| l + a.find_hook(:around, :each, self, example)}
221       end
222 
223       def self.run(reporter)
224         if RSpec.wants_to_quit
225           RSpec.clear_remaining_example_groups if top_level?
226           return
227         end
228         reporter.example_group_started(self)
229 
230         begin
231           eval_before_alls(new)
232           result_for_this_group = run_examples(reporter)
233           results_for_descendants = children.map {|child| child.run(reporter)}.all?
234           result_for_this_group && results_for_descendants
235         rescue Exception => ex
236           fail_filtered_examples(ex, reporter)
237         ensure
238           eval_after_alls(new)
239           reporter.example_group_finished(self)
240         end
241       end
242 
243       def self.fail_filtered_examples(exception, reporter)
244         filtered_examples.each { |example| example.fail_fast(reporter, exception) }
245 
246         children.each do |child|
247           reporter.example_group_started(child)
248           child.fail_filtered_examples(exception, reporter)
249           reporter.example_group_finished(child)
250         end
251       end
252 
253       def self.fail_fast?
254         RSpec.configuration.fail_fast?
255       end
256 
257       def self.run_examples(reporter)
258         filtered_examples.map do |example|
259           next if RSpec.wants_to_quit
260           instance = new
261           set_ivars(instance, before_all_ivars)
262           succeeded = example.run(instance, reporter)
263           RSpec.wants_to_quit = true if fail_fast? && !succeeded
264           succeeded
265         end.all?
266       end
267 
268       def self.apply?(predicate, filters)
269         metadata.apply?(predicate, filters)
270       end
271 
272       def self.declaration_line_numbers
273         @declaration_line_numbers ||= [metadata[:example_group][:line_number]] +
274           examples.collect {|e| e.metadata[:line_number]} +
275           children.inject([]) {|l,c| l + c.declaration_line_numbers}
276       end
277 
278       def self.top_level_description
279         ancestors.last.description
280       end
281 
282       def self.set_ivars(instance, ivars)
283         ivars.each {|name, value| instance.instance_variable_set(name, value)}
284       end
285 
286       def described_class
287         self.class.described_class
288       end
289 
290       def instance_eval_with_rescue(&hook)
291         begin
292           instance_eval(&hook)
293         rescue Exception => e
294           raise unless example
295           example.set_exception(e)
296         end
297       end
298     end
299   end
300 end

Generated on Fri Apr 22 17:22:42 -0700 2011 with rcov 0.9.8