rubocop-rspec 1.15.1 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -1
  3. data/Gemfile +0 -1
  4. data/config/default.yml +105 -0
  5. data/lib/rubocop-rspec.rb +27 -0
  6. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +51 -0
  7. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +51 -0
  8. data/lib/rubocop/cop/rspec/any_instance.rb +1 -1
  9. data/lib/rubocop/cop/rspec/cop.rb +4 -2
  10. data/lib/rubocop/cop/rspec/expect_in_hook.rb +61 -0
  11. data/lib/rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically.rb +84 -0
  12. data/lib/rubocop/cop/rspec/hook_argument.rb +11 -5
  13. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +42 -0
  14. data/lib/rubocop/cop/rspec/let_before_examples.rb +66 -0
  15. data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -5
  16. data/lib/rubocop/cop/rspec/multiple_subjects.rb +80 -0
  17. data/lib/rubocop/cop/rspec/named_subject.rb +5 -6
  18. data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
  19. data/lib/rubocop/cop/rspec/predicate_matcher.rb +337 -0
  20. data/lib/rubocop/cop/rspec/return_from_stub.rb +83 -0
  21. data/lib/rubocop/cop/rspec/void_expect.rb +52 -0
  22. data/lib/rubocop/rspec/align_let_brace.rb +64 -0
  23. data/lib/rubocop/rspec/config_formatter.rb +7 -4
  24. data/lib/rubocop/rspec/description_extractor.rb +2 -2
  25. data/lib/rubocop/rspec/example_group.rb +25 -2
  26. data/lib/rubocop/rspec/factory_girl.rb +7 -0
  27. data/lib/rubocop/rspec/language.rb +6 -1
  28. data/lib/rubocop/rspec/version.rb +1 -1
  29. data/rubocop-rspec.gemspec +1 -4
  30. data/spec/project/default_config_spec.rb +8 -4
  31. data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +62 -0
  32. data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +62 -0
  33. data/spec/rubocop/cop/rspec/any_instance_spec.rb +3 -3
  34. data/spec/rubocop/cop/rspec/around_block_spec.rb +11 -11
  35. data/spec/rubocop/cop/rspec/be_eql_spec.rb +7 -7
  36. data/spec/rubocop/cop/rspec/before_after_all_spec.rb +4 -4
  37. data/spec/rubocop/cop/rspec/cop_spec.rb +7 -7
  38. data/spec/rubocop/cop/rspec/describe_class_spec.rb +18 -18
  39. data/spec/rubocop/cop/rspec/describe_method_spec.rb +4 -4
  40. data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +6 -6
  41. data/spec/rubocop/cop/rspec/described_class_spec.rb +18 -18
  42. data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +5 -5
  43. data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +9 -9
  44. data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +5 -5
  45. data/spec/rubocop/cop/rspec/example_length_spec.rb +6 -6
  46. data/spec/rubocop/cop/rspec/example_wording_spec.rb +10 -10
  47. data/spec/rubocop/cop/rspec/expect_actual_spec.rb +10 -10
  48. data/spec/rubocop/cop/rspec/expect_in_hook_spec.rb +79 -0
  49. data/spec/rubocop/cop/rspec/expect_output_spec.rb +7 -7
  50. data/spec/rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically_spec.rb +87 -0
  51. data/spec/rubocop/cop/rspec/file_path_spec.rb +29 -29
  52. data/spec/rubocop/cop/rspec/focus_spec.rb +6 -6
  53. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +35 -23
  54. data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +10 -10
  55. data/spec/rubocop/cop/rspec/instance_spy_spec.rb +4 -4
  56. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +7 -7
  57. data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +37 -0
  58. data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +4 -4
  59. data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +8 -8
  60. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +5 -5
  61. data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +83 -0
  62. data/spec/rubocop/cop/rspec/let_setup_spec.rb +4 -4
  63. data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -2
  64. data/spec/rubocop/cop/rspec/message_expectation_spec.rb +4 -4
  65. data/spec/rubocop/cop/rspec/message_spies_spec.rb +18 -18
  66. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +3 -3
  67. data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +45 -9
  68. data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +96 -0
  69. data/spec/rubocop/cop/rspec/named_subject_spec.rb +4 -4
  70. data/spec/rubocop/cop/rspec/nested_groups_spec.rb +3 -3
  71. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +4 -4
  72. data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +4 -4
  73. data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +335 -0
  74. data/spec/rubocop/cop/rspec/repeated_description_spec.rb +5 -5
  75. data/spec/rubocop/cop/rspec/repeated_example_spec.rb +5 -5
  76. data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +85 -0
  77. data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -2
  78. data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +8 -8
  79. data/spec/rubocop/cop/rspec/shared_context_spec.rb +10 -10
  80. data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +10 -10
  81. data/spec/rubocop/cop/rspec/subject_stub_spec.rb +9 -9
  82. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +7 -7
  83. data/spec/rubocop/cop/rspec/void_expect_spec.rb +47 -0
  84. data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
  85. data/spec/spec_helper.rb +1 -1
  86. data/spec/support/expect_offense.rb +17 -0
  87. metadata +39 -51
  88. data/spec/expect_violation/expectation_spec.rb +0 -85
  89. data/spec/support/expect_violation.rb +0 -170
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a604474acdd504b70582e29579a8ec65a6bbbfa
4
- data.tar.gz: f8fa3ac1215089b95341115ca35edb73ddb148c3
3
+ metadata.gz: da531fd6da6c4bc5ffa7012451f5d496e876621d
4
+ data.tar.gz: 68cf66d909464963445c3d5edff27f434bea6d5c
5
5
  SHA512:
6
- metadata.gz: a0d4f97983ce7f1147d32b8948d22d5c7b30490a946e5500e2aa78f60daad47f9e68eac81e6da2825e83f8248a8a8ed4dfd538a30e4b7dcc9af462fee16bda2c
7
- data.tar.gz: dd3bc63ff868cef005a10da71f873dc804d333fd8950de8636d980064341b386a74e281ba698d051859c7c4ddceb7ee257d527ac68c7129fd660f7321014b9ac
6
+ metadata.gz: 4b97442d8f7fa551ffd4c85f76ca2bdfea664bc09a5ca5f3580f70c5c4f498da522017ef6a02b48caa0b8c8b9c6925f1edbfaf3f524265a6808b1cc01746732e
7
+ data.tar.gz: 4f228565a1e5842f9332b4af0dbd02084dc4203ab58c0f3f888560ac385af243ed66b4789596e621d669bdf1da1bdb3dd664f0d094981f54b525668b2fcc07a8
data/CHANGELOG.md CHANGED
@@ -2,13 +2,29 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 1.16.0 (2017-09-06)
6
+
7
+ * Add `RSpec/FactoryGirl` namespace including the first cop for factories: `FactoryGirl/DynamicAttributeDefinedStatically`. ([@jonatas][])
8
+ * Add disabled by default `RSpec/AlignLeftLetBrace`. ([@backus][])
9
+ * Add disabled by default `RSpec/AlignRightLetBrace`. ([@backus][])
10
+ * Add `RSpec/LetBeforeExamples` cop. ([@Darhazer][])
11
+ * Add `RSpec/MultipleSubjects` cop. ([@backus][])
12
+ * Add `RSpec/ReturnFromStub` cop. ([@Darhazer][])
13
+ * Add `RSpec/VoidExpect` cop. ([@pocke][])
14
+ * Add `RSpec/InvalidPredicateMatcher` cop. ([@pocke][])
15
+ * Change HookArgument cop to detect when hook has a receiver. ([@pocke][])
16
+ * Add `RSpec/PredicateMatcher` cop. ([@pocke][])
17
+ * Add `RSpec/ExpectInHook` cop. ([@pocke][])
18
+ * `RSpec/MultipleExpectations` now detects usage of expect_any_instance_of. ([@Darhazer][])
19
+ * `RSpec/MultipleExpectations` now detects usage of is_expected. ([@bmorrall][])
20
+
5
21
  ## 1.15.1 (2017-04-30)
6
22
 
7
23
  * Fix the handling of various edge cases in the `RSpec/ExampleWording` cop, including one that would cause autocorrect to crash. ([@dgollahon][])
8
24
  * Fix `RSpec/IteratedExpectation` crashing when there is an assignment in the iteration. ([@Darhazer][])
9
25
  * Fix false positive in `RSpec/SingleArgumentMessageChain` cop when the single argument is a hash. ([@Darhazer][])
10
26
 
11
- ## 1.15.0 (2017-03-26)
27
+ ## 1.15.0 (2017-03-24)
12
28
 
13
29
  * Add `RSpec/DescribeSymbol` cop. ([@tsigo][])
14
30
  * Fix error when `RSpec/OverwritingSetup` and `RSpec/ScatteredLet` analyzed empty example groups. ([@backus][])
@@ -218,3 +234,6 @@
218
234
  [@cfabianski]: https://github.com/cfabianski
219
235
  [@dgollahon]: https://github.com/dgollahon
220
236
  [@tsigo]: https://github.com/tsigo
237
+ [@jonatas]: https://github.com/jonatas
238
+ [@pocke]: https://github.com/pocke
239
+ [@bmorrall]: https:/github.com/bmorrall
data/Gemfile CHANGED
@@ -4,7 +4,6 @@ gemspec
4
4
 
5
5
  group :test do
6
6
  gem 'codeclimate-test-reporter', '~> 1.0.0'
7
- gem 'rubocop', '~> 0.47'
8
7
  gem 'simplecov', '~> 0.12.0', require: false
9
8
  end
10
9
 
data/config/default.yml CHANGED
@@ -4,18 +4,35 @@ AllCops:
4
4
  Patterns:
5
5
  - _spec.rb
6
6
  - "(?:^|/)spec/"
7
+ RSpec/FactoryGirl:
8
+ Patterns:
9
+ - spec/factories/**/*.rb
10
+ - features/support/factories/**/*.rb
7
11
 
8
12
  RSpec/AnyInstance:
9
13
  Description: Check that instances are not being stubbed globally.
10
14
  Enabled: true
15
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AnyInstance
11
16
 
12
17
  RSpec/AroundBlock:
13
18
  Description: Checks that around blocks actually run the test.
14
19
  Enabled: true
20
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AroundBlock
21
+
22
+ RSpec/AlignLeftLetBrace:
23
+ Description: Checks that left braces for adjacent single line lets are aligned.
24
+ Enabled: false
25
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AlignLeftLetBrace
26
+
27
+ RSpec/AlignRightLetBrace:
28
+ Description: Checks that right braces for adjacent single line lets are aligned.
29
+ Enabled: false
30
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AlignRightLetBrace
15
31
 
16
32
  RSpec/BeEql:
17
33
  Description: Check for expectations where `be(...)` can replace `eql(...)`.
18
34
  Enabled: true
35
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEql
19
36
 
20
37
  RSpec/BeforeAfterAll:
21
38
  Description: Check that before/after(:all) isn't being used.
@@ -24,10 +41,12 @@ RSpec/BeforeAfterAll:
24
41
  - spec/spec_helper.rb
25
42
  - spec/rails_helper.rb
26
43
  - spec/support/**/*.rb
44
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll
27
45
 
28
46
  RSpec/DescribeClass:
29
47
  Description: Check that the first argument to the top level describe is a constant.
30
48
  Enabled: true
49
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass
31
50
 
32
51
  RSpec/DescribedClass:
33
52
  Description: Checks that tests use `described_class`.
@@ -37,36 +56,44 @@ RSpec/DescribedClass:
37
56
  SupportedStyles:
38
57
  - described_class
39
58
  - explicit
59
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass
40
60
 
41
61
  RSpec/DescribeMethod:
42
62
  Description: Checks that the second argument to `describe` specifies a method.
43
63
  Enabled: true
64
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeMethod
44
65
 
45
66
  RSpec/DescribeSymbol:
46
67
  Description: Avoid describing symbols.
47
68
  Enabled: true
69
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeSymbol
48
70
 
49
71
  RSpec/IteratedExpectation:
50
72
  Description: Check that `all` matcher is used instead of iterating over an array.
51
73
  Enabled: true
74
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IteratedExpectation
52
75
 
53
76
  RSpec/EmptyExampleGroup:
54
77
  Description: Checks if an example group does not include any tests.
55
78
  Enabled: true
56
79
  CustomIncludeMethods: []
80
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup
57
81
 
58
82
  RSpec/EmptyLineAfterFinalLet:
59
83
  Description: Checks if there is an empty line after the last let block.
60
84
  Enabled: true
85
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet
61
86
 
62
87
  RSpec/EmptyLineAfterSubject:
63
88
  Description: Checks if there is an empty line after subject block.
64
89
  Enabled: true
90
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterSubject
65
91
 
66
92
  RSpec/ExampleLength:
67
93
  Description: Checks for long examples.
68
94
  Enabled: true
69
95
  Max: 5
96
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleLength
70
97
 
71
98
  RSpec/ExampleWording:
72
99
  Description: Checks for common mistakes in example descriptions.
@@ -77,16 +104,24 @@ RSpec/ExampleWording:
77
104
  have: has
78
105
  HAVE: HAS
79
106
  IgnoredWords: []
107
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWording
80
108
 
81
109
  RSpec/ExpectActual:
82
110
  Description: Checks for `expect(...)` calls containing literal values.
83
111
  Enabled: true
84
112
  Exclude:
85
113
  - spec/routing/**/*
114
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectActual
115
+
116
+ RSpec/ExpectInHook:
117
+ Enabled: true
118
+ Description: Do not use `expect` in hooks such as `before`.
119
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectInHook
86
120
 
87
121
  RSpec/ExpectOutput:
88
122
  Description: Checks for opportunities to use `expect { ... }.to output`.
89
123
  Enabled: true
124
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectOutput
90
125
 
91
126
  RSpec/FilePath:
92
127
  Description: Checks that spec file paths are consistent with the test subject.
@@ -95,10 +130,12 @@ RSpec/FilePath:
95
130
  RuboCop: rubocop
96
131
  RSpec: rspec
97
132
  IgnoreMethods: false
133
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FilePath
98
134
 
99
135
  RSpec/Focus:
100
136
  Description: Checks if examples are focused.
101
137
  Enabled: true
138
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Focus
102
139
 
103
140
  RSpec/HookArgument:
104
141
  Description: Checks the arguments passed to `before`, `around`, and `after`.
@@ -108,6 +145,7 @@ RSpec/HookArgument:
108
145
  - implicit
109
146
  - each
110
147
  - example
148
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HookArgument
111
149
 
112
150
  RSpec/ImplicitExpect:
113
151
  Description: Check that a consistent implicit expectation style is used.
@@ -116,15 +154,23 @@ RSpec/ImplicitExpect:
116
154
  SupportedStyles:
117
155
  - is_expected
118
156
  - should
157
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitExpect
119
158
 
120
159
  RSpec/InstanceSpy:
121
160
  Description: Checks for `instance_double` used with `have_received`.
122
161
  Enabled: true
162
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceSpy
123
163
 
124
164
  RSpec/InstanceVariable:
125
165
  Description: Checks for instance variable usage in specs.
126
166
  AssignmentOnly: false
127
167
  Enabled: true
168
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceVariable
169
+
170
+ RSpec/InvalidPredicateMatcher:
171
+ Description: Checks invalid usage for predicate matcher.
172
+ Enabled: true
173
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InvalidPredicateMatcher
128
174
 
129
175
  RSpec/ItBehavesLike:
130
176
  Description: Checks that only one `it_behaves_like` style is used.
@@ -133,18 +179,27 @@ RSpec/ItBehavesLike:
133
179
  SupportedStyles:
134
180
  - it_behaves_like
135
181
  - it_should_behave_like
182
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ItBehavesLike
136
183
 
137
184
  RSpec/LeadingSubject:
138
185
  Description: Checks for `subject` definitions that come after `let` definitions.
139
186
  Enabled: true
187
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LeadingSubject
188
+
189
+ RSpec/LetBeforeExamples:
190
+ Description: Checks for `let` definitions that come after an example.
191
+ Enabled: true
192
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetBeforeExamples
140
193
 
141
194
  RSpec/LetSetup:
142
195
  Description: Checks unreferenced `let!` calls being used for test setup.
143
196
  Enabled: true
197
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetSetup
144
198
 
145
199
  RSpec/MessageChain:
146
200
  Description: Check that chains of messages are not being stubbed.
147
201
  Enabled: true
202
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageChain
148
203
 
149
204
  RSpec/MessageExpectation:
150
205
  Description: Checks for consistent message expectation style.
@@ -153,6 +208,7 @@ RSpec/MessageExpectation:
153
208
  SupportedStyles:
154
209
  - allow
155
210
  - expect
211
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageExpectation
156
212
 
157
213
  RSpec/MessageSpies:
158
214
  Description: Checks that message expectations are set using spies.
@@ -161,24 +217,34 @@ RSpec/MessageSpies:
161
217
  SupportedStyles:
162
218
  - have_received
163
219
  - receive
220
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageSpies
164
221
 
165
222
  RSpec/MultipleDescribes:
166
223
  Description: Checks for multiple top level describes.
167
224
  Enabled: true
225
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleDescribes
168
226
 
169
227
  RSpec/MultipleExpectations:
170
228
  Description: Checks if examples contain too many `expect` calls.
171
229
  Enabled: true
172
230
  Max: 1
231
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleExpectations
232
+
233
+ RSpec/MultipleSubjects:
234
+ Description: Checks if an example group defines `subject` multiple times.
235
+ Enabled: true
236
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleSubjects
173
237
 
174
238
  RSpec/NamedSubject:
175
239
  Description: Checks for explicitly referenced test subjects.
176
240
  Enabled: true
241
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NamedSubject
177
242
 
178
243
  RSpec/NestedGroups:
179
244
  Description: Checks for nested example groups.
180
245
  Enabled: true
181
246
  Max: 3
247
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NestedGroups
182
248
 
183
249
  RSpec/NotToNot:
184
250
  Description: Checks for consistent method usage for negating expectations.
@@ -187,40 +253,79 @@ RSpec/NotToNot:
187
253
  - not_to
188
254
  - to_not
189
255
  Enabled: true
256
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NotToNot
190
257
 
191
258
  RSpec/OverwritingSetup:
192
259
  Enabled: true
193
260
  Description: Checks if there is a let/subject that overwrites an existing one.
261
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/OverwritingSetup
194
262
 
195
263
  RSpec/RepeatedDescription:
196
264
  Enabled: true
197
265
  Description: Check for repeated description strings in example groups.
266
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedDescription
198
267
 
199
268
  RSpec/RepeatedExample:
200
269
  Enabled: true
201
270
  Description: Check for repeated examples within example groups.
271
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExample
272
+
273
+ RSpec/ReturnFromStub:
274
+ Enabled: true
275
+ Description: Checks for consistent style of stub's return setting.
276
+ EnforcedStyle: and_return
277
+ SupportedStyles:
278
+ - and_return
279
+ - block
280
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReturnFromStub
202
281
 
203
282
  RSpec/SharedContext:
204
283
  Description: Checks for proper shared_context and shared_examples usage.
205
284
  Enabled: true
285
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SharedContext
206
286
 
207
287
  RSpec/SingleArgumentMessageChain:
208
288
  Description: Checks that chains of messages contain more than one element.
209
289
  Enabled: true
290
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SingleArgumentMessageChain
210
291
 
211
292
  RSpec/ScatteredLet:
212
293
  Description: Checks for let scattered across the example group.
213
294
  Enabled: true
295
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredLet
214
296
 
215
297
  RSpec/ScatteredSetup:
216
298
  Description: Checks for setup scattered across multiple hooks in an example group.
217
299
  Enabled: true
300
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredSetup
218
301
 
219
302
  RSpec/SubjectStub:
220
303
  Description: Checks for stubbed test subjects.
221
304
  Enabled: true
305
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SubjectStub
306
+
307
+ RSpec/PredicateMatcher:
308
+ Description: Prefer using predicate matcher over using predicate method directly.
309
+ Enabled: true
310
+ Strict: true
311
+ EnforcedStyle: inflected
312
+ SupportedStyles:
313
+ - inflected
314
+ - explicit
315
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/PredicateMatcher
222
316
 
223
317
  RSpec/VerifiedDoubles:
224
318
  Description: Prefer using verifying doubles over normal doubles.
225
319
  Enabled: true
226
320
  IgnoreSymbolicNames: false
321
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubles
322
+
323
+ RSpec/VoidExpect:
324
+ Description: This cop checks void `expect()`.
325
+ Enabled: true
326
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VoidExpect
327
+
328
+ FactoryGirl/DynamicAttributeDefinedStatically:
329
+ Description: Prefer declaring dynamic attribute values in a block.
330
+ Enabled: true
331
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/FactoryGirl/DynamicAttributeDefinedStatically
data/lib/rubocop-rspec.rb CHANGED
@@ -16,10 +16,14 @@ require 'rubocop/rspec/example_group'
16
16
  require 'rubocop/rspec/example'
17
17
  require 'rubocop/rspec/hook'
18
18
  require 'rubocop/cop/rspec/cop'
19
+ require 'rubocop/rspec/align_let_brace'
20
+ require 'rubocop/rspec/factory_girl'
19
21
 
20
22
  RuboCop::RSpec::Inject.defaults!
21
23
 
22
24
  # cops
25
+ require 'rubocop/cop/rspec/align_left_let_brace'
26
+ require 'rubocop/cop/rspec/align_right_let_brace'
23
27
  require 'rubocop/cop/rspec/any_instance'
24
28
  require 'rubocop/cop/rspec/around_block'
25
29
  require 'rubocop/cop/rspec/be_eql'
@@ -34,31 +38,54 @@ require 'rubocop/cop/rspec/empty_line_after_subject'
34
38
  require 'rubocop/cop/rspec/example_length'
35
39
  require 'rubocop/cop/rspec/example_wording'
36
40
  require 'rubocop/cop/rspec/expect_actual'
41
+ require 'rubocop/cop/rspec/expect_in_hook'
37
42
  require 'rubocop/cop/rspec/expect_output'
43
+ require 'rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically'
38
44
  require 'rubocop/cop/rspec/file_path'
39
45
  require 'rubocop/cop/rspec/focus'
40
46
  require 'rubocop/cop/rspec/hook_argument'
41
47
  require 'rubocop/cop/rspec/implicit_expect'
42
48
  require 'rubocop/cop/rspec/instance_spy'
43
49
  require 'rubocop/cop/rspec/instance_variable'
50
+ require 'rubocop/cop/rspec/invalid_predicate_matcher'
44
51
  require 'rubocop/cop/rspec/it_behaves_like'
45
52
  require 'rubocop/cop/rspec/iterated_expectation'
46
53
  require 'rubocop/cop/rspec/leading_subject'
54
+ require 'rubocop/cop/rspec/let_before_examples'
47
55
  require 'rubocop/cop/rspec/let_setup'
48
56
  require 'rubocop/cop/rspec/message_chain'
49
57
  require 'rubocop/cop/rspec/message_expectation'
50
58
  require 'rubocop/cop/rspec/message_spies'
51
59
  require 'rubocop/cop/rspec/multiple_describes'
52
60
  require 'rubocop/cop/rspec/multiple_expectations'
61
+ require 'rubocop/cop/rspec/multiple_subjects'
53
62
  require 'rubocop/cop/rspec/named_subject'
54
63
  require 'rubocop/cop/rspec/nested_groups'
55
64
  require 'rubocop/cop/rspec/not_to_not'
56
65
  require 'rubocop/cop/rspec/overwriting_setup'
57
66
  require 'rubocop/cop/rspec/repeated_description'
58
67
  require 'rubocop/cop/rspec/repeated_example'
68
+ require 'rubocop/cop/rspec/return_from_stub'
59
69
  require 'rubocop/cop/rspec/scattered_let'
60
70
  require 'rubocop/cop/rspec/scattered_setup'
61
71
  require 'rubocop/cop/rspec/shared_context'
62
72
  require 'rubocop/cop/rspec/single_argument_message_chain'
63
73
  require 'rubocop/cop/rspec/subject_stub'
74
+ require 'rubocop/cop/rspec/predicate_matcher'
64
75
  require 'rubocop/cop/rspec/verified_doubles'
76
+ require 'rubocop/cop/rspec/void_expect'
77
+
78
+ # We have to register our autocorrect incompatibilies in RuboCop's cops as well
79
+ # so we do not hit infinite loops
80
+
81
+ module RuboCop
82
+ module Cop
83
+ module Layout
84
+ class ExtraSpacing # rubocop:disable Style/Documentation
85
+ def self.autocorrect_incompatible_with
86
+ [RSpec::AlignLeftLetBrace, RSpec::AlignRightLetBrace]
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Checks that left braces for adjacent single line lets are aligned.
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ # let(:foobar) { blahblah }
12
+ # let(:baz) { bar }
13
+ # let(:a) { b }
14
+ #
15
+ # # good
16
+ # let(:foobar) { blahblah }
17
+ # let(:baz) { bar }
18
+ # let(:a) { b }
19
+ #
20
+ class AlignLeftLetBrace < Cop
21
+ MSG = 'Align left let brace'.freeze
22
+
23
+ def self.autocorrect_incompatible_with
24
+ [Layout::ExtraSpacing]
25
+ end
26
+
27
+ def investigate(_)
28
+ token_aligner.offending_tokens.each do |let|
29
+ add_offense(let, :begin)
30
+ end
31
+ end
32
+
33
+ def autocorrect(let)
34
+ lambda do |corrector|
35
+ corrector.insert_before(
36
+ let.loc.begin,
37
+ token_aligner.indent_for(let)
38
+ )
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def token_aligner
45
+ @token_aligner ||=
46
+ RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :begin)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end