gitlab-org--gitlab-foss/rubocop/spec_helpers.rb
Rémy Coutable 8a31b07437 Add a new RSpec::EnvAssignment cop to prevent assigning to ENV in specs
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-10-18 18:42:09 +02:00

12 lines
368 B
Ruby

module RuboCop
module SpecHelpers
SPEC_HELPERS = %w[spec_helper.rb rails_helper.rb].freeze
# Returns true if the given node originated from the spec directory.
def in_spec?(node)
path = node.location.expression.source_buffer.name
!SPEC_HELPERS.include?(File.basename(path)) && path.start_with?(File.join(Dir.pwd, 'spec'))
end
end
end