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

Commit 41aced6

Browse files
committed
When filtering, do not consider declaration lines from other files.
Before this, our logic for line number filtering asked `RSpec.world` for the preceding declaration line of a particular line number, *without* passing it a file name, which meant that it looked at the declaration line numbers from _all_ files. This was prone to producing weird filtering behavior. Fixes #2136.
1 parent d55841c commit 41aced6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/rspec/core/world.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ def descending_declaration_line_numbers_by_file
186186
declaration_locations = FlatMap.flat_map(example_groups, &:declaration_locations)
187187
hash_of_arrays = Hash.new { |h, k| h[k] = [] }
188188

189-
line_nums_by_file = declaration_locations.each_with_object(hash_of_arrays) do |(file_name, line_number), hash|
189+
# TODO: change `inject` to `each_with_object` when we drop 1.8.7 support.
190+
line_nums_by_file = declaration_locations.inject(hash_of_arrays) do |hash, (file_name, line_number)|
190191
hash[file_name] << line_number
192+
hash
191193
end
192194

193195
line_nums_by_file.each_value do |list|

0 commit comments

Comments
 (0)