debian-mirror-gitlab/rubocop/spec_helpers.rb

31 lines
1,023 B
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
module RuboCop
module SpecHelpers
2018-10-15 14:42:47 +05:30
SPEC_HELPERS = %w[fast_spec_helper.rb rails_helper.rb spec_helper.rb].freeze
2019-03-02 22:35:43 +05:30
MIGRATION_SPEC_DIRECTORIES = ['spec/migrations', 'spec/lib/gitlab/background_migration'].freeze
2018-03-17 18:26:18 +05:30
# Returns true if the given node originated from the spec directory.
def in_spec?(node)
path = node.location.expression.source_buffer.name
2019-07-31 22:56:46 +05:30
pwd = RuboCop::PathUtil.pwd
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
!SPEC_HELPERS.include?(File.basename(path)) &&
2019-07-31 22:56:46 +05:30
path.start_with?(File.join(pwd, 'spec'), File.join(pwd, 'ee', 'spec'))
2018-05-09 12:01:36 +05:30
end
2019-03-02 22:35:43 +05:30
def migration_directories
@migration_directories ||= MIGRATION_SPEC_DIRECTORIES.map do |dir|
2019-07-31 22:56:46 +05:30
pwd = RuboCop::PathUtil.pwd
[File.join(pwd, dir), File.join(pwd, 'ee', dir)]
2019-03-02 22:35:43 +05:30
end.flatten
end
2018-05-09 12:01:36 +05:30
# Returns true if the given node originated from a migration spec.
def in_migration_spec?(node)
path = node.location.expression.source_buffer.name
in_spec?(node) &&
2019-03-02 22:35:43 +05:30
path.start_with?(*migration_directories)
2018-03-17 18:26:18 +05:30
end
end
end