Skip to content

Commit 863a722

Browse files
committed
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.
1 parent 934276b commit 863a722

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/rspec/rails/example/system_example_group.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def method_name
4141
@method_name ||= [
4242
self.class.name.underscore,
4343
RSpec.current_example.description.underscore
44-
].join("_").tr(CHARS_TO_TRANSLATE.join, "_")[0...200] + "_#{rand(1000)}"
44+
].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}"
4545
end
4646

4747
# Delegates to `Rails.application`.

spec/rspec/rails/example/system_example_group_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ module RSpec::Rails
1616
expect(example.send(:method_name)).to start_with('method_name')
1717
end
1818
end
19+
20+
it "slices long method name - #{'あ'*100}" do
21+
group = RSpec::Core::ExampleGroup.describe do
22+
include SystemExampleGroup
23+
end
24+
example = group.new
25+
group.hooks.run(:before, :example, example)
26+
expect(example.send(:method_name).bytesize).to be <= 210
27+
end
1928
end
2029

2130
describe '#driver' do

0 commit comments

Comments
 (0)