Module: Ruptr::Compat::RSpec::ExampleGroupHooks
- Included in:
- ExampleGroup
- Defined in:
- lib/ruptr/rspec/example_group.rb
Defined Under Namespace
Modules: ContextHooksInstanceMethods, ExampleHooksBaseInstanceMethods
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.def_hook(name, setup_method_name) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/ruptr/rspec/example_group.rb', line 89
def self.def_hook(name, setup_method_name)
iv_name = :"@#{name}"
attr_reader name
define_method(:"#{name}=") do |new|
instance_variable_set(iv_name, new)
send(setup_method_name)
new
end
end
|
Instance Method Details
#need_wrap_context? ⇒ Boolean
117
|
# File 'lib/ruptr/rspec/example_group.rb', line 117
def need_wrap_context? = context_around_layer_hook || context_before_hook || context_after_hook
|
#setup_context_hooks ⇒ Object
#setup_example_phase1_hooks ⇒ Object
161
162
163
164
165
166
167
168
|
# File 'lib/ruptr/rspec/example_group.rb', line 161
def setup_example_phase1_hooks
return if method_defined?(:wrap_example_phase1_hooks, false)
include ExampleHooksBaseInstanceMethods
eg = self
define_method(:wrap_example_phase1_hooks) do |down_h, &up|
super(down_h) { |h| instance_exec(h.chain(&up), &eg.example_around_hook) }
end
end
|
#setup_example_phase2_hooks ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/ruptr/rspec/example_group.rb', line 170
def setup_example_phase2_hooks
return if method_defined?(:wrap_example_phase2_hooks, false)
include ExampleHooksBaseInstanceMethods
eg = self
define_method(:wrap_example_phase2_hooks) do |down_h, &up|
super(down_h) do |h|
k = if eg.example_before_hook || eg.example_after_hook
lambda do |h|
instance_exec(h, &eg.example_before_hook) if eg.example_before_hook
up.call(h)
ensure
instance_exec(h.caught($!), &eg.example_after_hook) if eg.example_after_hook
end
else
up
end
if eg.example_around_layer_hook
instance_exec(h.chain(&k), &eg.example_around_layer_hook)
else
k.call(h)
end
end
end
end
|