From 863a72258b9ada36dc9b16b7e1f6e7e172e9189d Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 23 Nov 2020 13:37:12 +0900 Subject: [PATCH] Consider the multibyte value in the method name of system test `String#[]` returns a value that considers multibyte value. But some file systems use byte for maximum filename length. So if applications use that file system and multibyte value to a method name, currently check doesn't work expected. This PR fixes to use `String#byteslice` instead of `String#[]`. Also, added `String#scrub` to avoid generating an invalid byte sequence. --- lib/rspec/rails/example/system_example_group.rb | 2 +- spec/rspec/rails/example/system_example_group_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rspec/rails/example/system_example_group.rb b/lib/rspec/rails/example/system_example_group.rb index 59c5606cca..e0f395bce0 100644 --- a/lib/rspec/rails/example/system_example_group.rb +++ b/lib/rspec/rails/example/system_example_group.rb @@ -41,7 +41,7 @@ def method_name @method_name ||= [ self.class.name.underscore, RSpec.current_example.description.underscore - ].join("_").tr(CHARS_TO_TRANSLATE.join, "_")[0...200] + "_#{rand(1000)}" + ].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}" end # Delegates to `Rails.application`. diff --git a/spec/rspec/rails/example/system_example_group_spec.rb b/spec/rspec/rails/example/system_example_group_spec.rb index 862f8cdda2..889ac818e1 100644 --- a/spec/rspec/rails/example/system_example_group_spec.rb +++ b/spec/rspec/rails/example/system_example_group_spec.rb @@ -16,6 +16,15 @@ module RSpec::Rails expect(example.send(:method_name)).to start_with('method_name') end end + + it "slices long method name - #{'あ'*100}" do + group = RSpec::Core::ExampleGroup.describe do + include SystemExampleGroup + end + example = group.new + group.hooks.run(:before, :example, example) + expect(example.send(:method_name).bytesize).to be <= 210 + end end describe '#driver' do