rubocop-rspec 1.35.0 → 1.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/config/default.yml +11 -0
  4. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +16 -0
  5. data/lib/rubocop/cop/rspec/context_method.rb +53 -0
  6. data/lib/rubocop/cop/rspec/describe_class.rb +7 -10
  7. data/lib/rubocop/cop/rspec/described_class.rb +29 -1
  8. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +87 -0
  9. data/lib/rubocop/cop/rspec/example_wording.rb +28 -12
  10. data/lib/rubocop/cop/rspec/expect_change.rb +8 -8
  11. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +2 -9
  12. data/lib/rubocop/cop/rspec/focus.rb +5 -10
  13. data/lib/rubocop/cop/rspec/instance_variable.rb +2 -1
  14. data/lib/rubocop/cop/rspec/multiple_expectations.rb +13 -21
  15. data/lib/rubocop/cop/rspec/pending.rb +19 -25
  16. data/lib/rubocop/cop/rspec_cops.rb +2 -0
  17. data/lib/rubocop/rspec/version.rb +1 -1
  18. metadata +7 -198
  19. data/Gemfile +0 -11
  20. data/Rakefile +0 -87
  21. data/rubocop-rspec.gemspec +0 -49
  22. data/spec/project/changelog_spec.rb +0 -76
  23. data/spec/project/default_config_spec.rb +0 -76
  24. data/spec/project/project_requires_spec.rb +0 -20
  25. data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +0 -51
  26. data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +0 -51
  27. data/spec/rubocop/cop/rspec/any_instance_spec.rb +0 -32
  28. data/spec/rubocop/cop/rspec/around_block_spec.rb +0 -121
  29. data/spec/rubocop/cop/rspec/be_eql_spec.rb +0 -81
  30. data/spec/rubocop/cop/rspec/be_spec.rb +0 -35
  31. data/spec/rubocop/cop/rspec/before_after_all_spec.rb +0 -52
  32. data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +0 -65
  33. data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +0 -130
  34. data/spec/rubocop/cop/rspec/context_wording_spec.rb +0 -94
  35. data/spec/rubocop/cop/rspec/cop_spec.rb +0 -95
  36. data/spec/rubocop/cop/rspec/describe_class_spec.rb +0 -168
  37. data/spec/rubocop/cop/rspec/describe_method_spec.rb +0 -34
  38. data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +0 -44
  39. data/spec/rubocop/cop/rspec/described_class_spec.rb +0 -352
  40. data/spec/rubocop/cop/rspec/dialect_spec.rb +0 -78
  41. data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +0 -93
  42. data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +0 -121
  43. data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +0 -239
  44. data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +0 -133
  45. data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +0 -94
  46. data/spec/rubocop/cop/rspec/example_length_spec.rb +0 -78
  47. data/spec/rubocop/cop/rspec/example_without_description_spec.rb +0 -92
  48. data/spec/rubocop/cop/rspec/example_wording_spec.rb +0 -173
  49. data/spec/rubocop/cop/rspec/expect_actual_spec.rb +0 -150
  50. data/spec/rubocop/cop/rspec/expect_change_spec.rb +0 -86
  51. data/spec/rubocop/cop/rspec/expect_in_hook_spec.rb +0 -79
  52. data/spec/rubocop/cop/rspec/expect_output_spec.rb +0 -62
  53. data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +0 -208
  54. data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +0 -171
  55. data/spec/rubocop/cop/rspec/file_path_spec.rb +0 -200
  56. data/spec/rubocop/cop/rspec/focus_spec.rb +0 -139
  57. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +0 -173
  58. data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +0 -150
  59. data/spec/rubocop/cop/rspec/implicit_block_expectation_spec.rb +0 -135
  60. data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +0 -102
  61. data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +0 -188
  62. data/spec/rubocop/cop/rspec/instance_spy_spec.rb +0 -61
  63. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +0 -95
  64. data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +0 -39
  65. data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +0 -47
  66. data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +0 -82
  67. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +0 -119
  68. data/spec/rubocop/cop/rspec/leaky_constant_declaration_spec.rb +0 -91
  69. data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +0 -137
  70. data/spec/rubocop/cop/rspec/let_setup_spec.rb +0 -66
  71. data/spec/rubocop/cop/rspec/message_chain_spec.rb +0 -23
  72. data/spec/rubocop/cop/rspec/message_expectation_spec.rb +0 -45
  73. data/spec/rubocop/cop/rspec/message_spies_spec.rb +0 -151
  74. data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +0 -57
  75. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +0 -30
  76. data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +0 -261
  77. data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +0 -83
  78. data/spec/rubocop/cop/rspec/named_subject_spec.rb +0 -123
  79. data/spec/rubocop/cop/rspec/nested_groups_spec.rb +0 -81
  80. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +0 -77
  81. data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +0 -91
  82. data/spec/rubocop/cop/rspec/pending_spec.rb +0 -186
  83. data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +0 -354
  84. data/spec/rubocop/cop/rspec/rails/http_status_spec.rb +0 -90
  85. data/spec/rubocop/cop/rspec/receive_counts_spec.rb +0 -138
  86. data/spec/rubocop/cop/rspec/receive_never_spec.rb +0 -57
  87. data/spec/rubocop/cop/rspec/repeated_description_spec.rb +0 -76
  88. data/spec/rubocop/cop/rspec/repeated_example_spec.rb +0 -74
  89. data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +0 -289
  90. data/spec/rubocop/cop/rspec/scattered_let_spec.rb +0 -28
  91. data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +0 -98
  92. data/spec/rubocop/cop/rspec/shared_context_spec.rb +0 -137
  93. data/spec/rubocop/cop/rspec/shared_examples_spec.rb +0 -75
  94. data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +0 -178
  95. data/spec/rubocop/cop/rspec/subject_stub_spec.rb +0 -293
  96. data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +0 -177
  97. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +0 -86
  98. data/spec/rubocop/cop/rspec/void_expect_spec.rb +0 -49
  99. data/spec/rubocop/cop/rspec/yield_spec.rb +0 -81
  100. data/spec/rubocop/rspec/config_formatter_spec.rb +0 -52
  101. data/spec/rubocop/rspec/description_extractor_spec.rb +0 -63
  102. data/spec/rubocop/rspec/example_group_spec.rb +0 -44
  103. data/spec/rubocop/rspec/example_spec.rb +0 -62
  104. data/spec/rubocop/rspec/hook_spec.rb +0 -53
  105. data/spec/rubocop/rspec/language/selector_set_spec.rb +0 -53
  106. data/spec/rubocop/rspec/util/one_spec.rb +0 -23
  107. data/spec/rubocop/rspec/wording_spec.rb +0 -52
  108. data/spec/shared/autocorrect_behavior.rb +0 -9
  109. data/spec/shared/detects_style_behavior.rb +0 -9
  110. data/spec/shared/smoke_test_examples.rb +0 -27
  111. data/spec/smoke_tests/empty_spec.rb +0 -0
  112. data/spec/smoke_tests/factory_bot_spec.rb +0 -11
  113. data/spec/smoke_tests/no_tests_spec.rb +0 -4
  114. data/spec/smoke_tests/weird_rspec_spec.rb +0 -233
  115. data/spec/spec_helper.rb +0 -42
  116. data/spec/support/expect_offense.rb +0 -19
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::Dialect, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:cop_config) do
7
- {
8
- 'PreferredMethods' => {
9
- 'context' => 'describe'
10
- }
11
- }
12
- end
13
-
14
- it 'allows describe blocks' do
15
- expect_no_offenses(<<-RUBY)
16
- describe 'display name presence' do
17
- end
18
- RUBY
19
- end
20
-
21
- it 'allows calling methods named context in examples' do
22
- expect_no_offenses(<<-RUBY)
23
- it 'tests common context invocations' do
24
- expect(request.context).to be_empty?
25
- end
26
- RUBY
27
- end
28
-
29
- it 'registers an offense for context blocks' do
30
- expect_offense(<<-RUBY)
31
- context 'display name presence' do
32
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`.
33
- end
34
- RUBY
35
-
36
- expect_correction(<<-RUBY)
37
- describe 'display name presence' do
38
- end
39
- RUBY
40
- end
41
-
42
- it 'registers an offense for RSpec.context blocks' do
43
- expect_offense(<<-RUBY)
44
- RSpec.context 'context' do
45
- ^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`.
46
- it 'tests common context invocations' do
47
- expect(request.context).to be_empty?
48
- end
49
- end
50
- RUBY
51
-
52
- expect_correction(<<-RUBY)
53
- RSpec.describe 'context' do
54
- it 'tests common context invocations' do
55
- expect(request.context).to be_empty?
56
- end
57
- end
58
- RUBY
59
- end
60
-
61
- context 'without preferred methods' do
62
- let(:cop_config) do
63
- {
64
- 'PreferredMethods' => {}
65
- }
66
- end
67
-
68
- it 'allows all methods blocks' do
69
- expect_no_offenses(<<-RUBY)
70
- context 'is important' do
71
- specify 'for someone to work' do
72
- everyone.should have_some_leeway
73
- end
74
- end
75
- RUBY
76
- end
77
- end
78
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::EmptyExampleGroup, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- it 'flags an empty context' do
7
- expect_offense(<<-RUBY)
8
- describe Foo do
9
- context 'when bar' do
10
- ^^^^^^^^^^^^^^^^^^ Empty example group detected.
11
-
12
- let(:foo) { bar }
13
- end
14
-
15
- describe '#thingy?' do
16
- specify do
17
- expect(whatever.thingy?).to be(true)
18
- end
19
- end
20
-
21
- it { should be_true }
22
- end
23
- RUBY
24
- end
25
-
26
- it 'flags an empty top level describe' do
27
- expect_offense(<<-RUBY)
28
- describe Foo do
29
- ^^^^^^^^^^^^ Empty example group detected.
30
- end
31
- RUBY
32
- end
33
-
34
- it 'does not flag include_examples' do
35
- expect_no_offenses(<<-RUBY)
36
- describe Foo do
37
- context "when something is true" do
38
- include_examples "some expectations"
39
- end
40
-
41
- context "when something else is true" do
42
- include_context "some expectations"
43
- end
44
-
45
- context "when a third thing is true" do
46
- it_behaves_like "some thingy"
47
- end
48
- end
49
- RUBY
50
- end
51
-
52
- it 'does not flag methods matching example group names' do
53
- expect_no_offenses(<<-RUBY)
54
- describe Foo do
55
- it 'yields a block when given' do
56
- value = nil
57
-
58
- helper.feature('whatevs') { value = 5 }
59
-
60
- expect(value).to be 5
61
- end
62
- end
63
- RUBY
64
- end
65
-
66
- it 'does not recognize custom include methods by default' do
67
- expect_offense(<<-RUBY)
68
- describe Foo do
69
- ^^^^^^^^^^^^ Empty example group detected.
70
- context "when I do something clever" do
71
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Empty example group detected.
72
- it_has_special_behavior
73
- end
74
- end
75
- RUBY
76
- end
77
-
78
- context 'when a custom include method is specified' do
79
- let(:cop_config) do
80
- { 'CustomIncludeMethods' => %w[it_has_special_behavior] }
81
- end
82
-
83
- it 'does not flag an otherwise empty example group' do
84
- expect_no_offenses(<<-RUBY)
85
- describe Foo do
86
- context "when I do something clever" do
87
- it_has_special_behavior
88
- end
89
- end
90
- RUBY
91
- end
92
- end
93
- end
@@ -1,121 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterExampleGroup do
4
- subject(:cop) { described_class.new }
5
-
6
- it 'checks for empty line after describe' do
7
- expect_offense(<<-RUBY)
8
- RSpec.describe Foo do
9
- describe '#bar' do
10
- end
11
- ^^^ Add an empty line after `describe`.
12
- describe '#baz' do
13
- end
14
- end
15
- RUBY
16
-
17
- expect_correction(<<-RUBY)
18
- RSpec.describe Foo do
19
- describe '#bar' do
20
- end
21
-
22
- describe '#baz' do
23
- end
24
- end
25
- RUBY
26
- end
27
-
28
- it 'highlights single line formulations correctly' do
29
- expect_offense(<<-RUBY)
30
- RSpec.describe Foo do
31
- describe('#bar') { }
32
- ^^^^^^^^^^^^^^^^^^^^ Add an empty line after `describe`.
33
- describe '#baz' do
34
- end
35
- end
36
- RUBY
37
-
38
- expect_correction(<<-RUBY)
39
- RSpec.describe Foo do
40
- describe('#bar') { }
41
-
42
- describe '#baz' do
43
- end
44
- end
45
- RUBY
46
- end
47
-
48
- it 'checks for empty line after context' do
49
- expect_offense(<<-RUBY)
50
- RSpec.context 'foo' do
51
- context 'bar' do
52
- end
53
- ^^^ Add an empty line after `context`.
54
- context 'baz' do
55
- end
56
- end
57
- RUBY
58
-
59
- expect_correction(<<-RUBY)
60
- RSpec.context 'foo' do
61
- context 'bar' do
62
- end
63
-
64
- context 'baz' do
65
- end
66
- end
67
- RUBY
68
- end
69
-
70
- it 'approves empty line after describe' do
71
- expect_no_offenses(<<-RUBY)
72
- RSpec.describe Foo do
73
- describe '#bar' do
74
- end
75
-
76
- describe '#baz' do
77
- end
78
- end
79
- RUBY
80
- end
81
-
82
- it 'approves empty line after context' do
83
- expect_no_offenses(<<-RUBY)
84
- RSpec.context 'foo' do
85
- context 'bar' do
86
- end
87
-
88
- context 'baz' do
89
- end
90
- end
91
- RUBY
92
- end
93
-
94
- it 'handles describes in an if block' do
95
- expect_offense(<<-RUBY)
96
- if RUBY_VERSION < 2.3
97
- describe 'skips checks under old ruby' do
98
- end
99
- else
100
- describe 'first check' do
101
- end
102
- ^^^ Add an empty line after `describe`.
103
- describe 'second check' do
104
- end
105
- end
106
- RUBY
107
-
108
- expect_correction(<<-RUBY)
109
- if RUBY_VERSION < 2.3
110
- describe 'skips checks under old ruby' do
111
- end
112
- else
113
- describe 'first check' do
114
- end
115
-
116
- describe 'second check' do
117
- end
118
- end
119
- RUBY
120
- end
121
- end
@@ -1,239 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterFinalLet do
4
- subject(:cop) { described_class.new }
5
-
6
- it 'checks for empty line after last let' do
7
- expect_offense(<<-RUBY)
8
- RSpec.describe User do
9
- let(:a) { a }
10
- let(:b) { b }
11
- ^^^^^^^^^^^^^ Add an empty line after the last `let` block.
12
- it { expect(a).to eq(b) }
13
- end
14
- RUBY
15
-
16
- expect_correction(<<-RUBY)
17
- RSpec.describe User do
18
- let(:a) { a }
19
- let(:b) { b }
20
-
21
- it { expect(a).to eq(b) }
22
- end
23
- RUBY
24
- end
25
-
26
- it 'check for empty line after the last `let!`' do
27
- expect_offense(<<-RUBY)
28
- RSpec.describe User do
29
- let(:a) { a }
30
- let!(:b) do
31
- b
32
- end
33
- ^^^ Add an empty line after the last `let` block.
34
- it { expect(a).to eq(b) }
35
- end
36
- RUBY
37
-
38
- expect_correction(<<-RUBY)
39
- RSpec.describe User do
40
- let(:a) { a }
41
- let!(:b) do
42
- b
43
- end
44
-
45
- it { expect(a).to eq(b) }
46
- end
47
- RUBY
48
- end
49
-
50
- it 'approves empty line after let' do
51
- expect_no_offenses(<<-RUBY)
52
- RSpec.describe User do
53
- let(:a) { a }
54
- let(:b) { b }
55
-
56
- it { expect(a).to eq(b) }
57
- end
58
- RUBY
59
- end
60
-
61
- it 'allows comment followed by an empty line after let' do
62
- expect_no_offenses(<<-RUBY)
63
- RSpec.describe User do
64
- let(:a) { a }
65
- let(:b) { b }
66
- # end of setup
67
-
68
- it { expect(a).to eq(b) }
69
- end
70
- RUBY
71
- end
72
-
73
- it 'flags missing empty line after the comment that comes after last let' do
74
- expect_offense(<<-RUBY)
75
- RSpec.describe User do
76
- let(:a) { a }
77
- let(:b) { b }
78
- # end of setup
79
- ^^^^^^^^^^^^^^ Add an empty line after the last `let` block.
80
- it { expect(a).to eq(b) }
81
- end
82
- RUBY
83
-
84
- expect_correction(<<-RUBY)
85
- RSpec.describe User do
86
- let(:a) { a }
87
- let(:b) { b }
88
- # end of setup
89
-
90
- it { expect(a).to eq(b) }
91
- end
92
- RUBY
93
- end
94
-
95
- it 'flags missing empty line after a multiline comment after last let' do
96
- expect_offense(<<-RUBY)
97
- RSpec.describe User do
98
- let(:a) { a }
99
- let(:b) { b }
100
- # a multiline comment marking
101
- # the end of setup
102
- ^^^^^^^^^^^^^^^^^^ Add an empty line after the last `let` block.
103
- it { expect(a).to eq(b) }
104
- end
105
- RUBY
106
-
107
- expect_correction(<<-RUBY)
108
- RSpec.describe User do
109
- let(:a) { a }
110
- let(:b) { b }
111
- # a multiline comment marking
112
- # the end of setup
113
-
114
- it { expect(a).to eq(b) }
115
- end
116
- RUBY
117
- end
118
-
119
- it 'ignores empty lines between the lets' do
120
- expect_offense(<<-RUBY)
121
- RSpec.describe User do
122
- let(:a) { a }
123
-
124
- subject { described_class }
125
-
126
- let!(:b) { b }
127
- ^^^^^^^^^^^^^^ Add an empty line after the last `let` block.
128
- it { expect(a).to eq(b) }
129
- end
130
- RUBY
131
-
132
- expect_correction(<<-RUBY)
133
- RSpec.describe User do
134
- let(:a) { a }
135
-
136
- subject { described_class }
137
-
138
- let!(:b) { b }
139
-
140
- it { expect(a).to eq(b) }
141
- end
142
- RUBY
143
- end
144
-
145
- it 'handles let in tests' do
146
- expect_no_offenses(<<-RUBY)
147
- RSpec.describe User do
148
- # This shouldn't really ever happen in a sane codebase but I still
149
- # want to avoid false positives
150
- it "doesn't mind me calling a method called let in the test" do
151
- let(foo)
152
- subject { bar }
153
- end
154
- end
155
- RUBY
156
- end
157
-
158
- it 'handles multiline let block' do
159
- expect_no_offenses(<<-RUBY)
160
- RSpec.describe User do
161
- let(:a) { a }
162
- let(:b) do
163
- b
164
- end
165
-
166
- it { expect(a).to eq(b) }
167
- end
168
- RUBY
169
- end
170
-
171
- it 'handles let being the latest node' do
172
- expect_no_offenses(<<-RUBY)
173
- RSpec.describe User do
174
- let(:a) { a }
175
- let(:b) { b }
176
- end
177
- RUBY
178
- end
179
-
180
- it 'handles HEREDOC for let' do
181
- expect_no_offenses(<<-RUBY)
182
- RSpec.describe User do
183
- let(:foo) do
184
- <<-BAR
185
- hello
186
- world
187
- BAR
188
- end
189
-
190
- it 'uses heredoc' do
191
- expect(foo).to eql(" hello\n world\n")
192
- end
193
- end
194
- RUBY
195
- end
196
-
197
- it 'handles silly HEREDOC syntax for let' do
198
- expect_no_offenses(<<-RUBY)
199
- RSpec.describe 'silly heredoc syntax' do
200
- let(:foo) { <<-BAR }
201
- hello
202
- world
203
- BAR
204
-
205
- it 'has tricky syntax' do
206
- expect(foo).to eql(" hello\n world\n")
207
- end
208
- end
209
- RUBY
210
- end
211
-
212
- it 'handles silly HEREDOC offense' do
213
- expect_offense(<<-RUBY)
214
- RSpec.describe 'silly heredoc syntax' do
215
- let(:foo) { <<-BAR }
216
- hello
217
- world
218
- BAR
219
- ^^^ Add an empty line after the last `let` block.
220
- it 'has tricky syntax' do
221
- expect(foo).to eql(" hello\n world\n")
222
- end
223
- end
224
- RUBY
225
-
226
- expect_correction(<<-RUBY)
227
- RSpec.describe 'silly heredoc syntax' do
228
- let(:foo) { <<-BAR }
229
- hello
230
- world
231
- BAR
232
-
233
- it 'has tricky syntax' do
234
- expect(foo).to eql(" hello\n world\n")
235
- end
236
- end
237
- RUBY
238
- end
239
- end