Skip to content

Commit 3e9cbea

Browse files
committed
Merge pull request #2487 from rspec/fix-method-name-truncation-for-multibyte-strings
Fix method name truncation for multibyte strings (redux)
1 parent 1195037 commit 3e9cbea

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### Development
2+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.0...main)
3+
4+
Bug Fixes:
5+
6+
* Limit multibyte example descriptions when used in system tests for #method_name
7+
which ends up as screenshot names etc. (@y-yagi, #2405, #2487)
8+
19
### 5.0.0 / 2021-03-09
210
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.1.1...v5.0.0)
311

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

spec/rspec/rails/example/system_example_group_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ module RSpec::Rails
1515
expect(example.send(:method_name)).to start_with('method_name')
1616
end
1717
end
18+
19+
it "handles long method names which include unicode characters" do
20+
group =
21+
RSpec::Core::ExampleGroup.describe do
22+
include SystemExampleGroup
23+
end
24+
25+
example = group.new
26+
allow(example.class).to receive(:name) { "really long unicode example name - #{'あ'*100}" }
27+
28+
expect(example.send(:method_name).bytesize).to be <= 210
29+
end
1830
end
1931

2032
describe '#driver' do

0 commit comments

Comments
 (0)