summaryrefslogtreecommitdiff
path: root/rubocop/spec_helpers.rb
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-10-11 13:25:40 +0200
committerRémy Coutable <remy@rymai.me>2017-10-18 18:42:09 +0200
commit8a31b0743753f080e0ba07c8d6d0da863a5c4726 (patch)
tree0a5d03d993597a3f68b4f233b4f7f1ebc0481fa2 /rubocop/spec_helpers.rb
parent4774b6cfd2095974df4267e4e4871b38b274a956 (diff)
downloadgitlab-ce-8a31b0743753f080e0ba07c8d6d0da863a5c4726.tar.gz
Add a new RSpec::EnvAssignment cop to prevent assigning to ENV in specs18765-stub_env_in_specs
Signed-off-by: Rémy Coutable <remy@rymai.me>
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