Permalink
Browse files

behaviour to example_group

  • Loading branch information...
1 parent 12615ba commit 6b1ff00afd4b79bd4b6136793ddb5ea301643b60 @dchelimsky dchelimsky committed Feb 4, 2010
View
@@ -8,7 +8,7 @@
require 'rspec/core/example'
require 'rspec/core/metadata'
require 'rspec/core/kernel_extensions'
-require 'rspec/core/shared_behaviour'
+require 'rspec/core/shared_example_group'
require 'rspec/core/example_group_subject'
require 'rspec/core/example_group'
require 'rspec/core/formatters'
View
@@ -2,11 +2,12 @@ module Rspec
module Core
class Example
- attr_reader :behaviour, :metadata, :example_block
+ attr_reader :example_group, :metadata, :example_block
+ alias_method :behaviour, :example_group
- def initialize(behaviour, desc, options, example_block=nil)
- @behaviour, @options, @example_block = behaviour, options, example_block
- @metadata = @behaviour.metadata.for_example(desc, options)
+ def initialize(example_group, desc, options, example_block=nil)
+ @example_group, @options, @example_block = example_group, options, example_block
+ @metadata = @example_group.metadata.for_example(desc, options)
end
def description
@@ -22,7 +23,7 @@ def execution_result
end
def file_path
- @metadata[:file_path] || behaviour.file_path
+ @metadata[:file_path] || example_group.file_path
end
def run_started
@@ -50,11 +51,11 @@ def run_finished(status, results={})
def run_before_each
@example_group_instance._setup_mocks if @example_group_instance.respond_to?(:_setup_mocks)
- @behaviour.eval_before_eachs(@example_group_instance)
+ @example_group.eval_before_eachs(@example_group_instance)
end
def run_after_each
- @behaviour.eval_after_eachs(@example_group_instance)
+ @example_group.eval_after_eachs(@example_group_instance)
@example_group_instance._verify_mocks if @example_group_instance.respond_to?(:_verify_mocks)
ensure
@example_group_instance._teardown_mocks if @example_group_instance.respond_to?(:_teardown_mocks)
@@ -92,10 +93,10 @@ def run(example_group_instance)
begin
run_before_each
- if @behaviour.around_eachs.empty?
+ if @example_group.around_eachs.empty?
@example_group_instance.instance_eval(&example_block) if runnable?
else
- @behaviour.around_eachs.first.call(AroundProxy.new(self, &example_block))
+ @example_group.around_eachs.first.call(AroundProxy.new(self, &example_block))
end
rescue Exception => e
exception_encountered = e
@@ -13,7 +13,7 @@ class ExampleGroup
def self.inherited(klass)
super
Rspec::Core.configuration.autorun!
- Rspec::Core.world.behaviours << klass
+ Rspec::Core.world.example_groups << klass
end
def self.extended_modules #:nodoc:
@@ -45,7 +45,7 @@ def self.#{new_alias}(desc=nil, options={}, &block)
alias_example_to :pending, :pending => true
def self.it_should_behave_like(*names)
- Rspec::Core.world.shared_behaviours.each do |name, block|
+ Rspec::Core.world.shared_example_groups.each do |name, block|
module_eval(&block) if names.include?(name)
end
end
@@ -75,36 +75,36 @@ def self.metadata
end
def self.name(friendly=true)
- friendly ? metadata[:behaviour][:name] : super
+ friendly ? metadata[:example_group][:name] : super
end
def self.describes
- metadata[:behaviour][:describes]
+ metadata[:example_group][:describes]
end
def self.described_class
describes || description
end
def self.description
- metadata[:behaviour][:description]
+ metadata[:example_group][:description]
end
def self.file_path
- metadata[:behaviour][:file_path]
+ metadata[:example_group][:file_path]
end
- def self.describe(*args, &behaviour_block)
+ def self.describe(*args, &example_group_block)
raise(ArgumentError, "No arguments given. You must a least supply a type or description") if args.empty?
- raise(ArgumentError, "You must supply a block when calling describe") if behaviour_block.nil?
+ raise(ArgumentError, "You must supply a block when calling describe") if example_group_block.nil?
# TODO: Pull out the below into a metadata object, that we can defer the subclassing if necessary
# describe 'foo', :shared => true will need this to be completed first
subclass('NestedLevel') do
args << {} unless args.last.is_a?(Hash)
- args.last.update(:behaviour_block => behaviour_block, :caller => caller)
+ args.last.update(:example_group_block => example_group_block, :caller => caller)
set_it_up(*args)
- module_eval(&behaviour_block)
+ module_eval(&example_group_block)
end
end
@@ -136,33 +136,33 @@ def self.before_all_ivars
@before_all_ivars ||= {}
end
- def self.eval_before_alls(running_behaviour)
- superclass.before_all_ivars.each { |ivar, val| running_behaviour.instance_variable_set(ivar, val) }
- Rspec::Core.configuration.find_advice(:before, :all, self).each { |blk| running_behaviour.instance_eval(&blk) }
+ def self.eval_before_alls(running_example_group)
+ superclass.before_all_ivars.each { |ivar, val| running_example_group.instance_variable_set(ivar, val) }
+ Rspec::Core.configuration.find_advice(:before, :all, self).each { |blk| running_example_group.instance_eval(&blk) }
- before_alls.each { |blk| running_behaviour.instance_eval(&blk) }
- running_behaviour.instance_variables.each { |ivar| before_all_ivars[ivar] = running_behaviour.instance_variable_get(ivar) }
+ before_alls.each { |blk| running_example_group.instance_eval(&blk) }
+ running_example_group.instance_variables.each { |ivar| before_all_ivars[ivar] = running_example_group.instance_variable_get(ivar) }
end
- def self.eval_before_eachs(running_behaviour)
- Rspec::Core.configuration.find_advice(:before, :each, self).each { |blk| running_behaviour.instance_eval(&blk) }
- before_ancestors.each { |ancestor| ancestor.before_eachs.each { |blk| running_behaviour.instance_eval(&blk) } }
+ def self.eval_before_eachs(running_example_group)
+ Rspec::Core.configuration.find_advice(:before, :each, self).each { |blk| running_example_group.instance_eval(&blk) }
+ before_ancestors.each { |ancestor| ancestor.before_eachs.each { |blk| running_example_group.instance_eval(&blk) } }
end
- def self.eval_after_alls(running_behaviour)
- after_alls.each { |blk| running_behaviour.instance_eval(&blk) }
- Rspec::Core.configuration.find_advice(:after, :all, self).each { |blk| running_behaviour.instance_eval(&blk) }
- before_all_ivars.keys.each { |ivar| before_all_ivars[ivar] = running_behaviour.instance_variable_get(ivar) }
+ def self.eval_after_alls(running_example_group)
+ after_alls.each { |blk| running_example_group.instance_eval(&blk) }
+ Rspec::Core.configuration.find_advice(:after, :all, self).each { |blk| running_example_group.instance_eval(&blk) }
+ before_all_ivars.keys.each { |ivar| before_all_ivars[ivar] = running_example_group.instance_variable_get(ivar) }
end
- def self.eval_after_eachs(running_behaviour)
- after_ancestors.each { |ancestor| ancestor.after_eachs.each { |blk| running_behaviour.instance_eval(&blk) } }
- Rspec::Core.configuration.find_advice(:after, :each, self).each { |blk| running_behaviour.instance_eval(&blk) }
+ def self.eval_after_eachs(running_example_group)
+ after_ancestors.each { |ancestor| ancestor.after_eachs.each { |blk| running_example_group.instance_eval(&blk) } }
+ Rspec::Core.configuration.find_advice(:after, :each, self).each { |blk| running_example_group.instance_eval(&blk) }
end
def self.run(reporter)
example_world = new
- reporter.add_behaviour(self)
+ reporter.add_example_group(self)
eval_before_alls(example_world)
success = run_examples(example_world, reporter)
eval_after_alls(example_world)
@@ -210,7 +210,7 @@ def assignments
end
def described_class
- running_example.metadata[:behaviour][:describes]
+ running_example.metadata[:example_group][:describes]
end
def __reset__
@@ -5,13 +5,13 @@ module Core
module Formatters
class BaseFormatter
- attr_accessor :behaviour
+ attr_accessor :example_group
attr_reader :example_count, :duration, :examples
def initialize
@example_count = 0
@examples = []
- @behaviour = nil
+ @example_group = nil
end
def configuration
@@ -43,7 +43,7 @@ def failed_examples
# formatters that need to provide progress on feedback (graphical ones)
#
# This method will only be invoked once, and the next one to be invoked
- # is #add_behaviour
+ # is #add_example_group
def start(example_count)
@example_count = example_count
end
@@ -52,13 +52,15 @@ def example_finished(example)
examples << example
end
- # This method is invoked at the beginning of the execution of each behaviour.
- # +behaviour+ is the behaviour.
+ # This method is invoked at the beginning of the execution of each example group.
+ # +example_group+ is the example_group.
#
# The next method to be invoked after this is #example_failed or #example_finished
- def add_behaviour(behaviour)
- @behaviour = behaviour
+ def add_example_group(example_group)
+ @example_group = example_group
end
+
+ alias_method :add_example_group, :add_example_group
# This method is invoked after all of the examples have executed. The next method
# to be invoked after this one is #dump_failure (once for each failed example),
@@ -6,28 +6,26 @@ module Formatters
class DocumentationFormatter < BaseTextFormatter
- attr_reader :previous_nested_behaviours
-
def initialize
super
- @previous_nested_behaviours = []
+ @previous_nested_example_groups = []
end
- def add_behaviour(behaviour)
+ def add_example_group(example_group)
super
- described_behaviour_chain.each_with_index do |nested_behaviour, i|
- unless nested_behaviour == previous_nested_behaviours[i]
+ described_example_group_chain.each_with_index do |nested_example_group, i|
+ unless nested_example_group == @previous_nested_example_groups[i]
at_root_level = (i == 0)
- desc_or_name = at_root_level ? nested_behaviour.name : nested_behaviour.description
+ desc_or_name = at_root_level ? nested_example_group.name : nested_example_group.description
output.puts if at_root_level
output.puts "#{' ' * i}#{desc_or_name}"
end
end
- @previous_nested_behaviours = described_behaviour_chain
+ @previous_nested_example_groups = described_example_group_chain
end
-
+
def output_for(example)
case example.execution_result[:status]
when 'failed'
@@ -68,11 +66,11 @@ def pending_output(example, message)
end
def current_indentation
- ' ' * previous_nested_behaviours.size
+ ' ' * @previous_nested_example_groups.size
end
- def described_behaviour_chain
- behaviour.ancestors
+ def described_example_group_chain
+ example_group.ancestors
end
end
@@ -2,10 +2,10 @@ module Rspec
module Core
module KernelExtensions
- def describe(*args, &behaviour_block)
+ def describe(*args, &example_group_block)
args << {} unless args.last.is_a?(Hash)
args.last.update :caller => caller(1)
- Rspec::Core::ExampleGroup.describe(*args, &behaviour_block)
+ Rspec::Core::ExampleGroup.describe(*args, &example_group_block)
end
alias :context :describe
View
@@ -13,24 +13,26 @@ def self.process(superclass_metadata, *args)
def initialize(superclass_metadata=nil)
@superclass_metadata = superclass_metadata
update(@superclass_metadata) if @superclass_metadata
- store(:behaviour, {})
+ store(:example_group, {})
+ store(:behaviour, self[:example_group])
yield self if block_given?
end
def process(*args)
extra_metadata = args.last.is_a?(Hash) ? args.pop : {}
- extra_metadata.delete(:behaviour) # Remove it when present to prevent it clobbering the one we setup
+ extra_metadata.delete(:example_group) # Remove it when present to prevent it clobbering the one we setup
+ extra_metadata.delete(:behaviour) # Remove it when present to prevent it clobbering the one we setup
- self[:behaviour][:describes] = args.shift unless args.first.is_a?(String)
- self[:behaviour][:describes] ||= self.superclass_metadata && self.superclass_metadata[:behaviour][:describes]
- self[:behaviour][:description] = args.shift || ''
+ self[:example_group][:describes] = args.shift unless args.first.is_a?(String)
+ self[:example_group][:describes] ||= self.superclass_metadata && self.superclass_metadata[:example_group][:describes]
+ self[:example_group][:description] = args.shift || ''
- self[:behaviour][:name] = determine_name
- self[:behaviour][:block] = extra_metadata.delete(:behaviour_block)
- self[:behaviour][:caller] = extra_metadata.delete(:caller)
- self[:behaviour][:file_path] = file_path_from(self[:behaviour], extra_metadata.delete(:file_path))
- self[:behaviour][:line_number] = line_number_from(self[:behaviour], extra_metadata.delete(:line_number))
- self[:behaviour][:location] = location_from(self[:behaviour])
+ self[:example_group][:name] = determine_name
+ self[:example_group][:block] = extra_metadata.delete(:example_group_block)
+ self[:example_group][:caller] = extra_metadata.delete(:caller)
+ self[:example_group][:file_path] = file_path_from(self[:example_group], extra_metadata.delete(:file_path))
+ self[:example_group][:line_number] = line_number_from(self[:example_group], extra_metadata.delete(:line_number))
+ self[:example_group][:location] = location_from(self[:example_group])
update(extra_metadata)
end
@@ -41,7 +43,7 @@ def for_example(description, options)
def configure_for_example(description, options)
store(:description, description.to_s)
- store(:full_description, "#{self[:behaviour][:name]} #{self[:description]}")
+ store(:full_description, "#{self[:example_group][:name]} #{self[:description]}")
store(:execution_result, {})
store(:caller, options.delete(:caller))
if self[:caller]
@@ -64,7 +66,7 @@ def apply_condition(filter_on, filter, metadata=nil)
filter.call(metadata[filter_on]) rescue false
when Fixnum
if filter_on == :line_number
- [metadata[:line_number],metadata[:behaviour][:line_number]].include?(filter)
+ [metadata[:line_number],metadata[:example_group][:line_number]].include?(filter)
else
metadata[filter_on] == filter
end
@@ -102,10 +104,10 @@ def candidate_entries_from_caller(metadata)
end
def determine_name
- if superclass_metadata && superclass_metadata[:behaviour][:name]
- self[:behaviour][:name] = "#{superclass_metadata[:behaviour][:name]} #{self[:behaviour][:description]}".strip
+ if superclass_metadata && superclass_metadata[:example_group][:name]
+ self[:example_group][:name] = "#{superclass_metadata[:example_group][:name]} #{self[:example_group][:description]}".strip
else
- self[:behaviour][:name] = "#{self[:behaviour][:describes]} #{self[:behaviour][:description]}".strip
+ self[:example_group][:name] = "#{self[:example_group][:describes]} #{self[:example_group][:description]}".strip
end
end
View
@@ -42,8 +42,8 @@ def run(args = [])
formatter.start(total_examples_to_run) # start the clock
start = Time.now
- Rspec::Core.world.behaviours_to_run.each do |behaviour|
- suite_success &= behaviour.run(formatter)
+ Rspec::Core.world.example_groups_to_run.each do |example_group|
+ suite_success &= example_group.run(formatter)
end
formatter.start_dump(Time.now - start)
Oops, something went wrong.

0 comments on commit 6b1ff00

Please sign in to comment.