Skip to content
Browse files

Move run_hook to world

  • Loading branch information...
1 parent 593804e commit 63fb5c47bb5d5a6db9a9c91f714121f012b74c0b @dchelimsky dchelimsky committed May 9, 2010
Showing with 16 additions and 4 deletions.
  1. +2 −0 lib/rspec/core/configuration.rb
  2. +4 −4 lib/rspec/core/example_group.rb
  3. +10 −0 lib/rspec/core/world.rb
View
2 lib/rspec/core/configuration.rb
@@ -1,6 +1,8 @@
module Rspec
module Core
class Configuration
+ attr_reader :hooks # :nodoc:
+
# Control what examples are run by filtering
attr_accessor :filter
View
8 lib/rspec/core/example_group.rb
@@ -152,7 +152,7 @@ def self.eval_before_alls(running_example)
if superclass.respond_to?(:before_all_ivars)
superclass.before_all_ivars.each { |ivar, val| running_example.instance_variable_set(ivar, val) }
end
- configuration.find_hook(:before, :all, self).each { |blk| running_example.instance_eval(&blk) }
+ world.run_hook(:before, :all, self, running_example)
ancestors.reverse.each do |ancestor|
until ancestor.before_alls.empty?
@@ -163,13 +163,13 @@ def self.eval_before_alls(running_example)
end
def self.eval_before_eachs(running_example)
- configuration.find_hook(:before, :each, self).each { |blk| running_example.instance_eval(&blk) }
+ world.run_hook(:before, :each, self, running_example)
ancestors.reverse.each { |ancestor| ancestor.before_eachs.each { |blk| running_example.instance_eval(&blk) } }
end
def self.eval_after_eachs(running_example)
ancestors.each { |ancestor| ancestor.after_eachs.reverse.each { |blk| running_example.instance_eval(&blk) } }
- configuration.find_hook(:after, :each, self).each { |blk| running_example.instance_eval(&blk) }
+ world.run_hook(:after, :each, self, running_example)
end
def self.eval_after_alls(running_example)
@@ -179,7 +179,7 @@ def self.eval_after_alls(running_example)
running_example.instance_eval &ancestor.after_alls.pop
end
end
- configuration.find_hook(:after, :all, self).each { |blk| running_example.instance_eval(&blk) }
+ world.run_hook(:after, :all, self, running_example)
before_all_ivars.keys.each { |ivar| before_all_ivars[ivar] = running_example.instance_variable_get(ivar) }
end
View
10 lib/rspec/core/world.rb
@@ -40,6 +40,16 @@ def preceding_declaration_line(filter_line)
end
end
+ def run_hook(hook, scope, group, example)
+ find_hook(hook, scope, group).each { |blk| example.instance_eval(&blk) }
+ end
+
+ def find_hook(hook, scope, group)
+ Rspec.configuration.hooks[hook][scope].select do |filters, block|
+ group.all_apply?(filters)
+ end.map { |filters, block| block }
+ end
+
private
def all_apply?(conditions)

0 comments on commit 63fb5c4

Please sign in to comment.
Something went wrong with that request. Please try again.