Skip to content

Commit 9fb6fef

Browse files
committed
Consider the multibyte value in the method name of system test
`String#[]` returns a value that considers multibyte value. But maximum filename length use bytes. So if applications use 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 9fb6fef

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

features/system_specs/system_specs.feature

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,29 @@ Feature: System spec
107107
Then the output should contain "1 example, 0 failures"
108108
And the output should not contain "starting Puma"
109109
And the exit status should be 0
110+
111+
@system_test
112+
Scenario: System specs can save screenshots if the method name is too long
113+
Given a file named "spec/system/widget_system_spec.rb" with:
114+
"""ruby
115+
require "rails_helper"
116+
117+
RSpec.describe "Widget management", :type => :system do
118+
before do
119+
driven_by(:selenium_chrome_headless)
120+
end
121+
122+
it "long test name #{'あ'*100}" do
123+
visit "/widgets/new"
124+
125+
fill_in "Name", :with => "My Widget"
126+
click_button "Create Widget"
127+
128+
expect(page).to have_text("Widget was created.")
129+
end
130+
end
131+
"""
132+
When I run `rspec spec/system/widget_system_spec.rb`
133+
Then the output should contain "1 example, 1 failure"
134+
And the output should not contain "Errno::ENAMETOOLONG"
135+
And the output should contain "[Screenshot]"

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`.

0 commit comments

Comments
 (0)