debian-mirror-gitlab/rubocop/spec_helpers.rb

24 lines
761 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
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
2018-05-09 12:01:36 +05:30
!SPEC_HELPERS.include?(File.basename(path)) &&
path.start_with?(File.join(Dir.pwd, 'spec'), File.join(Dir.pwd, 'ee', 'spec'))
end
# 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) &&
path.start_with?(
File.join(Dir.pwd, 'spec', 'migrations'),
File.join(Dir.pwd, 'ee', 'spec', 'migrations'))
2018-03-17 18:26:18 +05:30
end
end
end