Permalink
Browse files

push apply_condition to metadata

  • Loading branch information...
1 parent 644e680 commit cdf4be2e4a6dd087bd9204a4f947531ac8806f18 @dchelimsky dchelimsky committed Feb 1, 2010
Showing with 42 additions and 39 deletions.
  1. +5 −5 lib/rspec/core/configuration.rb
  2. +4 −0 lib/rspec/core/example_group.rb
  3. +20 −0 lib/rspec/core/metadata.rb
  4. +13 −34 lib/rspec/core/world.rb
@@ -195,8 +195,8 @@ def extend(mod, options={})
end
def find_modules(group)
- include_or_extend_modules.select do |include_or_extend, mod, options|
- Rspec::Core.world.all_apply?(group, options)
+ include_or_extend_modules.select do |include_or_extend, mod, filters|
+ group.all_apply?(filters)
end
end
@@ -209,9 +209,9 @@ def after(each_or_all=:each, options={}, &block)
end
def find_advice(desired_advice_type, desired_each_or_all, group)
- advice[desired_advice_type][desired_each_or_all].select do |options, block|
- Rspec::Core.world.all_apply?(group, options)
- end.map { |options, block| block }
+ advice[desired_advice_type][desired_each_or_all].select do |filters, block|
+ group.all_apply?(filters)
+ end.map { |filters, block| block }
end
end
@@ -199,6 +199,10 @@ def self.let(name, &block)
end
end
+ def self.all_apply?(filters)
+ metadata.all_apply?(filters)
+ end
+
def assignments
@assignments ||= {}
end
@@ -53,6 +53,26 @@ def configure_for_example(description, options)
self
end
+ def apply_condition(filter_on, filter, metadata=nil)
+ metadata ||= self
+ case filter
+ when Hash
+ filter.all? { |k, v| apply_condition(k, v, metadata[filter_on]) }
+ when Regexp
+ metadata[filter_on] =~ filter
+ when Proc
+ filter.call(metadata[filter_on]) rescue false
+ else
+ metadata[filter_on] == filter
+ end
+ end
+
+ def all_apply?(filters)
+ filters.all? do |filter_on, filter|
+ apply_condition(filter_on, filter)
+ end
+ end
+
private
def file_path_from(hash, given_file_path=nil)
@@ -47,32 +47,20 @@ def total_examples_to_run
end
def filter_behaviours
- behaviours.inject([]) do |list_of_behaviors, _behavior|
- examples = _behavior.examples
+ behaviours.inject([]) do |list_of_example_groups, example_group|
+ examples = example_group.examples
examples = apply_exclusion_filters(examples, exclusion_filter) if exclusion_filter
examples = apply_inclusion_filters(examples, filter) if filter
examples.uniq!
- _behavior.examples_to_run.replace(examples)
+ example_group.examples_to_run.replace(examples)
if examples.empty?
- list_of_behaviors << nil
+ list_of_example_groups << nil
else
- list_of_behaviors << _behavior
+ list_of_example_groups << example_group
end
end.compact
end
- def find(collection, type_of_filter=:positive, conditions={})
- negative = type_of_filter != :positive
-
- collection.select do |item|
- # negative conditions.any?, positive conditions.all? ?????
- result = conditions.all? do |filter_on, filter|
- apply_condition(filter_on, filter, item.metadata)
- end
- negative ? !result : result
- end
- end
-
def apply_inclusion_filters(collection, conditions={})
find(collection, :positive, conditions)
end
@@ -81,24 +69,15 @@ def apply_exclusion_filters(collection, conditions={})
find(collection, :negative, conditions)
end
- def apply_condition(filter_on, filter, metadata)
- return false if metadata.nil?
-
- case filter
- when Hash
- filter.all? { |k, v| apply_condition(k, v, metadata[filter_on]) }
- when Regexp
- metadata[filter_on] =~ filter
- when Proc
- filter.call(metadata[filter_on]) rescue false
- else
- metadata[filter_on] == filter
- end
- end
+ def find(collection, type_of_filter=:positive, conditions={})
+ negative = type_of_filter != :positive
- def all_apply?(group, filters)
- filters.all? do |filter_on, filter|
- Rspec::Core.world.apply_condition(filter_on, filter, group.metadata)
+ collection.select do |item|
+ # negative conditions.any?, positive conditions.all? ?????
+ result = conditions.all? do |filter_on, filter|
+ item.metadata.apply_condition(filter_on, filter)
+ end
+ negative ? !result : result
end
end

0 comments on commit cdf4be2

Please sign in to comment.