Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Fix filtering based on :example_group to work for example groups. #2234

Merged
merged 1 commit into from
May 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Bug Fixes:
* Fix `--bisect` so it works on large spec suites that were previously triggering
"Argument list too long errors" due to all the spec locations being passed as
CLI args. (Matt Jones, #2223).
* Fix deprecated `:example_group`-based filtering so that it properly
applies to matching example groups. (Myron Marston, #2234)

### 3.5.0.beta1 / 2016-02-06
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.4.3...v3.5.0.beta1)
Expand Down
32 changes: 22 additions & 10 deletions lib/rspec/core/metadata_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def filter_applies?(key, value, metadata)
end
end

# @private
def silence_metadata_example_group_deprecations
RSpec::Support.thread_local_data[:silence_metadata_example_group_deprecations] = true
yield
ensure
RSpec::Support.thread_local_data.delete(:silence_metadata_example_group_deprecations)
end

private

def filter_applies_to_any_value?(key, value, metadata)
Expand Down Expand Up @@ -72,13 +80,6 @@ def filters_apply?(key, value, metadata)
return false unless Hash === subhash || HashImitatable === subhash
value.all? { |k, v| filter_applies?(k, v, subhash) }
end

def silence_metadata_example_group_deprecations
RSpec::Support.thread_local_data[:silence_metadata_example_group_deprecations] = true
yield
ensure
RSpec::Support.thread_local_data.delete(:silence_metadata_example_group_deprecations)
end
end
end

Expand Down Expand Up @@ -202,9 +203,20 @@ def handle_mutation(metadata)
end

def applicable_metadata_from(metadata)
@applicable_keys.inject({}) do |hash, key|
hash[key] = metadata[key] if metadata.key?(key)
hash
MetadataFilter.silence_metadata_example_group_deprecations do
@applicable_keys.inject({}) do |hash, key|
# :example_group is treated special here because...
# - In RSpec 2, example groups had an `:example_group` key
# - In RSpec 3, that key is deprecated (it was confusing!).
# - The key is not technically present in an example group metadata hash
# (and thus would fail the `metadata.key?(key)` check) but a value
# is provided when accessed via the hash's `default_proc`
# - Thus, for backwards compatibility, we have to explicitly check
# for `:example_group` here if it is one of the keys being used to
# filter.
hash[key] = metadata[key] if metadata.key?(key) || key == :example_group
hash
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,16 @@ def metadata_hash(*args)
expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
end

it "includes in example groups that match a deprecated `:example_group` filter" do
RSpec.configure do |c|
c.include(InstanceLevelMethods, :example_group => { :file_path => /./ })
end

group = RSpec.describe('does like, stuff and junk')
expect(group).not_to respond_to(:you_call_this_a_blt?)
expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
end

it "includes the given module into each existing matching example group" do
matching_group = RSpec.describe('does like, stuff and junk', :magic_key => :include) { }
non_matching_group = RSpec.describe
Expand Down