Skip to content

Commit

Permalink
Fix metadata filter to not blow up on unmatched nested hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Mar 15, 2014
1 parent c8afb7c commit 999d2cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rspec/core/metadata_filter.rb
Expand Up @@ -67,7 +67,9 @@ def example_group_declaration_line(locations, metadata)
end

def filters_apply?(key, value, metadata)
value.all? { |k, v| filter_applies?(k, v, metadata[key]) }
subhash = metadata[key]
return false unless Hash === subhash
value.all? { |k, v| filter_applies?(k, v, subhash) }
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions spec/rspec/core/metadata_filter_spec.rb
Expand Up @@ -138,6 +138,27 @@ def filter_applies?(key, value, metadata)
}.to raise_error(ArgumentError)
end

context "with a nested hash" do
it 'matches when the nested entry matches' do
metadata = { :foo => { :bar => "words" } }
expect(filter_applies?(:foo, { :bar => /wor/ }, metadata)).to be_truthy
end

it 'does not match when the nested entry does not match' do
metadata = { :foo => { :bar => "words" } }
expect(filter_applies?(:foo, { :bar => /sword/ }, metadata)).to be_falsey
end

it 'does not match when the metadata lacks the key' do
expect(filter_applies?(:foo, { :bar => /sword/ }, {})).to be_falsey
end

it 'does not match when the metadata does not have a hash entry for the key' do
metadata = { :foo => "words" }
expect(filter_applies?(:foo, { :bar => /word/ }, metadata)).to be_falsey
end
end

context "with an Array" do
let(:metadata_with_array) do
meta = nil
Expand Down

0 comments on commit 999d2cc

Please sign in to comment.