From 9fb6fef21a2305eeb77d74b545429d95ab744aec 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 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. --- features/system_specs/system_specs.feature | 26 +++++++++++++++++++ .../rails/example/system_example_group.rb | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/features/system_specs/system_specs.feature b/features/system_specs/system_specs.feature index 2ef93f6e54..73167fb20c 100644 --- a/features/system_specs/system_specs.feature +++ b/features/system_specs/system_specs.feature @@ -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]" 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`.