Skip to content

Commit

Permalink
Use :rerun_file_path when checking location filters
Browse files Browse the repository at this point in the history
Fixes #1961

The problem with using :absolute_file_path is that it doesn't function
correctly for shared examples in an external file. The filter manager thinks
that there are no location filters set, when actually there are. Since
MetadataFilter already handles location filtering correctly across multiple
nested examples / files, correcting the path that is checked is sufficient to
fix the line filtering issue.
  • Loading branch information
Ben Axnick committed May 18, 2015
1 parent 1a08928 commit b8319b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rspec/core/filter_manager.rb
Expand Up @@ -99,8 +99,10 @@ def prune_conditionally_filtered_examples(examples)
# defined in the same file as the location filters. Excluded specs in
# other files should still be excluded.
def file_scoped_include?(ex_metadata, ids, locations)
no_location_filters = locations[ex_metadata[:absolute_file_path]].empty?
no_id_filters = ids[ex_metadata[:rerun_file_path]].empty?
no_location_filters = locations[
File.expand_path(ex_metadata[:rerun_file_path])
].empty?

return yield if no_location_filters && no_id_filters

Expand Down
22 changes: 22 additions & 0 deletions spec/rspec/core/filter_manager_spec.rb
Expand Up @@ -159,6 +159,28 @@ def example_with(*args)
included_via_tag, excluded_via_tag
]).map(&:description)).to eq([included_via_loc_or_id, included_via_tag].map(&:description))
end

it "skips examples in external files when included from a #{type} filtered file" do
group = RSpec.describe("group")

included_via_loc_or_id = group.example("inc via #{type}"); line = __LINE__

# instantiate shared example in external file
instance_eval <<-EOS, "a_shared_example.rb", 1
RSpec.shared_examples_for("a shared example") do
example("inside of a shared example")
end
EOS

included_via_behaves_like = group.it_behaves_like("a shared example")
test_inside_a_shared_example = included_via_behaves_like.examples.first

add_filter(:line_number => line, :scoped_id => "1:1")

expect(prune([
included_via_loc_or_id, test_inside_a_shared_example
]).map(&:description)).to eq([included_via_loc_or_id].map(&:description))
end
end

describe "location filtering" do
Expand Down

0 comments on commit b8319b0

Please sign in to comment.