Skip to content

Commit

Permalink
Consider the multibyte value in the method name of system test
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
y-yagi committed Nov 24, 2020
1 parent 934276b commit 9fb6fef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions features/system_specs/system_specs.feature
Expand Up @@ -107,3 +107,29 @@ Feature: System spec
Then the output should contain "1 example, 0 failures"
And the output should not contain "starting Puma"
And the exit status should be 0

@system_test
Scenario: System specs can save screenshots if the method name is too long
Given a file named "spec/system/widget_system_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe "Widget management", :type => :system do
before do
driven_by(:selenium_chrome_headless)
end
it "long test name #{'あ'*100}" do
visit "/widgets/new"
fill_in "Name", :with => "My Widget"
click_button "Create Widget"
expect(page).to have_text("Widget was created.")
end
end
"""
When I run `rspec spec/system/widget_system_spec.rb`
Then the output should contain "1 example, 1 failure"
And the output should not contain "Errno::ENAMETOOLONG"
And the output should contain "[Screenshot]"
2 changes: 1 addition & 1 deletion lib/rspec/rails/example/system_example_group.rb
Expand Up @@ -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`.
Expand Down

0 comments on commit 9fb6fef

Please sign in to comment.