Skip to content

Commit c798777

Browse files
authored
Merge pull request #1955 from shanecav84/patch-1
Substitute quotes with underscores for method name
2 parents 38721b7 + 30c4a57 commit c798777

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/rspec/rails/example/system_example_group.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ module SystemExampleGroup
1111
include ActionDispatch::Assertions
1212
include ActionController::TemplateAssertions
1313

14+
# Special characters to translate into underscores for #method_name
15+
CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze
16+
1417
# @private
1518
module BlowAwayAfterTeardownHook
1619
# @private
@@ -35,7 +38,7 @@ def method_name
3538
self.class.name.underscore,
3639
RSpec.current_example.description.underscore,
3740
rand(1000)
38-
].join("_").gsub(/[\/\.:, ]/, "_")
41+
].join("_").tr(CHARS_TO_TRANSLATE.join, "_")
3942
end
4043

4144
# Delegates to `Rails.application`.

spec/rspec/rails/example/system_example_group_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ module RSpec::Rails
44
RSpec.describe SystemExampleGroup do
55
it_behaves_like "an rspec-rails example group mixin", :system,
66
'./spec/system/', '.\\spec\\system\\'
7+
8+
describe '#method_name' do
9+
it 'converts special characters to underscores' do
10+
group = RSpec::Core::ExampleGroup.describe ActionPack do
11+
include SystemExampleGroup
12+
end
13+
SystemExampleGroup::CHARS_TO_TRANSLATE.each do |char|
14+
example = group.new
15+
example_class_mock = double('name' => "method#{char}name")
16+
allow(example).to receive(:class).and_return(example_class_mock)
17+
expect(example.send(:method_name)).to start_with('method_name')
18+
end
19+
end
20+
end
721
end
822
end
923
end

0 commit comments

Comments
 (0)