From 761a43b3f9f5e908bee0ff64ed33d517ca32a5ae Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 12 May 2024 01:11:31 +0000 Subject: [PATCH] Fix coverage --- lib/mutant/config.rb | 11 +++++------ lib/mutant/expression/parser.rb | 9 ++++----- lib/mutant/integration/rspec.rb | 3 ++- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/mutant/config.rb b/lib/mutant/config.rb index fffdd8416..35914d66c 100644 --- a/lib/mutant/config.rb +++ b/lib/mutant/config.rb @@ -111,14 +111,13 @@ def self.load(cli_config:, world:) # # @return [Either] def self.load_config_file(reporter:, world:) - files = CANDIDATES - .map(&world.pathname.public_method(:new)) - .select(&:readable?) + files = CANDIDATES.map(&world.pathname.public_method(:new)).select(&:readable?) - if files.one? - load_contents(reporter: reporter, path: files.first).fmap(&DEFAULT.public_method(:with)) - elsif files.empty? + case files + in [] Either::Right.new(DEFAULT) + in [file] + load_contents(reporter: reporter, path: file).fmap(&DEFAULT.public_method(:with)) else Either::Left.new(MORE_THAN_ONE_CONFIG_FILE % files.join(', ')) end diff --git a/lib/mutant/expression/parser.rb b/lib/mutant/expression/parser.rb index bceae1555..366caa314 100644 --- a/lib/mutant/expression/parser.rb +++ b/lib/mutant/expression/parser.rb @@ -15,12 +15,11 @@ class Parser # @return [nil] # otherwise def call(input) - expressions = expressions(input) - case expressions.length - when 0 + case expressions(input) + in [] Either::Left.new("Expression: #{input.inspect} is invalid") - when 1 - Either::Right.new(expressions.first) + in [expression] + Either::Right.new(expression) else Either::Left.new("Expression: #{input.inspect} is ambiguous") end diff --git a/lib/mutant/integration/rspec.rb b/lib/mutant/integration/rspec.rb index 073a8f58f..b32fe114e 100644 --- a/lib/mutant/integration/rspec.rb +++ b/lib/mutant/integration/rspec.rb @@ -157,6 +157,7 @@ def example_group_map end memoize :example_group_map + # mutant:disable -- 3.3 specific mutation on match.captures -> match def parse_metadata(metadata) if metadata.key?(:mutant_expression) expression = metadata.fetch(:mutant_expression) @@ -167,7 +168,7 @@ def parse_metadata(metadata) expressions.map(&method(:parse_expression)) else match = EXPRESSION_CANDIDATE.match(metadata.fetch(:full_description)) - [parse_expression(match.captures.first) { ALL_EXPRESSION }] + [parse_expression(Util.one(match.captures)) { ALL_EXPRESSION }] end end