Browse files

Configuration#inclusion_filter and #exclusion_filter guarantee non-nil

- Fixes #376.
  • Loading branch information...
1 parent e687d01 commit b06c1d5396989e407464cc1b5589e728123c261b @dchelimsky dchelimsky committed May 18, 2011
Showing with 28 additions and 8 deletions.
  1. +8 −1 lib/rspec/core/configuration.rb
  2. +7 −7 lib/rspec/core/world.rb
  3. +13 −0 spec/rspec/core/configuration_spec.rb
View
9 lib/rspec/core/configuration.rb
@@ -349,10 +349,17 @@ def exclusion_filter=(filter)
settings[:exclusion_filter] = filter
end
+ def exclusion_filter
+ settings[:exclusion_filter] || {}
+ end
+
def inclusion_filter=(filter)
settings[:inclusion_filter] = filter
end
+ def inclusion_filter
+ settings[:inclusion_filter] || {}
+ end
def filter_run_including(*args)
force_overwrite = if args.last.is_a?(Hash) || args.last.is_a?(Symbol)
false
@@ -362,7 +369,7 @@ def filter_run_including(*args)
options = build_metadata_hash_from(args)
- if inclusion_filter and inclusion_filter[:line_number] || inclusion_filter[:full_description]
+ if inclusion_filter[:line_number] || inclusion_filter[:full_description]
warn "Filtering by #{options.inspect} is not possible since " \
"you are already filtering by #{inclusion_filter.inspect}"
else
View
14 lib/rspec/core/world.rb
@@ -34,8 +34,8 @@ def initialize(configuration=RSpec.configuration)
@filtered_examples = Hash.new { |hash,group|
hash[group] = begin
examples = group.examples.dup
- examples = apply_exclusion_filters(examples, exclusion_filter) if exclusion_filter
- examples = apply_inclusion_filters(examples, inclusion_filter) if inclusion_filter
+ examples = apply_exclusion_filters(examples, exclusion_filter)
+ examples = apply_inclusion_filters(examples, inclusion_filter)
examples.uniq
end
}
@@ -106,13 +106,13 @@ def announce_filters
example_groups.clear
if filter_announcements.empty?
reporter.message("No examples found.")
- elsif inclusion_filter
+ elsif !inclusion_filter.empty?
message = "No examples matched #{inclusion_filter.description}."
if @configuration.run_all_when_everything_filtered?
message << " Running all."
end
reporter.message(message)
- elsif exclusion_filter
+ elsif !exclusion_filter.empty?
reporter.message(
"No examples were matched. Perhaps #{exclusion_filter.description} is excluding everything?")
end
@@ -122,7 +122,7 @@ def announce_filters
end
def announce_inclusion_filter(announcements)
- if inclusion_filter
+ unless inclusion_filter.empty?
announcements << "including #{inclusion_filter.description}"
end
end
@@ -139,8 +139,8 @@ def find_hook(hook, scope, group, example = nil)
private
- def apply?(predicate, conditions)
- lambda {|example| example.metadata.apply?(predicate, conditions)}
+ def apply?(predicate, filter)
+ lambda {|example| filter.empty? || example.metadata.apply?(predicate, filter)}
end
def declaration_line_numbers
View
13 spec/rspec/core/configuration_spec.rb
@@ -527,7 +527,20 @@ def metadata_hash(*args)
end
end
+ describe "#inclusion_filter" do
+ it "returns {} even if set to nil" do
+ config.inclusion_filter = nil
+ config.inclusion_filter.should eq({})
+ end
+ end
+
+
describe "#exclusion_filter" do
+ it "returns {} even if set to nil" do
+ config.exclusion_filter = nil
+ config.exclusion_filter.should eq({})
+ end
+
describe "the default :if filter" do
it "does not exclude a spec with no :if metadata" do
config.exclusion_filter[:if].call(nil, {}).should be_false

0 comments on commit b06c1d5

Please sign in to comment.