rubocop-airbnb 4.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/config/default.yml +9 -8
  4. data/config/rubocop-performance.yml +3 -0
  5. data/config/rubocop-rails.yml +3 -0
  6. data/config/rubocop-rspec.yml +4 -9
  7. data/lib/rubocop/airbnb/version.rb +1 -1
  8. data/lib/rubocop/cop/airbnb/class_or_module_declared_in_wrong_file.rb +1 -1
  9. data/lib/rubocop/cop/airbnb/const_assigned_in_wrong_file.rb +1 -1
  10. data/lib/rubocop/cop/airbnb/continuation_slash.rb +1 -1
  11. data/lib/rubocop/cop/airbnb/default_scope.rb +1 -1
  12. data/lib/rubocop/cop/airbnb/factory_attr_references_class.rb +1 -1
  13. data/lib/rubocop/cop/airbnb/factory_class_use_string.rb +1 -1
  14. data/lib/rubocop/cop/airbnb/mass_assignment_accessible_modifier.rb +1 -1
  15. data/lib/rubocop/cop/airbnb/module_method_in_wrong_file.rb +1 -1
  16. data/lib/rubocop/cop/airbnb/no_timeout.rb +1 -1
  17. data/lib/rubocop/cop/airbnb/opt_arg_parameters.rb +1 -1
  18. data/lib/rubocop/cop/airbnb/phrase_bundle_keys.rb +1 -1
  19. data/lib/rubocop/cop/airbnb/risky_activerecord_invocation.rb +1 -1
  20. data/lib/rubocop/cop/airbnb/rspec_describe_or_context_under_namespace.rb +1 -1
  21. data/lib/rubocop/cop/airbnb/rspec_environment_modification.rb +1 -1
  22. data/lib/rubocop/cop/airbnb/simple_modifier_conditional.rb +1 -1
  23. data/lib/rubocop/cop/airbnb/simple_unless.rb +1 -1
  24. data/lib/rubocop/cop/airbnb/spec_constant_assignment.rb +3 -4
  25. data/lib/rubocop/cop/airbnb/unsafe_yaml_marshal.rb +1 -1
  26. data/rubocop-airbnb.gemspec +3 -3
  27. data/spec/rubocop/cop/airbnb/class_or_module_declared_in_wrong_file_spec.rb +69 -102
  28. data/spec/rubocop/cop/airbnb/const_assigned_in_wrong_file_spec.rb +58 -101
  29. data/spec/rubocop/cop/airbnb/continuation_slash_spec.rb +77 -112
  30. data/spec/rubocop/cop/airbnb/default_scope_spec.rb +24 -31
  31. data/spec/rubocop/cop/airbnb/factory_attr_references_class_spec.rb +81 -121
  32. data/spec/rubocop/cop/airbnb/factory_class_use_string_spec.rb +12 -20
  33. data/spec/rubocop/cop/airbnb/mass_assignment_accessible_modifier_spec.rb +17 -22
  34. data/spec/rubocop/cop/airbnb/module_method_in_wrong_file_spec.rb +75 -114
  35. data/spec/rubocop/cop/airbnb/no_timeout_spec.rb +16 -22
  36. data/spec/rubocop/cop/airbnb/opt_arg_parameter_spec.rb +46 -73
  37. data/spec/rubocop/cop/airbnb/phrase_bundle_keys_spec.rb +5 -20
  38. data/spec/rubocop/cop/airbnb/risky_activerecord_invocation_spec.rb +19 -33
  39. data/spec/rubocop/cop/airbnb/rspec_describe_or_context_under_namespace_spec.rb +109 -187
  40. data/spec/rubocop/cop/airbnb/rspec_environment_modification_spec.rb +31 -41
  41. data/spec/rubocop/cop/airbnb/simple_modifier_conditional_spec.rb +64 -88
  42. data/spec/rubocop/cop/airbnb/simple_unless_spec.rb +17 -27
  43. data/spec/rubocop/cop/airbnb/spec_constant_assignment_spec.rb +42 -60
  44. data/spec/rubocop/cop/airbnb/unsafe_yaml_marshal_spec.rb +24 -36
  45. data/spec/spec_helper.rb +2 -0
  46. metadata +8 -8
@@ -1,103 +1,76 @@
1
- describe RuboCop::Cop::Airbnb::OptArgParameters do
2
- subject(:cop) { described_class.new }
3
-
1
+ describe RuboCop::Cop::Airbnb::OptArgParameters, :config do
4
2
  it 'allows method with no parameters' do
5
- source = [
6
- 'def my_method',
7
- 'end',
8
- ].join("\n")
9
-
10
- inspect_source(source)
11
- expect(cop.offenses).to be_empty
3
+ expect_no_offenses(<<~RUBY)
4
+ def my_method
5
+ end
6
+ RUBY
12
7
  end
13
8
 
14
9
  it 'allows method with one parameter' do
15
- source = [
16
- 'def my_method(params)',
17
- 'end',
18
- ].join("\n")
19
-
20
- inspect_source(source)
21
- expect(cop.offenses).to be_empty
10
+ expect_no_offenses(<<~RUBY)
11
+ def my_method(params)
12
+ end
13
+ RUBY
22
14
  end
23
15
 
24
16
  it 'allows method with one parameter with a default hash value' do
25
- source = [
26
- 'def my_method(params = {})',
27
- 'end',
28
- ].join("\n")
29
-
30
- inspect_source(source)
31
- expect(cop.offenses).to be_empty
17
+ expect_no_offenses(<<~RUBY)
18
+ def my_method(params = {})
19
+ end
20
+ RUBY
32
21
  end
33
22
 
34
23
  it 'allows method named default parameters' do
35
- source = [
36
- 'def my_method(a, b, c: 5, d: 6)',
37
- 'end',
38
- ].join("\n")
39
-
40
- inspect_source(source)
41
- expect(cop.offenses).to be_empty
24
+ expect_no_offenses(<<~RUBY)
25
+ def my_method(a, b, c: 5, d: 6)
26
+ end
27
+ RUBY
42
28
  end
43
29
 
44
30
  it 'allows method with multiple parameter with a default hash value' do
45
- source = [
46
- 'def my_method(a, b, c, params = {})',
47
- 'end',
48
- ].join("\n")
49
-
50
- inspect_source(source)
51
- expect(cop.offenses).to be_empty
31
+ expect_no_offenses(<<~RUBY)
32
+ def my_method(a, b, c, params = {})
33
+ end
34
+ RUBY
52
35
  end
53
36
 
54
37
  it 'allows method with default parameter before block parameter' do
55
- source = [
56
- 'def my_method(a, b, c, params = {}, &block)',
57
- 'end',
58
- ].join("\n")
59
-
60
- inspect_source(source)
61
- expect(cop.offenses).to be_empty
38
+ expect_no_offenses(<<~RUBY)
39
+ def my_method(a, b, c, params = {}, &block)
40
+ end
41
+ RUBY
62
42
  end
63
43
 
64
44
  it 'rejects method with a default parameter other than the last non-block parameter' do
65
- source = [
66
- 'def my_method(a, b = nil, c, &block)',
67
- 'end',
68
- ].join("\n")
69
-
70
- inspect_source(source)
71
- expect(cop.offenses.size).to eq(1)
45
+ expect_offense(<<~RUBY)
46
+ def my_method(a, b = nil, c, &block)
47
+ ^^^^^^^ Do not use default positional arguments. [...]
48
+ end
49
+ RUBY
72
50
  end
73
51
 
74
52
  it 'rejects method with a default parameter other than the last parameter' do
75
- source = [
76
- 'def my_method(a, b = 5, c = nil, params = {})',
77
- 'end',
78
- ].join("\n")
79
-
80
- inspect_source(source)
81
- expect(cop.offenses.size).to eq(2)
53
+ expect_offense(<<~RUBY)
54
+ def my_method(a, b = 5, c = nil, params = {})
55
+ ^^^^^ Do not use default positional arguments. [...]
56
+ ^^^^^^^ Do not use default positional arguments. [...]
57
+ end
58
+ RUBY
82
59
  end
83
60
 
84
61
  it 'rejects method where last parameter has a default value of nil' do
85
- source = [
86
- 'def my_method(a, b, c, params = nil)',
87
- 'end',
88
- ].join("\n")
89
-
90
- inspect_source(source)
91
- expect(cop.offenses.size).to eq(1)
62
+ expect_offense(<<~RUBY)
63
+ def my_method(a, b, c, params = nil)
64
+ ^^^^^^^^^^^^ Do not use default positional arguments. [...]
65
+ end
66
+ RUBY
92
67
  end
93
68
 
94
69
  it 'rejects method where last parameter has a default value of a constant' do
95
- source = [
96
- 'def my_method(a, b, c, params = Constants::A_CONSTANT)',
97
- 'end',
98
- ].join("\n")
99
-
100
- inspect_source(source)
101
- expect(cop.offenses.size).to eq(1)
70
+ expect_offense(<<~RUBY)
71
+ def my_method(a, b, c, params = Constants::A_CONSTANT)
72
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use default positional arguments. [...]
73
+ end
74
+ RUBY
102
75
  end
103
76
  end
@@ -1,8 +1,6 @@
1
- describe RuboCop::Cop::Airbnb::PhraseBundleKeys do
2
- subject(:cop) { described_class.new }
3
-
1
+ describe RuboCop::Cop::Airbnb::PhraseBundleKeys, :config do
4
2
  it 'generates offenses for mismatched keys in PhraseBundle classes' do
5
- source = <<EOS
3
+ expect_offense(<<EOS)
6
4
  # encoding: UTF-8
7
5
  module PhraseBundles
8
6
  class Host < PhraseBundle
@@ -10,6 +8,7 @@ module PhraseBundles
10
8
  def phrases
11
9
  {
12
10
  "shortened_key" => t(
11
+ ^^^^^^^^^^^^^^^ Phrase bundle keys should match their translation keys.
13
12
  "my_real_translation_key",
14
13
  default: 'Does not matter',
15
14
  ),
@@ -18,17 +17,10 @@ module PhraseBundles
18
17
  end
19
18
  end
20
19
  EOS
21
-
22
- inspect_source(source)
23
- expect(cop.offenses.size).to eq(1)
24
- expect(cop.offenses.map(&:line).sort).to eq([7])
25
- expect(cop.messages).to eq(
26
- ['Phrase bundle keys should match their translation keys.']
27
- )
28
20
  end
29
21
 
30
22
  it 'does not generate offenses for matching keys in PhraseBundle classes' do
31
- source = <<EOS
23
+ expect_no_offenses(<<EOS)
32
24
  # encoding: UTF-8
33
25
  module PhraseBundles
34
26
  class Host < PhraseBundle
@@ -44,14 +36,10 @@ module PhraseBundles
44
36
  end
45
37
  end
46
38
  EOS
47
-
48
- inspect_source(source)
49
- inspect_source(source)
50
- expect(cop.offenses).to be_empty
51
39
  end
52
40
 
53
41
  it 'passes on t calls that are not in PhraseBundle classes' do
54
- source = <<EOS
42
+ expect_no_offenses(<<EOS)
55
43
  # encoding: UTF-8
56
44
  module PhraseBundles
57
45
  class Host
@@ -67,8 +55,5 @@ module PhraseBundles
67
55
  end
68
56
  end
69
57
  EOS
70
-
71
- inspect_source(source)
72
- expect(cop.offenses).to be_empty
73
58
  end
74
59
  end
@@ -1,54 +1,40 @@
1
- describe RuboCop::Cop::Airbnb::RiskyActiverecordInvocation do
2
- subject(:cop) { described_class.new }
3
-
1
+ describe RuboCop::Cop::Airbnb::RiskyActiverecordInvocation, :config do
4
2
  it "allows where statement that's a hash" do
5
- source = [
6
- 'Users.where({:name => "Bob"})',
7
- ].join("\n")
8
-
9
- inspect_source(source)
10
- expect(cop.offenses).to be_empty
3
+ expect_no_offenses(<<~RUBY)
4
+ Users.where({:name => "Bob"})
5
+ RUBY
11
6
  end
12
7
 
13
8
  it "allows where statement that's a flat string" do
14
- source = 'Users.where("age = 24")'
15
-
16
- inspect_source(source)
17
- expect(cop.offenses).to be_empty
9
+ expect_no_offenses('Users.where("age = 24")')
18
10
  end
19
11
 
20
12
  it "allows a multiline where statement" do
21
- source = "Users.where(\"age = 24 OR \" \\\n\"age = 25\")"
22
-
23
- inspect_source(source)
24
- expect(cop.offenses).to be_empty
13
+ expect_no_offenses("Users.where(\"age = 24 OR \" \\\n\"age = 25\")")
25
14
  end
26
15
 
27
16
  it "allows interpolation in subsequent arguments to where" do
28
- source = 'Users.where("name like ?", "%#{name}%")'
29
-
30
- inspect_source(source)
31
- expect(cop.offenses).to be_empty
17
+ expect_no_offenses('Users.where("name like ?", "%#{name}%")')
32
18
  end
33
19
 
34
20
  it "disallows interpolation in where statements" do
35
- source = 'Users.where("name = #{username}")'
36
-
37
- inspect_source(source)
38
- expect(cop.offenses.size).to eq(1)
21
+ expect_offense(<<~RUBY)
22
+ Users.where("name = \#{username}")
23
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Passing a string computed by interpolation or addition to an ActiveRecord method is likely to lead to SQL injection. [...]
24
+ RUBY
39
25
  end
40
26
 
41
27
  it "disallows addition in where statements" do
42
- source = 'Users.where("name = " + username)'
43
-
44
- inspect_source(source)
45
- expect(cop.offenses.size).to eq(1)
28
+ expect_offense(<<~RUBY)
29
+ Users.where("name = " + username)
30
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Passing a string computed by interpolation or addition to an ActiveRecord method is likely to lead to SQL injection. [...]
31
+ RUBY
46
32
  end
47
33
 
48
34
  it "disallows interpolation in order statements" do
49
- source = 'Users.where("age = 24").order("name #{sortorder}")'
50
-
51
- inspect_source(source)
52
- expect(cop.offenses.size).to eq(1)
35
+ expect_offense(<<~RUBY)
36
+ Users.where("age = 24").order("name \#{sortorder}")
37
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Passing a string computed by interpolation or addition to an ActiveRecord method is likely to lead to SQL injection. [...]
38
+ RUBY
53
39
  end
54
40
  end
@@ -1,6 +1,4 @@
1
- describe RuboCop::Cop::Airbnb::RspecDescribeOrContextUnderNamespace do
2
- subject(:cop) { described_class.new }
3
-
1
+ describe RuboCop::Cop::Airbnb::RspecDescribeOrContextUnderNamespace, :config do
4
2
  let(:tmpdir) { Dir.mktmpdir }
5
3
  let(:models_spec_dir) do
6
4
  FileUtils.mkdir_p("#{tmpdir}/spec/models").first
@@ -13,125 +11,73 @@ describe RuboCop::Cop::Airbnb::RspecDescribeOrContextUnderNamespace do
13
11
  shared_examples 'rspec namespacing rule' do
14
12
  context 'under a namespace' do
15
13
  it 'rejects without change message when argument is a string' do
16
- source = [
17
- 'module Foo',
18
- " #{method} 'SomeClass' do",
19
- ' it "passes" do',
20
- ' expect(true).to be_true',
21
- ' end',
22
- ' end',
23
- 'end',
24
- ].join("\n")
25
-
26
14
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
27
15
  File.open "#{models_spec_dir}/foo/some_class_spec.rb", "w" do |file|
28
- inspect_source(source, file)
16
+ expect_offense(<<~RUBY, file)
17
+ module Foo
18
+ ^^^^^^^^^^ Declaring a `module` in a spec can break autoloading because subsequent references to it will not cause it to be loaded from the app. This could cause flaky tests. Remove `module Foo` and fix `Foo::CONST` and `Foo.method` calls accordingly.
19
+ #{method} 'SomeClass' do
20
+ it "passes" do
21
+ expect(true).to be_true
22
+ end
23
+ end
24
+ end
25
+ RUBY
29
26
  end
30
-
31
- expect(cop.offenses.size).to eql(1)
32
- expect(cop.offenses.first.message).
33
- to include('Declaring a `module` in a spec can break autoloading because ')
34
-
35
- expect(cop.offenses.first.message).
36
- not_to include(
37
- "Change `#{method} SomeClass do` to `#{method} Foo::SomeClass do`"
38
- )
39
-
40
- expect(cop.offenses.first.message).
41
- to include('Remove `module Foo` and fix `Foo::CONST` and `Foo.method` calls')
42
27
  end
43
28
 
44
29
  it 'rejects with change message when argument is a constant' do
45
- source = [
46
- 'module Foo',
47
- " #{method} SomeClass do",
48
- ' it "passes" do',
49
- ' expect(true).to be_true',
50
- ' end',
51
- ' end',
52
- 'end',
53
- ].join("\n")
54
-
55
30
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
56
31
  File.open "#{models_spec_dir}/foo/some_class_spec.rb", "w" do |file|
57
- inspect_source(source, file)
32
+ expect_offense(<<~RUBY, file)
33
+ module Foo
34
+ ^^^^^^^^^^ Declaring a `module` in a spec can break autoloading because subsequent references to it will not cause it to be loaded from the app. This could cause flaky tests. Change `#{method} SomeClass do` to `#{method} Foo::SomeClass do`. Remove `module Foo` and fix `Foo::CONST` and `Foo.method` calls accordingly.
35
+ #{method} SomeClass do
36
+ it "passes" do
37
+ expect(true).to be_true
38
+ end
39
+ end
40
+ end
41
+ RUBY
58
42
  end
59
-
60
- expect(cop.offenses.size).to eql(1)
61
- expect(cop.offenses.first.message).
62
- to include('Declaring a `module` in a spec can break autoloading because ')
63
-
64
- expect(cop.offenses.first.message).
65
- to include(
66
- "Change `#{method} SomeClass do` to `#{method} Foo::SomeClass do`"
67
- )
68
-
69
- expect(cop.offenses.first.message).
70
- to include('Remove `module Foo` and fix `Foo::CONST` and `Foo.method` calls')
71
43
  end
72
44
 
73
45
  it 'rejects when within a nested block' do
74
- source = [
75
- 'module Foo',
76
- ' 1.times do',
77
- " #{method} SomeClass do",
78
- ' it "passes" do',
79
- ' expect(true).to be_true',
80
- ' end',
81
- ' end',
82
- ' end',
83
- 'end',
84
- ].join("\n")
85
-
86
46
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
87
47
  File.open "#{models_spec_dir}/foo/some_class_spec.rb", "w" do |file|
88
- inspect_source(source, file)
48
+ expect_offense(<<~RUBY, file)
49
+ module Foo
50
+ ^^^^^^^^^^ Declaring a `module` in a spec can break autoloading because subsequent references to it will not cause it to be loaded from the app. This could cause flaky tests. Change `#{method} SomeClass do` to `#{method} Foo::SomeClass do`. Remove `module Foo` and fix `Foo::CONST` and `Foo.method` calls accordingly.
51
+ 1.times do
52
+ #{method} SomeClass do
53
+ it "passes" do
54
+ expect(true).to be_true
55
+ end
56
+ end
57
+ end
58
+ end
59
+ RUBY
89
60
  end
90
-
91
- expect(cop.offenses.size).to eql(1)
92
- expect(cop.offenses.first.message).
93
- to include('Declaring a `module` in a spec can break autoloading because ')
94
-
95
- expect(cop.offenses.first.message).
96
- to include(
97
- "Change `#{method} SomeClass do` to `#{method} Foo::SomeClass do`"
98
- )
99
-
100
- expect(cop.offenses.first.message).
101
- to include('Remove `module Foo` and fix `Foo::CONST` and `Foo.method` calls')
102
61
  end
103
62
 
104
63
  it 'rejects when a block is executed prior' do
105
- source = [
106
- 'module Foo',
107
- ' [1,2,3].each do',
108
- ' something',
109
- ' end',
110
- '',
111
- " #{method} SomeClass do",
112
- ' it "passes" do',
113
- ' expect(true).to be_true',
114
- ' end',
115
- ' end',
116
- 'end',
117
- ].join("\n")
118
-
119
64
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
120
65
  File.open "#{models_spec_dir}/foo/some_class_spec.rb", "w" do |file|
121
- inspect_source(source, file)
66
+ expect_offense(<<~RUBY, file)
67
+ module Foo
68
+ ^^^^^^^^^^ Declaring a `module` in a spec can break autoloading because subsequent references to it will not cause it to be loaded from the app. This could cause flaky tests. Change `#{method} SomeClass do` to `#{method} Foo::SomeClass do`. Remove `module Foo` and fix `Foo::CONST` and `Foo.method` calls accordingly.
69
+ [1,2,3].each do
70
+ something
71
+ end
72
+
73
+ #{method} SomeClass do
74
+ it "passes" do
75
+ expect(true).to be_true
76
+ end
77
+ end
78
+ end
79
+ RUBY
122
80
  end
123
-
124
- expect(cop.offenses.size).to eql(1)
125
- expect(cop.offenses.first.message).
126
- to include('Declaring a `module` in a spec can break autoloading because ')
127
-
128
- expect(cop.offenses.first.message).
129
- to include(
130
- "Change `#{method} SomeClass do` to `#{method} Foo::SomeClass do`"
131
- )
132
-
133
- expect(cop.offenses.first.message).
134
- to include('Remove `module Foo` and fix `Foo::CONST` and `Foo.method` calls')
135
81
  end
136
82
  end
137
83
  end
@@ -161,124 +107,100 @@ describe RuboCop::Cop::Airbnb::RspecDescribeOrContextUnderNamespace do
161
107
  end
162
108
 
163
109
  it 'accepts if file is not a spec file' do
164
- source = [
165
- 'module Foo',
166
- ' RSpec.describe "SomeClass" do',
167
- ' it "passes" do',
168
- ' expect(true).to be_true',
169
- ' end',
170
- ' end',
171
- 'end',
172
- ].join("\n")
173
-
174
110
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
175
111
  File.open "#{models_spec_dir}/foo/some_class.rb", "w" do |file|
176
- inspect_source(source, file)
112
+ expect_no_offenses(<<~RUBY, file)
113
+ module Foo
114
+ RSpec.describe "SomeClass" do
115
+ it "passes" do
116
+ expect(true).to be_true
117
+ end
118
+ end
119
+ end
120
+ RUBY
177
121
  end
178
-
179
- expect(cop.offenses).to be_empty
180
122
  end
181
123
 
182
124
  it 'accepts if not under a module' do
183
- source = [
184
- 'RSpec.describe "SomeClass" do',
185
- ' it "passes" do',
186
- ' expect(true).to be_true',
187
- ' end',
188
- 'end',
189
- ].join("\n")
190
-
191
125
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
192
126
  File.open "#{models_spec_dir}/foo/some_class_spec.rb", "w" do |file|
193
- inspect_source(source, file)
127
+ expect_no_offenses(<<~RUBY, file)
128
+ RSpec.describe "SomeClass" do
129
+ it "passes" do
130
+ expect(true).to be_true
131
+ end
132
+ end
133
+ RUBY
194
134
  end
195
-
196
- expect(cop.offenses).to be_empty
197
135
  end
198
136
 
199
137
  it 'accepts if not describe or context' do
200
- source = [
201
- 'module Foo',
202
- ' not_describe_or_context "SomeClass" do',
203
- ' it "passes" do',
204
- ' expect(true).to be_true',
205
- ' end',
206
- ' end',
207
- 'end',
208
- ].join("\n")
209
-
210
138
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
211
139
  File.open "#{models_spec_dir}/foo/some_class_spec.rb", "w" do |file|
212
- inspect_source(source, file)
140
+ expect_no_offenses(<<~RUBY, file)
141
+ module Foo
142
+ not_describe_or_context "SomeClass" do
143
+ it "passes" do
144
+ expect(true).to be_true
145
+ end
146
+ end
147
+ end
148
+ RUBY
213
149
  end
214
-
215
- expect(cop.offenses).to be_empty
216
150
  end
217
151
 
218
152
  it 'accepts an empty module' do
219
- source = [
220
- 'RSpec.describe "SomeClass" do',
221
- ' module Bar; end',
222
- '',
223
- ' it "passes" do',
224
- ' expect(true).to be_true',
225
- ' end',
226
- 'end',
227
- ].join("\n")
228
-
229
153
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
230
154
  File.open "#{models_spec_dir}/foo/some_class_spec.rb", "w" do |file|
231
- inspect_source(source, file)
232
- end
155
+ expect_no_offenses(<<~RUBY, file)
156
+ RSpec.describe "SomeClass" do
157
+ module Bar; end
233
158
 
234
- expect(cop.offenses).to be_empty
159
+ it "passes" do
160
+ expect(true).to be_true
161
+ end
162
+ end
163
+ RUBY
164
+ end
235
165
  end
236
166
 
237
167
  it 'accepts a module with code' do
238
- source = [
239
- 'RSpec.describe "SomeClass" do',
240
- ' module Bar',
241
- ' def self.foo',
242
- ' end',
243
- ' foo',
244
- ' end',
245
- '',
246
- ' it "passes" do',
247
- ' expect(true).to be_true',
248
- ' end',
249
- 'end',
250
- ].join("\n")
251
-
252
168
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
253
169
  File.open "#{models_spec_dir}/foo/some_class_spec.rb", "w" do |file|
254
- inspect_source(source, file)
170
+ expect_no_offenses(<<~RUBY, file)
171
+ RSpec.describe "SomeClass" do
172
+ module Bar
173
+ def self.foo
174
+ end
175
+ foo
176
+ end
177
+
178
+ it "passes" do
179
+ expect(true).to be_true
180
+ end
181
+ end
182
+ RUBY
255
183
  end
256
-
257
- expect(cop.offenses).to be_empty
258
184
  end
259
185
 
260
186
  it 'accepts when describe or context to be called when class or module is not RSpec' do
261
- source = [
262
- 'module Foo',
263
- ' Bar.describe "SomeClass" do',
264
- ' it "passes" do',
265
- ' expect(true).to be_true',
266
- ' end',
267
- ' end',
268
- '',
269
- ' Bar.context "SomeClass" do',
270
- ' it "passes" do',
271
- ' expect(true).to be_true',
272
- ' end',
273
- ' end',
274
- 'end',
275
- ].join("\n")
276
-
277
187
  FileUtils.mkdir_p "#{models_spec_dir}/foo"
278
188
  File.open "#{models_spec_dir}/foo/some_class_spec.rb", "w" do |file|
279
- inspect_source(source, file)
189
+ expect_no_offenses(<<~RUBY, file)
190
+ module Foo
191
+ Bar.describe "SomeClass" do
192
+ it "passes" do
193
+ expect(true).to be_true
194
+ end
195
+ end
196
+
197
+ Bar.context "SomeClass" do
198
+ it "passes" do
199
+ expect(true).to be_true
200
+ end
201
+ end
202
+ end
203
+ RUBY
280
204
  end
281
-
282
- expect(cop.offenses).to be_empty
283
205
  end
284
206
  end