Skip to content

Commit 49b1090

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 49b1090

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/rspec/rails/example/system_example_group.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ def passed?
3838

3939
# @private
4040
def method_name
41-
@method_name ||= [
42-
self.class.name.underscore,
43-
RSpec.current_example.description.underscore
44-
].join("_").tr(CHARS_TO_TRANSLATE.join, "_")[0...200] + "_#{rand(1000)}"
41+
@method_name ||= begin
42+
[
43+
self.class.name.underscore,
44+
RSpec.current_example.description.underscore
45+
].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}"
46+
end
4547
end
4648

4749
# 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)