Permalink
Browse files

Revert "refactoring: clarify intent of applying filters"

- it was more expressive, but caused errors in rspec-rails - will
  revisit later

This reverts commit 9d61d59.
  • Loading branch information...
1 parent 17782b0 commit 58926bb767a7b4ee77d7e9c8772d3464d841479d @dchelimsky dchelimsky committed May 12, 2011
View
@@ -1,7 +1,6 @@
-require 'rspec/core/applicable'
+require 'rspec/core/extensions'
require 'rspec/core/load_path'
require 'rspec/core/deprecation'
-require 'rspec/core/extensions'
require 'rspec/core/backward_compatibility'
require 'rspec/core/reporter'
@@ -26,14 +25,18 @@
require 'rspec/core/example_group'
require 'rspec/core/version'
require 'rspec/core/errors'
-require 'rspec/core/backward_compatibility'
-require 'rspec/monkey'
module RSpec
autoload :Matchers, 'rspec/matchers'
SharedContext = Core::SharedContext
+ module Core
+ def self.install_directory
+ @install_directory ||= File.expand_path(File.dirname(__FILE__))
+ end
+ end
+
def self.wants_to_quit
world.wants_to_quit
end
@@ -86,3 +89,6 @@ def self.warn_about_deprecated_configure
NOTICE
end
end
+
+require 'rspec/core/backward_compatibility'
+require 'rspec/monkey'
@@ -1,9 +0,0 @@
-module RSpec
- module Core
- module Applicable
- def apply_to?(target)
- target.apply?
- end
- end
- end
-end
@@ -5,7 +5,6 @@ module RSpec
module Core
class Configuration
include RSpec::Core::Hooks
- include RSpec::Core::Applicable
def self.add_setting(name, opts={})
if opts[:alias]
@@ -394,7 +393,7 @@ def extend(mod, *args)
def configure_group(group)
include_or_extend_modules.each do |include_or_extend, mod, filters|
- next unless filters.empty? || filters.any?(&apply_to?(group))
+ next unless filters.empty? || group.apply?(:any?, filters)
group.send(include_or_extend, mod)
end
end
@@ -27,8 +27,9 @@ def around_hooks
@around_hooks ||= example_group.around_hooks_for(self)
end
- def apply?
- @metadata.apply?
+ def apply?(predicate, filters)
+ @metadata.apply?(predicate, filters) ||
+ @example_group_class.apply?(predicate, filters)
end
alias_method :pending?, :pending
@@ -297,8 +297,8 @@ def self.run_examples(reporter)
end.all?
end
- def self.apply?
- @metadata.apply?
+ def self.apply?(predicate, filters)
+ metadata.apply?(predicate, filters)
end
def self.declaration_line_numbers
@@ -3,7 +3,9 @@
module RSpec
module Core
module ExpectationFrameworkAdapter
+
include RSpec::Matchers
+
end
end
end
View
@@ -4,8 +4,6 @@ module Hooks
include MetadataHashBuilder::WithConfigWarning
class Hook
- include RSpec::Core::Applicable
-
attr_reader :options
def initialize(options, &block)
@@ -14,8 +12,8 @@ def initialize(options, &block)
@block = block
end
- def with_conditions_applicable_to?(example_or_group)
- !example_or_group || options.all?(&apply_to?(example_or_group))
+ def options_apply?(example_or_group)
+ !example_or_group || example_or_group.apply?(:all?, options)
end
def to_proc
@@ -57,12 +55,12 @@ def call(wrapped_example)
end
class HookCollection < Array
- def with_conditions_applicable_to(example_or_group)
- self.class.new(select {|hook| hook.with_conditions_applicable_to?(example_or_group)})
+ def find_hooks_for(example_or_group)
+ self.class.new(select {|hook| hook.options_apply?(example_or_group)})
end
- def without_conditions_applicable_to(example_or_group)
- self.class.new(reject {|hook| hook.with_conditions_applicable_to?(example_or_group)})
+ def without_hooks_for(example_or_group)
+ self.class.new(reject {|hook| hook.options_apply?(example_or_group)})
end
end
@@ -128,13 +126,13 @@ def run_hook_filtered(hook, scope, group, example_group_instance, example = nil)
end
def find_hook(hook, scope, example_group_class, example = nil)
- found_hooks = hooks[hook][scope].with_conditions_applicable_to(example || example_group_class)
+ found_hooks = hooks[hook][scope].find_hooks_for(example || example_group_class)
# ensure we don't re-run :all hooks that were applied to any of the parent groups
if scope == :all
super_klass = example_group_class.superclass
while super_klass != RSpec::Core::ExampleGroup
- found_hooks = found_hooks.without_conditions_applicable_to(super_klass)
+ found_hooks = found_hooks.without_hooks_for(super_klass)
super_klass = super_klass.superclass
end
end
View
@@ -102,6 +102,12 @@ def configure_for_example(description, user_metadata)
update(user_metadata)
end
+ def apply?(predicate, filters)
+ filters.send(predicate) do |key, value|
+ apply_condition(key, value)
+ end
+ end
+
def relevant_line_numbers(metadata)
line_numbers = [metadata[:line_number]]
if metadata[:example_group]
@@ -111,10 +117,6 @@ def relevant_line_numbers(metadata)
end
end
- def apply?
- @apply ||= proc {|key, value| apply_condition(key, value)}
- end
-
def apply_condition(key, value, metadata=self)
case value
when Hash
@@ -1,9 +1,11 @@
module RSpec
module Core
module MockFrameworkAdapter
+
def setup_mocks_for_rspec; end
def verify_mocks_for_rspec; end
def teardown_mocks_for_rspec; end
+
end
end
end
@@ -12,15 +12,12 @@ module MockFrameworkAdapter
def self.framework_name; :flexmock end
include FlexMock::MockContainer
-
def setup_mocks_for_rspec
# No setup required
end
-
def verify_mocks_for_rspec
flexmock_verify
end
-
def teardown_mocks_for_rspec
flexmock_close
end
View
@@ -24,7 +24,6 @@ def empty?
end
include RSpec::Core::Hooks
- include RSpec::Core::Applicable
attr_reader :example_groups, :filtered_examples, :wants_to_quit
attr_writer :wants_to_quit
@@ -72,13 +71,13 @@ def example_count
end
def apply_inclusion_filters(examples, conditions={})
- examples.select {|example| conditions.any?(&apply_to?(example))}
+ examples.select(&apply?(:any?, conditions))
end
alias_method :find, :apply_inclusion_filters
def apply_exclusion_filters(examples, conditions={})
- examples.reject {|example| conditions.any?(&apply_to?(example))}
+ examples.reject(&apply?(:any?, conditions))
end
def preceding_declaration_line(filter_line)
@@ -140,6 +139,10 @@ def find_hook(hook, scope, group, example = nil)
private
+ def apply?(predicate, conditions)
+ lambda {|example| example.metadata.apply?(predicate, conditions)}
+ end
+
def declaration_line_numbers
@line_numbers ||= example_groups.inject([]) do |lines, g|
lines + g.declaration_line_numbers

0 comments on commit 58926bb

Please sign in to comment.