Skip to content

Commit

Permalink
adds private method Differ#run to get rid of PerceivedComplexity offense
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlHeitmann committed May 19, 2024
1 parent 8be1fd8 commit 47cf1b2
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lib/rspec/support/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,9 @@ module Support
# rubocop:disable Metrics/ClassLength
class Differ
def diff(actual, expected)
diff = ""

no_procs_no_numbers = lambda {|var1, var2| no_procs?(var1, var2) && no_numbers?(var1, var2)}

unless actual.nil? || expected.nil?
if all_strings?(actual, expected)
diff = diff_as_string(coerce_to_string(actual), coerce_to_string(expected)) if any_multiline_strings?(actual, expected)
elsif (keys = all_keys_from_hash(expected)) && keys.any?
diff = diff_as_object_with_anything(keys, actual, expected) if no_procs_no_numbers.call(actual, expected)
elsif no_procs_no_numbers.call(actual, expected)
diff = diff_as_object(actual, expected)
end
end
return "" if actual.nil? && expected.nil?

diff.to_s
run(actual, expected)
end

# rubocop:disable Metrics/MethodLength
Expand Down Expand Up @@ -88,6 +76,21 @@ def initialize(opts={})
end

private
def run(actual, expected)
diff = ""

no_procs_no_numbers = lambda {|var1, var2| no_procs?(var1, var2) && no_numbers?(var1, var2)}

if all_strings?(actual, expected)
diff = diff_as_string(coerce_to_string(actual), coerce_to_string(expected)) if any_multiline_strings?(actual, expected)
elsif (keys = all_keys_from_hash(expected)) && keys.any?
diff = diff_as_object_with_anything(keys, actual, expected) if no_procs_no_numbers.call(actual, expected)
elsif no_procs_no_numbers.call(actual, expected)
diff = diff_as_object(actual, expected)
end

diff.to_s
end

def all_keys_from_hash(arg)
return false unless Hash === arg
Expand Down

0 comments on commit 47cf1b2

Please sign in to comment.