Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't process filters when the metadata doesn't even have the key.

This allows us to simplify the filter_applies? method on metadata, and
gives us a small performance boost by not evaluating procs that would
always return false.

- See #556.
  • Loading branch information...
commit 14798e141ad5538385278908a309f96bc5e2a453 1 parent 5686c13
@dchelimsky dchelimsky authored
View
2  lib/rspec/core/filter_manager.rb
@@ -67,7 +67,7 @@ module Core
# @see Configuration#filter_run_excluding
class FilterManager
DEFAULT_EXCLUSIONS = {
- :if => lambda { |value, metadata| metadata.has_key?(:if) && !value },
+ :if => lambda { |value| !value },
:unless => lambda { |value| value }
}
View
14 lib/rspec/core/metadata.rb
@@ -174,21 +174,13 @@ def filter_applies?(key, value, metadata=self)
return metadata.location_filter_applies?(value) if key == :locations
return metadata.filters_apply?(key, value) if Hash === value
+ return false unless metadata.has_key?(key)
+
case value
when Regexp
metadata[key] =~ value
when Proc
- if value.arity == 2
- # Pass the metadata hash to allow the proc to check if it even has the key.
- # This is necessary for the implicit :if exclusion filter:
- # { } # => run the example
- # { :if => nil } # => exclude the example
- # The value of metadata[:if] is the same in these two cases but
- # they need to be treated differently.
- value.call(metadata[key], metadata)
- else
- value.call(metadata[key])
- end
+ value.call(metadata[key])
else
metadata[key].to_s == value.to_s
end
View
16 spec/rspec/core/configuration_spec.rb
@@ -713,20 +713,16 @@ def metadata_hash(*args)
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
+ it "does not exclude a spec with { :if => true } metadata" do
+ config.exclusion_filter[:if].call(true).should be_false
end
- it "does not exclude a spec with { :if => true } metadata" do
- config.exclusion_filter[:if].call(true, {:if => true}).should be_false
+ it "excludes a spec with { :if => false } metadata" do
+ config.exclusion_filter[:if].call(false).should be_true
end
- it "excludes a spec with { :if => false } metadata" do
- config.exclusion_filter[:if].call(false, {:if => false}).should be_true
- end
-
- it "excludes a spec with { :if => nil } metadata" do
- config.exclusion_filter[:if].call(false, {:if => nil}).should be_true
+ it "excludes a spec with { :if => nil } metadata" do
+ config.exclusion_filter[:if].call(nil).should be_true
end
end
View
6 spec/rspec/core/metadata_spec.rb
@@ -126,12 +126,6 @@ module Core
example_metadata.filter_applies?(:if, lambda { |v| !v }).should be_false
end
- it "passes the metadata hash as the second argument if a given proc expects 2 args" do
- passed_metadata = nil
- example_metadata.filter_applies?(:if, lambda { |v, m| passed_metadata = m })
- passed_metadata.should eq(example_metadata)
- end
-
context "with an Array" do
let(:metadata_with_array) {
group_metadata.for_example('example_with_array', :tag => [:one, 2, 'three', /four/])
Please sign in to comment.
Something went wrong with that request. Please try again.