Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb 282 217
73.05%
65.44%

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 Spec
2   module Example
3 
4     module ExampleGroupMethods
5       class << self
6         attr_accessor :matcher_class
7 
8         def build_description_from(*args)
9           text = args.inject("") do |description, arg|
10             description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/)
11             description << arg.to_s
12           end
13           text == "" ? nil : text
14         end
15       end
16 
17       include Spec::Example::BeforeAndAfterHooks
18       include Spec::Example::Subject::ExampleGroupMethods
19       include Spec::Example::PredicateMatchers
20       include Spec::Example::ArgsAndOptions
21 
22       attr_reader :location
23 
24       def options # :nodoc:
25         @options ||= {}
26       end
27 
28       def inherited(klass) # :nodoc:
29         super
30         ExampleGroupFactory.register_example_group(klass)
31       end
32 
33       # Makes the describe/it syntax available from a class. For example:
34       #
35       #   class StackSpec < Spec::ExampleGroup
36       #     describe Stack, "with no elements"
37       #
38       #     before
39       #       @stack = Stack.new
40       #     end
41       #
42       #     it "should raise on pop" do
43       #       lambda{ @stack.pop }.should raise_error
44       #     end
45       #   end
46       #
47       def describe(*args, &example_group_block)
48         raise Spec::Example::NoDescriptionError.new("example group", caller(0)[1]) if args.empty?
49         if example_group_block
50           options = add_options(args)
51           set_location(options, caller(0)[1])
52           if options[:shared]
53             ExampleGroupFactory.create_shared_example_group(*args, &example_group_block)
54           else
55             subclass(*args, &example_group_block)
56           end
57         else
58           set_description(*args)
59         end
60       end
61       alias :context :describe
62 
63       # Use this to pull in examples from shared example groups.
64       def it_should_behave_like(*shared_example_groups)
65         shared_example_groups.each do |group|
66           include_shared_example_group(group)
67         end
68       end
69 
70       # Creates an instance of the current example group class and adds it to
71       # a collection of examples of the current example group.
72       def example(description=nil, options={}, backtrace=nil, &implementation)
73         example_proxy = ExampleProxy.new(description, options, backtrace || caller(0)[1])
74         example_proxies << example_proxy
75         example_implementations[example_proxy] = implementation || pending_implementation
76         example_proxy
77       end
78 
79       def pending_implementation
80         lambda { raise(Spec::Example::NotYetImplementedError) }
81       end
82 
83       alias_method :it, :example
84       alias_method :specify, :example
85 
86       # Use this to temporarily disable an example.
87       def xexample(description=nil, opts={}, &block)
88         Kernel.warn("Example disabled: #{description}")
89       end
90 
91       alias_method :xit, :xexample
92       alias_method :xspecify, :xexample
93 
94       def run(run_options)
95         examples = examples_to_run(run_options)
96         notify(run_options.reporter) unless examples.empty?
97         return true if examples.empty?
98         return dry_run(examples, run_options) if run_options.dry_run?
99 
100         define_methods_from_predicate_matchers
101 
102         success, before_all_instance_variables = run_before_all(run_options)
103         success, after_all_instance_variables  = run_examples(success, before_all_instance_variables, examples, run_options)
104         success                                = run_after_all(success, after_all_instance_variables, run_options)
105       end
106 
107       def set_description(*args)
108         @description_args, @options = args_and_options(*args)
109         @backtrace = caller(1)
110         @location = File.expand_path(options[:location]) if options[:location]
111         self
112       end
113 
114       def notify(reporter) # :nodoc:
115         reporter.example_group_started(ExampleGroupProxy.new(self))
116       end
117 
118       def description
119         @description ||= ExampleGroupMethods.build_description_from(*description_parts) || to_s
120       end
121 
122       def described_type
123         @described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)}
124       end
125 
126       def described_class
127         @described_class ||= Class === described_type ? described_type : nil
128       end
129 
130       def description_args
131         @description_args ||= []
132       end
133 
134       def description_parts #:nodoc:
135         @description_parts ||= example_group_hierarchy.inject([]) do |parts, example_group_class|
136           [parts << example_group_class.description_args].flatten
137         end
138       end
139 
140       def example_proxies # :nodoc:
141         @example_proxies ||= []
142       end
143 
144       def example_implementations # :nodoc:
145         @example_implementations ||= {}
146       end
147 
148       def examples(run_options=nil) #:nodoc:
149         (run_options && run_options.reverse) ? example_proxies.reverse : example_proxies
150       end
151 
152       def number_of_examples #:nodoc:
153         example_proxies.length
154       end
155 
156       def example_group_hierarchy
157         @example_group_hierarchy ||= ExampleGroupHierarchy.new(self)
158       end
159 
160       def nested_descriptions
161         example_group_hierarchy.nested_descriptions
162       end
163 
164       def include_constants_in(mod)
165         include mod if (Spec::Ruby.version.to_f >= 1.9) & (Module === mod) & !(Class === mod)
166       end
167 
168       def let(name, &block)
169         define_method name do
170           @assignments ||= {}
171           @assignments[name] ||= instance_eval(&block)
172         end
173       end
174 
175     private
176 
177       def subclass(*args, &example_group_block)
178         @class_count ||= 0
179         @class_count += 1
180         klass = const_set("Subclass_#{@class_count}", Class.new(self))
181         klass.set_description(*args)
182         klass.include_constants_in(args.last[:scope])
183         klass.module_eval(&example_group_block)
184         klass
185       end
186 
187       def dry_run(examples, run_options)
188         examples.each do |example|
189           run_options.reporter.example_started(example)
190           run_options.reporter.example_finished(example)
191         end
192       end
193 
194       def run_before_all(run_options)
195         return [true,{}] if example_group_hierarchy.before_all_parts.empty?
196         example_proxy = ExampleProxy.new("before(:all)")
197         before_all = new(example_proxy)
198         begin
199           example_group_hierarchy.run_before_all(before_all)
200           return [true, before_all.instance_variable_hash]
201         rescue Exception => e
202           run_options.reporter.example_failed(example_proxy, e)
203           return [false, before_all.instance_variable_hash]
204         end
205       end
206 
207       def run_examples(success, instance_variables, examples, run_options)
208         return [success, instance_variables] unless success
209 
210         after_all_instance_variables = instance_variables
211 
212         examples.each do |example|
213           example_group_instance = new(example, &example_implementations[example])
214           success &= example_group_instance.execute(run_options, instance_variables)
215           after_all_instance_variables = example_group_instance.instance_variable_hash
216         end
217 
218         return [success, after_all_instance_variables]
219       end
220 
221       def run_after_all(success, instance_variables, run_options)
222         return success if example_group_hierarchy.after_all_parts.empty?
223         example_proxy = ExampleProxy.new("after(:all)")
224         after_all = new(example_proxy)
225         after_all.set_instance_variables_from_hash(instance_variables)
226         example_group_hierarchy.run_after_all(after_all)
227         success
228       rescue Exception => e
229         run_options.reporter.example_failed(example_proxy, e)
230         false
231       end
232 
233       def examples_to_run(run_options)
234         return example_proxies unless examples_were_specified?(run_options)
235         if run_options.line_number_requested?
236           if location =~ /:#{run_options.example_line}:?/
237             example_proxies
238           else
239             example_proxies.select {|proxy| proxy.location =~ /:#{run_options.example_line}:?/}
240           end
241         else
242           example_proxies.reject do |proxy|
243             matcher = ExampleGroupMethods.matcher_class.
244               new(description.to_s, proxy.description)
245             !matcher.matches?(run_options.examples)
246           end
247         end
248       end
249 
250       def examples_were_specified?(run_options)
251         !run_options.examples.empty?
252       end
253 
254       def method_added(name) # :nodoc:
255         example(name.to_s, {}, caller(0)[1]) {__send__ name.to_s} if example_method?(name.to_s)
256       end
257 
258       def example_method?(method_name)
259         should_method?(method_name)
260       end
261 
262       def should_method?(method_name)
263         !(method_name =~ /^should(_not)?$/) &&
264         method_name =~ /^should/ &&
265         instance_method(method_name).arity < 1
266       end
267 
268       def include_shared_example_group(shared_example_group)
269         case shared_example_group
270         when SharedExampleGroup
271           include shared_example_group
272         else
273           unless example_group = SharedExampleGroup.find(shared_example_group)
274             raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found")
275           end
276           include(example_group)
277         end
278       end
279     end
280 
281   end
282 end

Generated on Mon May 10 23:40:27 -0700 2010 with rcov 0.9.8