rubocop-rspec 1.24.0 → 1.25.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +1 -2
  4. data/README.md +7 -4
  5. data/Rakefile +18 -3
  6. data/config/default.yml +25 -0
  7. data/lib/rubocop-rspec.rb +3 -0
  8. data/lib/rubocop/cop/rspec/be.rb +35 -0
  9. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +34 -0
  10. data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
  11. data/lib/rubocop/cop/rspec/empty_example_group.rb +3 -3
  12. data/lib/rubocop/cop/rspec/example_without_description.rb +1 -2
  13. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +148 -0
  14. data/lib/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically.rb +1 -3
  15. data/lib/rubocop/cop/rspec/factory_bot/static_attribute_defined_dynamically.rb +3 -3
  16. data/lib/rubocop/cop/rspec/instance_variable.rb +2 -2
  17. data/lib/rubocop/cop/rspec/multiple_expectations.rb +2 -2
  18. data/lib/rubocop/cop/rspec/nested_groups.rb +6 -3
  19. data/lib/rubocop/cop/rspec/pending.rb +71 -0
  20. data/lib/rubocop/cop/rspec/predicate_matcher.rb +11 -13
  21. data/lib/rubocop/cop/rspec/return_from_stub.rb +9 -16
  22. data/lib/rubocop/cop/rspec/shared_examples.rb +76 -0
  23. data/lib/rubocop/cop/rspec_cops.rb +4 -0
  24. data/lib/rubocop/rspec/example.rb +1 -1
  25. data/lib/rubocop/rspec/node.rb +19 -0
  26. data/lib/rubocop/rspec/top_level_describe.rb +3 -6
  27. data/lib/rubocop/rspec/version.rb +1 -1
  28. data/rubocop-rspec.gemspec +6 -1
  29. data/spec/rubocop/cop/rspec/be_spec.rb +33 -0
  30. data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +75 -18
  31. data/spec/rubocop/cop/rspec/cop_spec.rb +0 -4
  32. data/spec/rubocop/cop/rspec/described_class_spec.rb +1 -1
  33. data/spec/rubocop/cop/rspec/example_without_description_spec.rb +8 -0
  34. data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +140 -0
  35. data/spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb +11 -1
  36. data/spec/rubocop/cop/rspec/nested_groups_spec.rb +15 -0
  37. data/spec/rubocop/cop/rspec/pending_spec.rb +162 -0
  38. data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +13 -9
  39. data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +9 -0
  40. data/spec/rubocop/cop/rspec/shared_examples_spec.rb +93 -0
  41. data/spec/spec_helper.rb +1 -1
  42. metadata +19 -4
@@ -9,7 +9,7 @@ RSpec.describe RuboCop::Cop::RSpec::PredicateMatcher, :config do
9
9
  context 'when enforced style is `inflected`' do
10
10
  let(:enforced_style) { 'inflected' }
11
11
 
12
- shared_examples :inflected_common do
12
+ shared_examples 'inflected common' do
13
13
  it 'registers an offense for a predicate method in actual' do
14
14
  expect_offense(<<-RUBY)
15
15
  expect(foo.empty?).to be_truthy
@@ -90,6 +90,10 @@ RSpec.describe RuboCop::Cop::RSpec::PredicateMatcher, :config do
90
90
  'expect(foo.is_a?(Array)).to be_truthy',
91
91
  'expect(foo).to be_a(Array)'
92
92
 
93
+ include_examples 'autocorrect',
94
+ 'expect(foo.instance_of?(Array)).to be_truthy',
95
+ 'expect(foo).to be_an_instance_of(Array)'
96
+
93
97
  include_examples 'autocorrect',
94
98
  'expect(foo.has_something?).to be_truthy',
95
99
  'expect(foo).to have_something'
@@ -148,7 +152,7 @@ RSpec.describe RuboCop::Cop::RSpec::PredicateMatcher, :config do
148
152
  context 'when strict is true' do
149
153
  let(:strict) { true }
150
154
 
151
- include_examples :inflected_common
155
+ include_examples 'inflected common'
152
156
 
153
157
  it 'accepts strict checking boolean matcher' do
154
158
  expect_no_offenses(<<-RUBY)
@@ -164,7 +168,7 @@ RSpec.describe RuboCop::Cop::RSpec::PredicateMatcher, :config do
164
168
  context 'when strict is false' do
165
169
  let(:strict) { false }
166
170
 
167
- include_examples :inflected_common
171
+ include_examples 'inflected common'
168
172
 
169
173
  it 'registers an offense for a predicate method in actual' do
170
174
  expect_offense(<<-RUBY)
@@ -205,7 +209,7 @@ RSpec.describe RuboCop::Cop::RSpec::PredicateMatcher, :config do
205
209
  context 'when enforced style is `explicit`' do
206
210
  let(:enforced_style) { 'explicit' }
207
211
 
208
- shared_examples :explicit_common do
212
+ shared_examples 'explicit common' do
209
213
  it 'registers an offense for a predicate mather' do
210
214
  expect_offense(<<-RUBY)
211
215
  expect(foo).to be_empty
@@ -258,7 +262,7 @@ RSpec.describe RuboCop::Cop::RSpec::PredicateMatcher, :config do
258
262
  end
259
263
  end
260
264
 
261
- shared_examples :explicit_autocorrect do |matcher_true, matcher_false|
265
+ shared_examples 'explicit autocorrect' do |matcher_true, matcher_false|
262
266
  include_examples 'autocorrect',
263
267
  'expect(foo).to be_something',
264
268
  "expect(foo.something?).to #{matcher_true}"
@@ -321,15 +325,15 @@ RSpec.describe RuboCop::Cop::RSpec::PredicateMatcher, :config do
321
325
  context 'when strict is true' do
322
326
  let(:strict) { true }
323
327
 
324
- include_examples :explicit_common
325
- include_examples :explicit_autocorrect, 'be(true)', 'be(false)'
328
+ include_examples 'explicit common'
329
+ include_examples 'explicit autocorrect', 'be(true)', 'be(false)'
326
330
  end
327
331
 
328
332
  context 'when strict is false' do
329
333
  let(:strict) { false }
330
334
 
331
- include_examples :explicit_common
332
- include_examples :explicit_autocorrect, 'be_truthy', 'be_falsey'
335
+ include_examples 'explicit common'
336
+ include_examples 'explicit autocorrect', 'be_truthy', 'be_falsey'
333
337
  end
334
338
  end
335
339
  end
@@ -62,6 +62,15 @@ RSpec.describe RuboCop::Cop::RSpec::ReturnFromStub, :config do
62
62
  RUBY
63
63
  end
64
64
 
65
+ it 'finds nested constants returned from block' do
66
+ expect_offense(<<-RUBY)
67
+ it do
68
+ allow(Foo).to receive(:bar) { {Life::MEANING => 42} }
69
+ ^ Use `and_return` for static values.
70
+ end
71
+ RUBY
72
+ end
73
+
65
74
  it 'ignores dynamic values returned from block' do
66
75
  expect_no_offenses(<<-RUBY)
67
76
  it do
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RuboCop::Cop::RSpec::SharedExamples do
4
+ subject(:cop) { described_class.new }
5
+
6
+ it 'registers an offense when using symbolic title' do
7
+ expect_offense(<<-RUBY)
8
+ it_behaves_like :foo_bar_baz
9
+ ^^^^^^^^^^^^ Prefer 'foo bar baz' over `:foo_bar_baz` to titleize shared examples.
10
+ it_should_behave_like :foo_bar_baz
11
+ ^^^^^^^^^^^^ Prefer 'foo bar baz' over `:foo_bar_baz` to titleize shared examples.
12
+ shared_examples :foo_bar_baz
13
+ ^^^^^^^^^^^^ Prefer 'foo bar baz' over `:foo_bar_baz` to titleize shared examples.
14
+ shared_examples_for :foo_bar_baz
15
+ ^^^^^^^^^^^^ Prefer 'foo bar baz' over `:foo_bar_baz` to titleize shared examples.
16
+ include_examples :foo_bar_baz
17
+ ^^^^^^^^^^^^ Prefer 'foo bar baz' over `:foo_bar_baz` to titleize shared examples.
18
+ include_examples :foo_bar_baz, 'foo', 'bar'
19
+ ^^^^^^^^^^^^ Prefer 'foo bar baz' over `:foo_bar_baz` to titleize shared examples.
20
+
21
+ shared_examples :foo_bar_baz do |param|
22
+ ^^^^^^^^^^^^ Prefer 'foo bar baz' over `:foo_bar_baz` to titleize shared examples.
23
+ # ...
24
+ end
25
+
26
+ RSpec.shared_examples :foo_bar_baz
27
+ ^^^^^^^^^^^^ Prefer 'foo bar baz' over `:foo_bar_baz` to titleize shared examples.
28
+ RUBY
29
+ end
30
+
31
+ it 'does not register an offense when using string title' do
32
+ expect_no_offenses(<<-RUBY)
33
+ it_behaves_like 'foo bar baz'
34
+ it_should_behave_like 'foo bar baz'
35
+ shared_examples 'foo bar baz'
36
+ shared_examples_for 'foo bar baz'
37
+ include_examples 'foo bar baz'
38
+ include_examples 'foo bar baz', 'foo', 'bar'
39
+
40
+ shared_examples 'foo bar baz', 'foo', 'bar' do |param|
41
+ # ...
42
+ end
43
+ RUBY
44
+ end
45
+
46
+ it 'does not register an offense when using Module/Class title' do
47
+ expect_no_offenses(<<-RUBY)
48
+ it_behaves_like FooBarBaz
49
+ it_should_behave_like FooBarBaz
50
+ shared_examples FooBarBaz
51
+ shared_examples_for FooBarBaz
52
+ include_examples FooBarBaz
53
+ include_examples FooBarBaz, 'foo', 'bar'
54
+
55
+ shared_examples FooBarBaz, 'foo', 'bar' do |param|
56
+ # ...
57
+ end
58
+ RUBY
59
+ end
60
+
61
+ include_examples 'autocorrect',
62
+ 'it_behaves_like :foo_bar_baz',
63
+ "it_behaves_like 'foo bar baz'"
64
+ include_examples 'autocorrect',
65
+ 'it_should_behave_like :foo_bar_baz',
66
+ "it_should_behave_like 'foo bar baz'"
67
+ include_examples 'autocorrect',
68
+ 'shared_examples :foo_bar_baz',
69
+ "shared_examples 'foo bar baz'"
70
+ include_examples 'autocorrect',
71
+ 'shared_examples_for :foo_bar_baz',
72
+ "shared_examples_for 'foo bar baz'"
73
+ include_examples 'autocorrect',
74
+ 'include_examples :foo_bar_baz',
75
+ "include_examples 'foo bar baz'"
76
+ include_examples 'autocorrect',
77
+ "include_examples :foo_bar_baz, 'foo', 'bar'",
78
+ "include_examples 'foo bar baz', 'foo', 'bar'"
79
+
80
+ bad_code_with_block = <<-RUBY
81
+ shared_examples :foo_bar_baz, 'foo', 'bar' do |param|
82
+ # ...
83
+ end
84
+ RUBY
85
+
86
+ good_code_with_block = <<-RUBY
87
+ shared_examples 'foo bar baz', 'foo', 'bar' do |param|
88
+ # ...
89
+ end
90
+ RUBY
91
+
92
+ include_examples 'autocorrect', bad_code_with_block, good_code_with_block
93
+ end
@@ -2,7 +2,7 @@ require 'rubocop'
2
2
 
3
3
  require 'rubocop/rspec/support'
4
4
 
5
- if ENV['CI']
5
+ if ENV['COVERAGE'] == 'true'
6
6
  require 'simplecov'
7
7
  SimpleCov.start
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.24.0
4
+ version: 1.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Backus
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-03-06 00:00:00.000000000 Z
13
+ date: 2018-04-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -120,6 +120,7 @@ files:
120
120
  - lib/rubocop/cop/rspec/align_right_let_brace.rb
121
121
  - lib/rubocop/cop/rspec/any_instance.rb
122
122
  - lib/rubocop/cop/rspec/around_block.rb
123
+ - lib/rubocop/cop/rspec/be.rb
123
124
  - lib/rubocop/cop/rspec/be_eql.rb
124
125
  - lib/rubocop/cop/rspec/before_after_all.rb
125
126
  - lib/rubocop/cop/rspec/capybara/current_path_expectation.rb
@@ -140,6 +141,7 @@ files:
140
141
  - lib/rubocop/cop/rspec/expect_change.rb
141
142
  - lib/rubocop/cop/rspec/expect_in_hook.rb
142
143
  - lib/rubocop/cop/rspec/expect_output.rb
144
+ - lib/rubocop/cop/rspec/factory_bot/create_list.rb
143
145
  - lib/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically.rb
144
146
  - lib/rubocop/cop/rspec/factory_bot/static_attribute_defined_dynamically.rb
145
147
  - lib/rubocop/cop/rspec/file_path.rb
@@ -164,6 +166,7 @@ files:
164
166
  - lib/rubocop/cop/rspec/nested_groups.rb
165
167
  - lib/rubocop/cop/rspec/not_to_not.rb
166
168
  - lib/rubocop/cop/rspec/overwriting_setup.rb
169
+ - lib/rubocop/cop/rspec/pending.rb
167
170
  - lib/rubocop/cop/rspec/predicate_matcher.rb
168
171
  - lib/rubocop/cop/rspec/rails/http_status.rb
169
172
  - lib/rubocop/cop/rspec/repeated_description.rb
@@ -172,6 +175,7 @@ files:
172
175
  - lib/rubocop/cop/rspec/scattered_let.rb
173
176
  - lib/rubocop/cop/rspec/scattered_setup.rb
174
177
  - lib/rubocop/cop/rspec/shared_context.rb
178
+ - lib/rubocop/cop/rspec/shared_examples.rb
175
179
  - lib/rubocop/cop/rspec/single_argument_message_chain.rb
176
180
  - lib/rubocop/cop/rspec/subject_stub.rb
177
181
  - lib/rubocop/cop/rspec/verified_doubles.rb
@@ -190,6 +194,7 @@ files:
190
194
  - lib/rubocop/rspec/inject.rb
191
195
  - lib/rubocop/rspec/language.rb
192
196
  - lib/rubocop/rspec/language/node_pattern.rb
197
+ - lib/rubocop/rspec/node.rb
193
198
  - lib/rubocop/rspec/top_level_describe.rb
194
199
  - lib/rubocop/rspec/util.rb
195
200
  - lib/rubocop/rspec/version.rb
@@ -203,6 +208,7 @@ files:
203
208
  - spec/rubocop/cop/rspec/any_instance_spec.rb
204
209
  - spec/rubocop/cop/rspec/around_block_spec.rb
205
210
  - spec/rubocop/cop/rspec/be_eql_spec.rb
211
+ - spec/rubocop/cop/rspec/be_spec.rb
206
212
  - spec/rubocop/cop/rspec/before_after_all_spec.rb
207
213
  - spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb
208
214
  - spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb
@@ -222,6 +228,7 @@ files:
222
228
  - spec/rubocop/cop/rspec/expect_change_spec.rb
223
229
  - spec/rubocop/cop/rspec/expect_in_hook_spec.rb
224
230
  - spec/rubocop/cop/rspec/expect_output_spec.rb
231
+ - spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb
225
232
  - spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb
226
233
  - spec/rubocop/cop/rspec/factory_bot/static_attribute_defined_dynamically_spec.rb
227
234
  - spec/rubocop/cop/rspec/file_path_spec.rb
@@ -246,6 +253,7 @@ files:
246
253
  - spec/rubocop/cop/rspec/nested_groups_spec.rb
247
254
  - spec/rubocop/cop/rspec/not_to_not_spec.rb
248
255
  - spec/rubocop/cop/rspec/overwriting_setup_spec.rb
256
+ - spec/rubocop/cop/rspec/pending_spec.rb
249
257
  - spec/rubocop/cop/rspec/predicate_matcher_spec.rb
250
258
  - spec/rubocop/cop/rspec/rails/http_status_spec.rb
251
259
  - spec/rubocop/cop/rspec/repeated_description_spec.rb
@@ -254,6 +262,7 @@ files:
254
262
  - spec/rubocop/cop/rspec/scattered_let_spec.rb
255
263
  - spec/rubocop/cop/rspec/scattered_setup_spec.rb
256
264
  - spec/rubocop/cop/rspec/shared_context_spec.rb
265
+ - spec/rubocop/cop/rspec/shared_examples_spec.rb
257
266
  - spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb
258
267
  - spec/rubocop/cop/rspec/subject_stub_spec.rb
259
268
  - spec/rubocop/cop/rspec/verified_doubles_spec.rb
@@ -270,10 +279,12 @@ files:
270
279
  - spec/shared/detects_style_behavior.rb
271
280
  - spec/spec_helper.rb
272
281
  - spec/support/expect_offense.rb
273
- homepage: http://github.com/backus/rubocop-rspec
282
+ homepage: https://github.com/rubocop-rspec/rubocop-rspec
274
283
  licenses:
275
284
  - MIT
276
- metadata: {}
285
+ metadata:
286
+ changelog_uri: https://github.com/rubocop-rspec/rubocop-rspec/blob/master/CHANGELOG.md
287
+ documentation_uri: https://rubocop-rspec.readthedocs.io/
277
288
  post_install_message:
278
289
  rdoc_options: []
279
290
  require_paths:
@@ -303,6 +314,7 @@ test_files:
303
314
  - spec/rubocop/cop/rspec/any_instance_spec.rb
304
315
  - spec/rubocop/cop/rspec/around_block_spec.rb
305
316
  - spec/rubocop/cop/rspec/be_eql_spec.rb
317
+ - spec/rubocop/cop/rspec/be_spec.rb
306
318
  - spec/rubocop/cop/rspec/before_after_all_spec.rb
307
319
  - spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb
308
320
  - spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb
@@ -322,6 +334,7 @@ test_files:
322
334
  - spec/rubocop/cop/rspec/expect_change_spec.rb
323
335
  - spec/rubocop/cop/rspec/expect_in_hook_spec.rb
324
336
  - spec/rubocop/cop/rspec/expect_output_spec.rb
337
+ - spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb
325
338
  - spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb
326
339
  - spec/rubocop/cop/rspec/factory_bot/static_attribute_defined_dynamically_spec.rb
327
340
  - spec/rubocop/cop/rspec/file_path_spec.rb
@@ -346,6 +359,7 @@ test_files:
346
359
  - spec/rubocop/cop/rspec/nested_groups_spec.rb
347
360
  - spec/rubocop/cop/rspec/not_to_not_spec.rb
348
361
  - spec/rubocop/cop/rspec/overwriting_setup_spec.rb
362
+ - spec/rubocop/cop/rspec/pending_spec.rb
349
363
  - spec/rubocop/cop/rspec/predicate_matcher_spec.rb
350
364
  - spec/rubocop/cop/rspec/rails/http_status_spec.rb
351
365
  - spec/rubocop/cop/rspec/repeated_description_spec.rb
@@ -354,6 +368,7 @@ test_files:
354
368
  - spec/rubocop/cop/rspec/scattered_let_spec.rb
355
369
  - spec/rubocop/cop/rspec/scattered_setup_spec.rb
356
370
  - spec/rubocop/cop/rspec/shared_context_spec.rb
371
+ - spec/rubocop/cop/rspec/shared_examples_spec.rb
357
372
  - spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb
358
373
  - spec/rubocop/cop/rspec/subject_stub_spec.rb
359
374
  - spec/rubocop/cop/rspec/verified_doubles_spec.rb