Rspec Steps C0 Coverage Information - RCov

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

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb 149 117
69.80%
61.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     module Hooks
4 
5       class Hook
6         attr_reader :options
7 
8         def initialize(options, &block)
9           @options = options
10           @block = block
11         end
12 
13         def options_apply?(example_or_group)
14           !example_or_group || example_or_group.apply?(:all?, options)
15         end
16 
17         def to_proc
18           @block
19         end
20 
21         def call
22           @block.call
23         end
24       end
25 
26       class BeforeHook < Hook
27         def run_in(example_group_instance)
28           if example_group_instance
29             example_group_instance.instance_eval(&self)
30           else
31             call
32           end
33         end
34       end
35 
36       class AfterHook < Hook
37         def run_in(example_group_instance)
38           if example_group_instance
39             example_group_instance.instance_eval_with_rescue(&self)
40           else
41             call
42           end
43         end
44       end
45 
46       class AroundHook < Hook
47         def call(wrapped_example)
48           @block.call(wrapped_example)
49         end
50       end
51 
52       class HookCollection < Array
53         def find_hooks_for(example_or_group)
54           self.class.new(select {|hook| hook.options_apply?(example_or_group)})
55         end
56 
57         def without_hooks_for(example_or_group)
58           self.class.new(reject {|hook| hook.options_apply?(example_or_group)})
59         end
60       end
61 
62       class BeforeHooks < HookCollection
63         def run_all(example_group_instance)
64           each {|h| h.run_in(example_group_instance) } unless empty?
65         end
66 
67         def run_all!(example_group_instance)
68           shift.run_in(example_group_instance) until empty?
69         end
70       end
71 
72       class AfterHooks < HookCollection
73         def run_all(example_group_instance)
74           reverse.each {|h| h.run_in(example_group_instance) } unless empty?
75         end
76 
77         def run_all!(example_group_instance)
78           pop.run_in(example_group_instance) until empty?
79         end
80       end
81 
82       class AroundHooks < HookCollection; end
83 
84       def hooks
85         @hooks ||= {
86           :around => { :each => AroundHooks.new },
87           :before => { :each => BeforeHooks.new, :all => BeforeHooks.new, :suite => BeforeHooks.new },
88           :after => { :each => AfterHooks.new, :all => AfterHooks.new, :suite => AfterHooks.new }
89         }
90       end
91 
92       def before(*args, &block)
93         scope, options = scope_and_options_from(*args)
94         hooks[:before][scope] << BeforeHook.new(options, &block)
95       end
96 
97       def after(*args, &block)
98         scope, options = scope_and_options_from(*args)
99         hooks[:after][scope] << AfterHook.new(options, &block)
100       end
101 
102       def around(*args, &block)
103         scope, options = scope_and_options_from(*args)
104         hooks[:around][scope] << AroundHook.new(options, &block)
105       end
106 
107       # Runs all of the blocks stored with the hook in the context of the
108       # example. If no example is provided, just calls the hook directly.
109       def run_hook(hook, scope, example_group_instance=nil)
110         hooks[hook][scope].run_all(example_group_instance)
111       end
112 
113       # Just like run_hook, except it removes the blocks as it evalutes them,
114       # ensuring that they will only be run once.
115       def run_hook!(hook, scope, example_group_instance)
116         hooks[hook][scope].run_all!(example_group_instance)
117       end
118 
119       def run_hook_filtered(hook, scope, group, example_group_instance, example = nil)
120         find_hook(hook, scope, group, example).run_all(example_group_instance)
121       end
122 
123       def find_hook(hook, scope, example_group_class, example = nil)
124         found_hooks = hooks[hook][scope].find_hooks_for(example || example_group_class)
125 
126         # ensure we don't re-run :all hooks that were applied to any of the parent groups
127         if scope == :all
128           super_klass = example_group_class.superclass
129           while super_klass != RSpec::Core::ExampleGroup
130             found_hooks = found_hooks.without_hooks_for(super_klass)
131             super_klass = super_klass.superclass
132           end
133         end
134 
135         found_hooks
136       end
137 
138     private
139 
140       def scope_and_options_from(scope=:each, options={})
141         if Hash === scope
142           options = scope
143           scope = :each
144         end
145         return scope, options
146       end
147     end
148   end
149 end

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