Skip to content

Commit

Permalink
Merge pull request #2487 from rspec/fix-method-name-truncation-for-mu…
Browse files Browse the repository at this point in the history
…ltibyte-strings

Fix method name truncation for multibyte strings (redux)
  • Loading branch information
JonRowe committed Mar 17, 2021
1 parent 1195037 commit 3e9cbea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Changelog.md
@@ -1,3 +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

0 comments on commit 3e9cbea

Please sign in to comment.