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

Commit d24df62

Browse files
committed
Move the symbol arguments check in has_kw_args_in?
1 parent 778f143 commit d24df62

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/rspec/support/method_signature_verifier.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@ def invalid_kw_args_from(given_kw_args)
7777
given_kw_args - @allowed_kw_args
7878
end
7979

80+
# If the last argument is Hash, Ruby will treat only symbol keys as keyword arguments
81+
# the rest will be grouped in another Hash and passed as positional argument.
8082
def has_kw_args_in?(args)
81-
Hash === args.last && could_contain_kw_args?(args)
83+
Hash === args.last &&
84+
could_contain_kw_args?(args) &&
85+
args.last.keys.any? { |x| x.is_a?(Symbol) }
8286
end
8387

8488
# Without considering what the last arg is, could it
8589
# contain keyword arguments?
8690
def could_contain_kw_args?(args)
8791
return false if args.count <= min_non_kw_args
88-
return false if args.count <= max_non_kw_args &&
89-
Hash === args.last &&
90-
args.last.keys.none? { |x| x.is_a?(Symbol) }
9192

9293
@allows_any_kw_args || @allowed_kw_args.any?
9394
end

0 commit comments

Comments
 (0)