summaryrefslogtreecommitdiff
path: root/rubocop/spec_helpers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'rubocop/spec_helpers.rb')
-rw-r--r--rubocop/spec_helpers.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/rubocop/spec_helpers.rb b/rubocop/spec_helpers.rb
new file mode 100644
index 00000000000..a702a083958
--- /dev/null
+++ b/rubocop/spec_helpers.rb
@@ -0,0 +1,12 @@
+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