Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method name truncation for multibyte strings (redux) #2487

Merged
merged 3 commits into from Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changelog.md
@@ -1,6 +1,11 @@
### Development
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.0...main)

Bug Fixes:

* Limit multibyte example descriptions when used in system tests for #method_name
which ends up as screenshot names etc. (@y-yagi, #2405, #2487)

### 5.0.0 / 2021-03-09
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.1.1...v5.0.0)

Expand Down
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
12 changes: 12 additions & 0 deletions spec/rspec/rails/example/system_example_group_spec.rb
Expand Up @@ -15,6 +15,18 @@ module RSpec::Rails
expect(example.send(:method_name)).to start_with('method_name')
end
end

it "handles long method names which include unicode characters" do
group =
RSpec::Core::ExampleGroup.describe do
include SystemExampleGroup
end

example = group.new
allow(example.class).to receive(:name) { "really long unicode example name - #{'あ'*100}" }

expect(example.send(:method_name).bytesize).to be <= 210
end
end

describe '#driver' do
Expand Down