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,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::RSpec::Language::SelectorSet do
4
- subject(:selector_set) { described_class.new(%i[foo bar]) }
5
-
6
- it 'composes sets' do
7
- combined = selector_set + described_class.new(%i[baz])
8
-
9
- expect(combined).to eq(described_class.new(%i[foo bar baz]))
10
- end
11
-
12
- it 'compares by value' do
13
- expect(selector_set).not_to eq(described_class.new(%i[foo bar baz]))
14
- end
15
-
16
- describe '#include?' do
17
- it 'returns false for selectors not in the set' do
18
- expect(selector_set.include?(:baz)).to be(false)
19
- end
20
-
21
- it 'returns true for selectors in the set' do
22
- expect(selector_set.include?(:foo)).to be(true)
23
- end
24
- end
25
-
26
- describe '#node_pattern' do
27
- it 'builds a node pattern' do
28
- expect(selector_set.node_pattern).to eql(':foo :bar')
29
- end
30
- end
31
-
32
- describe '#node_pattern_union' do
33
- it 'builds a node pattern union' do
34
- expect(selector_set.node_pattern_union).to eql('{:foo :bar}')
35
- end
36
- end
37
-
38
- describe '#send_pattern' do
39
- it 'builds a send matching pattern' do
40
- expect(selector_set.send_pattern).to eql(
41
- '(send {(const {nil? cbase} :RSpec) nil?} {:foo :bar} ...)'
42
- )
43
- end
44
- end
45
-
46
- describe '#block_pattern' do
47
- it 'builds a block matching pattern' do
48
- expect(selector_set.block_pattern).to eql(
49
- '(block (send {(const {nil? cbase} :RSpec) nil?} {:foo :bar} ...) ...)'
50
- )
51
- end
52
- end
53
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::RSpec::Util, '.one' do
4
- let(:first) { instance_double(Object) }
5
- let(:array) { instance_double(Array, one?: true, first: first) }
6
- let(:client) { Class.new.extend(described_class) }
7
-
8
- it 'returns first element' do
9
- expect(client.one(array)).to be(first)
10
- end
11
-
12
- it 'fails if the list is empty' do
13
- expect { client.one([]) }
14
- .to raise_error(described_class::SizeError)
15
- .with_message('expected size to be exactly 1 but size was 0')
16
- end
17
-
18
- it 'fails if the list has more than one element' do
19
- expect { client.one([1, 2]) }
20
- .to raise_error(described_class::SizeError)
21
- .with_message('expected size to be exactly 1 but size was 2')
22
- end
23
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::RSpec::Wording do
4
- let(:replacements) { { 'have' => 'has' } }
5
- let(:ignores) { %w[only really] }
6
-
7
- expected_rewrites =
8
- {
9
- 'should return something' => 'returns something',
10
- 'should not return something' => 'does not return something',
11
- 'should do nothing' => 'does nothing',
12
- 'should have sweets' => 'has sweets',
13
- 'should worry about the future' => 'worries about the future',
14
- 'should pay for pizza' => 'pays for pizza',
15
- 'should obey my orders' => 'obeys my orders',
16
- 'should deploy the app' => 'deploys the app',
17
- 'should buy the product' => 'buys the product',
18
- 'should miss me' => 'misses me',
19
- 'should fax the document' => 'faxes the document',
20
- 'should amass debt' => 'amasses debt',
21
- 'should echo the input' => 'echoes the input',
22
- 'should alias the method' => 'aliases the method',
23
- 'should search the internet' => 'searches the internet',
24
- 'should wish me luck' => 'wishes me luck',
25
- 'should really only return one item' => 'really only returns one item',
26
- "shouldn't return something" => 'does not return something',
27
- 'SHOULD RETAIN UPPERCASE' => 'RETAINS UPPERCASE',
28
- "shouldn't be true" => 'is not true',
29
- "SHOULDN'T BE true" => 'IS NOT true',
30
- "SHOULDN'T NOT RETAIN UPPERCASE" => 'DOES NOT NOT RETAIN UPPERCASE',
31
- 'should WORRY' => 'WORRIES',
32
- 'should WISH me luck' => 'WISHES me luck',
33
- '' => '',
34
- 'should' => '',
35
- "shouldn't" => 'does not',
36
- 'should not' => 'does not',
37
- 'should fizz' => 'fizzes'
38
- }
39
-
40
- expected_rewrites.each do |old, new|
41
- it %(rewrites "#{old}" as "#{new}") do
42
- rewrite =
43
- described_class.new(
44
- old,
45
- replace: replacements,
46
- ignore: ignores
47
- ).rewrite
48
-
49
- expect(rewrite).to eql(new)
50
- end
51
- end
52
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples 'autocorrect' do |original, corrected|
4
- it "autocorrects `#{original}` to `#{corrected}`" do
5
- autocorrected = autocorrect_source(original, 'spec/foo_spec.rb')
6
-
7
- expect(autocorrected).to eql(corrected)
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples 'detects style' do |source, style, filename: 'x_spec.rb'|
4
- it 'generates a todo based on the detected style' do
5
- inspect_source(source, filename)
6
-
7
- expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => style)
8
- end
9
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples 'smoke test', type: :cop_spec do
4
- context 'with default configuration' do
5
- # This is overridden to avoid a number of specs that define `cop_config`
6
- # (so it is referenced in the 'config' shared context) but do not define
7
- # all of the dependent configuration options until inside of a context
8
- # that is out of scope, causing a NameError.
9
- let(:cop_config) { {} }
10
-
11
- stress_tests = Pathname.glob('spec/smoke_tests/*.rb')
12
-
13
- raise 'No smoke tests could be found!' if stress_tests.empty?
14
-
15
- stress_tests.each do |path|
16
- it "does not crash on smoke test: #{path}" do
17
- source = path.read
18
- file_name = path.to_s
19
-
20
- aggregate_failures do
21
- expect { inspect_source(source, file_name) }.not_to raise_error
22
- expect { autocorrect_source(source, file_name) }.not_to raise_error
23
- end
24
- end
25
- end
26
- end
27
- end
File without changes
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Since FactoryBot is not a dependency, none of this should be executed. We just
4
- # need the AST to exist.
5
- if false
6
- FactoryBot.define do
7
- factory :foo do
8
- bar {}
9
- end
10
- end
11
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal:
2
-
3
- # This is sort of a test, but there's no rspec to see here.
4
- raise 'Uh oh, the Party seems to have gotten into ruby.' if 2 + 2 == 5
@@ -1,233 +0,0 @@
1
- RSpec.describe 'Weirdness' do
2
- subject! { nil }
3
- subject { nil }
4
- subject(:foo) { nil }
5
- subject!(:foo) { nil }
6
-
7
- subject! (:foo) { |something| nil }
8
- subject :foo do end
9
-
10
- let(:foo) { |something| something }
11
- let (:foo) { 1 }
12
- let! (:bar){}
13
-
14
- let :a do end
15
-
16
- let(:bar) { <<-HEREDOC }
17
- What a pain.
18
- HEREDOC
19
-
20
- let(:bar) { <<-'HEREDOC' }
21
- Even odder.
22
- HEREDOC
23
-
24
- let(:baz) do
25
- <<-INSIDE
26
- Hi. I'm in your lets.
27
- INSIDE
28
- end
29
-
30
- let(:hi) {}
31
- let(:bye) do
32
- end
33
-
34
- let(:doop) { foo; 1 }
35
-
36
- it {}
37
- specify {}
38
-
39
- it 'works', metadata: true do
40
- end
41
-
42
- describe {}
43
- context {}
44
-
45
- describe '#nothing' do
46
- end
47
-
48
- it 'is empty' do
49
- end
50
-
51
- it '' do end
52
- describe do end
53
- context do end
54
- shared_examples 'a' do end
55
-
56
- describe 'things' do
57
- context 'with context' do
58
- end
59
- end
60
-
61
- shared_examples 'weird rspec' do
62
- end
63
-
64
- shared_examples :something do
65
- end
66
-
67
- context 'test' do
68
- include_examples 'weird rspec'
69
- include_examples('weird rspec', serious: true) do
70
- it_behaves_like :something
71
- end
72
- end
73
-
74
- it_behaves_like :something
75
- it_should_behave_like :something
76
-
77
- it_behaves_like :something do
78
- let(:foo) { 'bar' }
79
- end
80
-
81
- it_behaves_like(:something) do |arg, *args, &block|
82
- end
83
-
84
- before {}
85
- context 'never run' do
86
- around {}
87
- end
88
- after {}
89
-
90
- before { <<-DOC }
91
- Eh, what's up?
92
- DOC
93
-
94
- around { |test| test.run; <<-DOC }
95
- Eh, what's up?
96
- DOC
97
-
98
- after { <<-DOC }
99
- Eh, what's up?
100
- DOC
101
-
102
- around do |test|
103
- test.run
104
- end
105
-
106
- it 'is expecting you' do
107
- expect('you').to eql('you')
108
- end
109
-
110
- it 'is expecting you not to raise an error' do
111
- expect { 'you' }.not_to raise_error
112
- end
113
-
114
- it 'has chained expectations' do
115
- expect('you').to eql('you').and(match(/y/))
116
- end
117
-
118
- %w[who likes dynamic examples].each do |word|
119
- let(word) { word }
120
-
121
- describe "#{word}" do
122
- context "#{word}" do
123
- it "lets the word '#{word}' be '#{word}'" do
124
- expect(send(word)).to eql(word)
125
- end
126
- end
127
- end
128
- end
129
-
130
- it { foo; 1 && 2}
131
- it('has a description too') { foo; 1 && 2}
132
-
133
- it %{quotes a string weird} do
134
- end
135
-
136
- it((' '.strip! ; 1 && 'isnt a simple string')) do
137
- expect(nil).to be(nil)
138
- end
139
-
140
- it((' '.strip! ; 1 && 'isnt a simple string')) do
141
- double = double(:foo)
142
-
143
- allow(double).to receive(:oogabooga).with(nil).and_return(nil)
144
-
145
- expect(double.oogabooga(nil)).to be(nil)
146
-
147
- expect(double).to have_received(:oogabooga).once
148
- end
149
-
150
- it 'uses a matcher' do
151
- expect([].empty?).to be(true)
152
- expect([]).to be_empty
153
- end
154
-
155
- let(:klass) do
156
- Class.new do
157
- def initialize(thing)
158
- @thing = thing
159
- end
160
-
161
- def announce
162
- 'wooo, so dynamic!'
163
- end
164
- end
165
- end
166
-
167
- it 'it does a thing' do
168
- end
169
-
170
- it 'It does a thing' do
171
- end
172
-
173
- it 'should not do the thing' do
174
- end
175
-
176
- specify do
177
- foo = double(:bar)
178
- allow(foo).to receive_message_chain(bar: 42, baz: 42)
179
- allow(foo).to receive(:bar)
180
- allow(foo).to receive_messages(bar: 42, baz: 42)
181
- end
182
- end
183
-
184
- RSpec.describe {}
185
- RSpec.shared_examples('pointless') {}
186
- RSpec.shared_context('even pointless-er') {}
187
- RSpec.describe do end
188
- RSpec.shared_examples('pointless2') do end
189
- RSpec.shared_context('even pointless-er2') do end
190
-
191
- class Broken
192
- end
193
-
194
- RSpec.describe Broken do
195
- end
196
-
197
- RSpec.describe 'RubocopBug' do
198
- subject { true }
199
-
200
- before do
201
- each_row = allow(double(:exporter)).to receive(:each_row)
202
-
203
- [1, 2].each do |sig|
204
- each_row = each_row.and_yield(sig)
205
- end
206
- end
207
-
208
- it 'has a single example' do
209
- expect(subject).to be_truthy
210
- end
211
-
212
- it 'has an expectation' do
213
- stats = double(event: nil)
214
-
215
- stats.event('tada!')
216
-
217
- expect(stats)
218
- .to have_received(:event)
219
- .with('tada!')
220
- end
221
- end
222
-
223
- RSpec.describe do
224
- let(:uh_oh) { <<-HERE.strip + ", #{<<-THERE.strip}" }
225
- Seriously
226
- HERE
227
- who designed these things?
228
- THERE
229
-
230
- it 'is insane' do
231
- expect(uh_oh).to eql('Seriously, who designed these things?')
232
- end
233
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubocop'
4
-
5
- require 'rubocop/rspec/support'
6
-
7
- if ENV['COVERAGE'] == 'true'
8
- require 'simplecov'
9
- SimpleCov.start
10
- end
11
-
12
- module SpecHelper
13
- ROOT = Pathname.new(__dir__).parent.freeze
14
- end
15
-
16
- spec_helper_glob = File.expand_path('{support,shared}/*.rb', __dir__)
17
- Dir.glob(spec_helper_glob).map(&method(:require))
18
-
19
- RSpec.configure do |config|
20
- config.define_derived_metadata(file_path: %r{/spec/rubocop/cop/}) do |meta|
21
- meta[:type] = :cop_spec
22
- end
23
-
24
- config.order = :random
25
-
26
- # Forbid RSpec from monkey patching any of our objects
27
- config.disable_monkey_patching!
28
-
29
- # We should address configuration warnings when we upgrade
30
- config.raise_errors_for_deprecations!
31
-
32
- # RSpec gives helpful warnings when you are doing something wrong.
33
- # We should take their advice!
34
- config.raise_on_warning = true
35
-
36
- config.include(ExpectOffense)
37
- end
38
-
39
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
40
- $LOAD_PATH.unshift(File.dirname(__FILE__))
41
-
42
- require 'rubocop-rspec'