Skip to content

Substitute quotes with underscores for method name #1955

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

Merged
merged 4 commits into from
Feb 16, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/rspec/rails/example/system_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module SystemExampleGroup
include ActionDispatch::Assertions
include ActionController::TemplateAssertions

# Special characters to translate into underscores for #method_name
CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze

# @private
module BlowAwayAfterTeardownHook
# @private
Expand All @@ -35,7 +38,7 @@ def method_name
self.class.name.underscore,
RSpec.current_example.description.underscore,
rand(1000)
].join("_").gsub(/[\/\.:, ]/, "_")
].join("_").tr(CHARS_TO_TRANSLATE.join, "_")
end

# Delegates to `Rails.application`.
Expand Down
14 changes: 14 additions & 0 deletions spec/rspec/rails/example/system_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ module RSpec::Rails
RSpec.describe SystemExampleGroup do
it_behaves_like "an rspec-rails example group mixin", :system,
'./spec/system/', '.\\spec\\system\\'

describe '#method_name' do
it 'converts special characters to underscores' do
group = RSpec::Core::ExampleGroup.describe ActionPack do
include SystemExampleGroup
end
SystemExampleGroup::CHARS_TO_TRANSLATE.each do |char|
example = group.new
example_class_mock = double('name' => "method#{char}name")
allow(example).to receive(:class).and_return(example_class_mock)
expect(example.send(:method_name)).to start_with('method_name')
end
end
end
end
end
end