Skip to content

Commit

Permalink
Compute file path with ActiveSupport Inflector if defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromedalbert committed Apr 23, 2022
1 parent 2f8ec8a commit cfb46fe
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/rubocop/cop/rspec/file_path.rb
Expand Up @@ -130,6 +130,13 @@ def expected_path(constant)
end

def camel_to_snake_case(string)
if defined?(ActiveSupport::Inflector)
if File.exist?('./config/initializers/inflections.rb')
require './config/initializers/inflections'
end
return ActiveSupport::Inflector.underscore(string)
end

string
.gsub(/([^A-Z])([A-Z]+)/, '\1_\2')
.gsub(/([A-Z])([A-Z][^A-Z\d]+)/, '\1_\2')
Expand Down

0 comments on commit cfb46fe

Please sign in to comment.