58 lines
2.3 KiB
Diff
58 lines
2.3 KiB
Diff
|
|
From b2f4a683f163cfbb663595464caed99a09f16bd1 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Jon Rowe <hello@jonrowe.co.uk>
|
||
|
|
Date: Thu, 26 Dec 2019 19:58:59 +0000
|
||
|
|
Subject: [PATCH] Make usage of keyword arguments for String#encode explicit to
|
||
|
|
avoid warning on 2.7.0
|
||
|
|
|
||
|
|
---
|
||
|
|
lib/rspec/support/encoded_string.rb | 33 +++++++++++++++++++++++++++--
|
||
|
|
1 file changed, 31 insertions(+), 2 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/lib/rspec/support/encoded_string.rb b/lib/rspec/support/encoded_string.rb
|
||
|
|
index a6ca0cb6..66f75ca1 100644
|
||
|
|
--- a/lib/rspec/support/encoded_string.rb
|
||
|
|
+++ b/lib/rspec/support/encoded_string.rb
|
||
|
|
@@ -112,11 +112,40 @@ def matching_encoding(string)
|
||
|
|
string = remove_invalid_bytes(string)
|
||
|
|
string.encode(@encoding)
|
||
|
|
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
|
||
|
|
- string.encode(@encoding, ENCODE_UNCONVERTABLE_BYTES)
|
||
|
|
+ encode_unconvertable_bytes(string)
|
||
|
|
rescue Encoding::ConverterNotFoundError
|
||
|
|
- string.dup.force_encoding(@encoding).encode(ENCODE_NO_CONVERTER)
|
||
|
|
+ encode_no_converter(string.dup.force_encoding(@encoding))
|
||
|
|
end
|
||
|
|
|
||
|
|
+ private
|
||
|
|
+
|
||
|
|
+ # On Ruby 2.7.0 keyword arguments mixed with conventional cause a warning to
|
||
|
|
+ # be issued requiring us to be explicit by using a ** to pass the hash as
|
||
|
|
+ # keyword arguments. Any keyword argument supporting Ruby supports this.
|
||
|
|
+ if RubyFeatures.kw_args_supported?
|
||
|
|
+ # Note on non keyword supporting Ruby ** causes a syntax error hence
|
||
|
|
+ # we must use eval. To be removed in RSpec 4.
|
||
|
|
+ binding.eval(<<-CODE, __FILE__, __LINE__)
|
||
|
|
+ def encode_unconvertable_bytes(string)
|
||
|
|
+ string.encode(@encoding, **ENCODE_UNCONVERTABLE_BYTES)
|
||
|
|
+ end
|
||
|
|
+
|
||
|
|
+ def encode_no_converter(string)
|
||
|
|
+ string.encode(**ENCODE_NO_CONVERTER)
|
||
|
|
+ end
|
||
|
|
+ CODE
|
||
|
|
+ else
|
||
|
|
+ def encode_unconvertable_bytes(string)
|
||
|
|
+ string.encode(@encoding, ENCODE_UNCONVERTABLE_BYTES)
|
||
|
|
+ end
|
||
|
|
+
|
||
|
|
+ def encode_no_converter(string)
|
||
|
|
+ string.encode(ENCODE_NO_CONVERTER)
|
||
|
|
+ end
|
||
|
|
+ end
|
||
|
|
+
|
||
|
|
+ public
|
||
|
|
+
|
||
|
|
# Prevents raising ArgumentError
|
||
|
|
if String.method_defined?(:scrub)
|
||
|
|
# https://github.com/ruby/ruby/blob/eeb05e8c11/doc/NEWS-2.1.0#L120-L123
|