-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathlint_env_spec.rb
50 lines (42 loc) · 1.41 KB
/
lint_env_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require "spec_helper"
require "common/rubocop/cop/lint_env"
describe RuboCop::Cop::Lint::Env, :config do
subject(:cop) { described_class.new(config) }
it "rejects ENV usage" do
inspect_source("a = ENV['x']")
expect(cop.offenses.size).to eq(1)
expect(cop.messages.first).to include("Avoid direct usage of ENV in application code")
end
it "rejects ::ENV usage" do
inspect_source("a = ::ENV['x']")
expect(cop.offenses.size).to eq(1)
expect(cop.messages.first).to include("Avoid direct usage of ENV in application code")
end
it "rejects Rails.env usage" do
inspect_source("a = Rails.env.production?")
expect(cop.offenses.size).to eq(1)
expect(cop.messages.first).to include("Avoid direct usage of Rails.env in application code")
end
it "reject Rails.env with condition" do
inspect_source(<<~SOURCE
if Rails.env.production?
true
end
SOURCE
)
expect(cop.offenses.size).to eq(1)
expect(cop.messages.first).to include("Avoid direct usage of Rails.env in application code")
end
it "accepts nested constant" do
inspect_source("a = Custom::ENV")
expect(cop.offenses).to be_empty
end
it "accepts nested constant with dot" do
inspect_source("a = Custom.ENV")
expect(cop.offenses).to be_empty
end
it "accepts other Rails.x methods" do
inspect_source("a = Rails.envy")
expect(cop.offenses).to be_empty
end
end