Skip to content

Commit

Permalink
Get rid of FlatMap
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Dec 13, 2020
1 parent 2d1e973 commit b477a27
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 27 deletions.
1 change: 0 additions & 1 deletion lib/rspec/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
warnings

set
flat_map
filter_manager
dsl
notifications
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2154,7 +2154,7 @@ def run_suite_hooks(hook_description, hooks)
end

def get_files_to_run(paths)
files = FlatMap.flat_map(paths_to_check(paths)) do |path|
files = paths_to_check(paths).flat_map do |path|
path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
File.directory?(path) ? gather_directories(path) : extract_location(path)
end.uniq
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/configuration_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def parse_args_ignoring_files_or_dirs_to_run(args, source)
def args_from_options_file(path)
return [] unless path && File.exist?(path)
config_string = options_file_as_erb_string(path)
FlatMap.flat_map(config_string.split(/\n+/), &:shellsplit)
config_string.split(/\n+/).flat_map(&:shellsplit)
end

def options_file_as_erb_string(path)
Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/core/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def self.filtered_examples
# @private
def self.descendant_filtered_examples
@descendant_filtered_examples ||= filtered_examples +
FlatMap.flat_map(children, &:descendant_filtered_examples)
children.flat_map(&:descendant_filtered_examples)
end

# @private
Expand Down Expand Up @@ -501,7 +501,7 @@ def self.next_runnable_index_for(file)

# @private
def self.descendants
@_descendants ||= [self] + FlatMap.flat_map(children, &:descendants)
@_descendants ||= [self] + children.flat_map(&:descendants)
end

## @private
Expand Down Expand Up @@ -646,7 +646,7 @@ def self.for_filtered_examples(reporter, &block)
def self.declaration_locations
@declaration_locations ||= [Metadata.location_tuple_from(metadata)] +
examples.map { |e| Metadata.location_tuple_from(e.metadata) } +
FlatMap.flat_map(children, &:declaration_locations)
children.flat_map(&:declaration_locations)
end

# @return [String] the unique id of this example group. Pass
Expand Down
12 changes: 0 additions & 12 deletions lib/rspec/core/flat_map.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/rspec/core/formatters/exception_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def sub_failure_list_formatter(exception, message_color)
common_backtrace_truncater = CommonBacktraceTruncater.new(exception)

lambda do |failure_number, colorizer|
FlatMap.flat_map(exception.all_exceptions.each_with_index) do |failure, index|
exception.all_exceptions.each_with_index.flat_map do |failure, index|
options = with_multiple_error_options_as_needed(
failure,
:description => nil,
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/formatters/snippet_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def line_range_of_expression
end

def unclosed_tokens_in_line_range(line_range)
tokens = FlatMap.flat_map(line_range) do |line_number|
tokens = line_range.flat_map do |line_number|
source.tokens_by_line_number[line_number]
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/core/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def process(host, parent_groups, globals, position, scope)
hooks_to_process = globals.processable_hooks_for(position, scope, host)
return if hooks_to_process.empty?

hooks_to_process -= FlatMap.flat_map(parent_groups) do |group|
hooks_to_process -= parent_groups.flat_map do |group|
group.hooks.all_hooks_for(position, scope)
end
return if hooks_to_process.empty?
Expand Down Expand Up @@ -609,7 +609,7 @@ def run_example_hooks_for(example, position, each_method)
end

def run_around_example_hooks_for(example)
hooks = FlatMap.flat_map(owner_parent_groups) do |group|
hooks = owner_parent_groups.flat_map do |group|
group.hooks.matching_hooks_for(:around, :example, example)
end

Expand Down
8 changes: 4 additions & 4 deletions lib/rspec/core/world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ def exclusion_filter
#
# Get count of examples to be run.
def example_count(groups=example_groups)
FlatMap.flat_map(groups) { |g| g.descendants }.
groups.flat_map { |g| g.descendants }.
inject(0) { |a, e| a + e.filtered_examples.size }
end

# @private
def all_example_groups
FlatMap.flat_map(example_groups) { |g| g.descendants }
example_groups.flat_map { |g| g.descendants }
end

# @private
def all_examples
FlatMap.flat_map(all_example_groups) { |g| g.examples }
all_example_groups.flat_map { |g| g.examples }
end

# @private
Expand Down Expand Up @@ -223,7 +223,7 @@ def announce_exclusion_filter(announcements)

def descending_declaration_line_numbers_by_file
@descending_declaration_line_numbers_by_file ||= begin
declaration_locations = FlatMap.flat_map(example_groups, &:declaration_locations)
declaration_locations = example_groups.flat_map(&:declaration_locations)

declarations_by_file = declaration_locations.group_by(&:first) # by file name

Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@ def exclude?(line)
registered_examples = nil

RSpec.configuration.define_derived_metadata(:ex) do |_meta|
registered_examples = FlatMap.flat_map(RSpec.world.all_example_groups, &:examples)
registered_examples = RSpec.world.all_example_groups.flat_map(&:examples)
end

example = nil
Expand Down

0 comments on commit b477a27

Please sign in to comment.