Skip to content

Commit

Permalink
optionally pass configuration to ExampleGroup.create
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Feb 19, 2010
1 parent 038f623 commit 992394a
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 183 deletions.
16 changes: 11 additions & 5 deletions lib/rspec/core/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,15 @@ def self.superclass_metadata
self.superclass.respond_to?(:metadata) ? self.superclass.metadata : nil
end

def self.configuration
@configuration
end

def self.set_it_up(*args)
@configuration = args.shift
@metadata = Rspec::Core::Metadata.process(superclass_metadata, *args)

Rspec::Core.configuration.find_modules(self).each do |include_or_extend, mod, opts|
configuration.find_modules(self).each do |include_or_extend, mod, opts|
if include_or_extend == :extend
send(:extend, mod) unless extended_modules.include?(mod)
else
Expand Down Expand Up @@ -116,6 +121,7 @@ def self.create(*args, &example_group_block)
def self._build(klass, given_caller, args, &example_group_block)
args << {} unless args.last.is_a?(Hash)
args.last.update(:example_group_block => example_group_block, :caller => given_caller)
args.unshift Rspec::Core.configuration unless args.first.is_a?(Rspec::Core::Configuration)
klass.set_it_up(*args)
klass.module_eval(&example_group_block) if example_group_block
klass
Expand Down Expand Up @@ -153,26 +159,26 @@ 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
Rspec::Core.configuration.find_advice(:before, :all, self).each { |blk| running_example.instance_eval(&blk) }
configuration.find_advice(:before, :all, self).each { |blk| running_example.instance_eval(&blk) }

before_alls.each { |blk| running_example.instance_eval(&blk) }
running_example.instance_variables.each { |ivar| before_all_ivars[ivar] = running_example.instance_variable_get(ivar) }
end

def self.eval_before_eachs(running_example)
Rspec::Core.configuration.find_advice(:before, :each, self).each { |blk| running_example.instance_eval(&blk) }
configuration.find_advice(:before, :each, self).each { |blk| running_example.instance_eval(&blk) }
before_ancestors.each { |ancestor| ancestor.before_eachs.each { |blk| running_example.instance_eval(&blk) } }
end

def self.eval_after_alls(running_example)
after_alls.each { |blk| running_example.instance_eval(&blk) }
Rspec::Core.configuration.find_advice(:after, :all, self).each { |blk| running_example.instance_eval(&blk) }
configuration.find_advice(:after, :all, self).each { |blk| running_example.instance_eval(&blk) }
before_all_ivars.keys.each { |ivar| before_all_ivars[ivar] = running_example.instance_variable_get(ivar) }
end

def self.eval_after_eachs(running_example)
after_ancestors.each { |ancestor| ancestor.after_eachs.each { |blk| running_example.instance_eval(&blk) } }
Rspec::Core.configuration.find_advice(:after, :each, self).each { |blk| running_example.instance_eval(&blk) }
configuration.find_advice(:after, :each, self).each { |blk| running_example.instance_eval(&blk) }
end

def self.run(reporter)
Expand Down
2 changes: 1 addition & 1 deletion rspec-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Chad Humphries", "David Chelimsky"]
s.date = %q{2010-02-16}
s.date = %q{2010-02-19}
s.default_executable = %q{rspec}
s.description = %q{Rspec runner and example group classes}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
Expand Down
Loading

0 comments on commit 992394a

Please sign in to comment.