rubocop-rspec 1.32.0 → 1.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/Gemfile +2 -0
  4. data/Rakefile +2 -0
  5. data/config/default.yml +6 -0
  6. data/lib/rubocop-rspec.rb +3 -0
  7. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +1 -1
  8. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +1 -1
  9. data/lib/rubocop/cop/rspec/any_instance.rb +3 -1
  10. data/lib/rubocop/cop/rspec/around_block.rb +4 -2
  11. data/lib/rubocop/cop/rspec/be.rb +4 -2
  12. data/lib/rubocop/cop/rspec/be_eql.rb +3 -1
  13. data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
  14. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -3
  15. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -3
  16. data/lib/rubocop/cop/rspec/context_wording.rb +2 -2
  17. data/lib/rubocop/cop/rspec/describe_class.rb +4 -4
  18. data/lib/rubocop/cop/rspec/describe_method.rb +2 -2
  19. data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
  20. data/lib/rubocop/cop/rspec/described_class.rb +3 -3
  21. data/lib/rubocop/cop/rspec/dialect.rb +76 -0
  22. data/lib/rubocop/cop/rspec/empty_example_group.rb +1 -1
  23. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
  24. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
  25. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
  26. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +1 -1
  27. data/lib/rubocop/cop/rspec/example_length.rb +1 -1
  28. data/lib/rubocop/cop/rspec/example_without_description.rb +2 -2
  29. data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
  30. data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
  31. data/lib/rubocop/cop/rspec/expect_change.rb +2 -2
  32. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  33. data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
  34. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +21 -40
  35. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +2 -2
  36. data/lib/rubocop/cop/rspec/file_path.rb +2 -2
  37. data/lib/rubocop/cop/rspec/focus.rb +3 -3
  38. data/lib/rubocop/cop/rspec/hook_argument.rb +4 -6
  39. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -5
  40. data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -2
  41. data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -1
  42. data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
  43. data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
  44. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +4 -2
  45. data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -1
  46. data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
  47. data/lib/rubocop/cop/rspec/leading_subject.rb +1 -2
  48. data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -5
  49. data/lib/rubocop/cop/rspec/let_setup.rb +1 -1
  50. data/lib/rubocop/cop/rspec/message_chain.rb +3 -1
  51. data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
  52. data/lib/rubocop/cop/rspec/message_spies.rb +3 -4
  53. data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
  54. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
  55. data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
  56. data/lib/rubocop/cop/rspec/multiple_subjects.rb +6 -2
  57. data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
  58. data/lib/rubocop/cop/rspec/nested_groups.rb +3 -4
  59. data/lib/rubocop/cop/rspec/not_to_not.rb +3 -1
  60. data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
  61. data/lib/rubocop/cop/rspec/pending.rb +3 -3
  62. data/lib/rubocop/cop/rspec/predicate_matcher.rb +17 -14
  63. data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -2
  64. data/lib/rubocop/cop/rspec/receive_counts.rb +5 -6
  65. data/lib/rubocop/cop/rspec/receive_never.rb +4 -7
  66. data/lib/rubocop/cop/rspec/repeated_description.rb +3 -1
  67. data/lib/rubocop/cop/rspec/repeated_example.rb +3 -1
  68. data/lib/rubocop/cop/rspec/return_from_stub.rb +2 -2
  69. data/lib/rubocop/cop/rspec/scattered_let.rb +1 -1
  70. data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
  71. data/lib/rubocop/cop/rspec/shared_context.rb +2 -2
  72. data/lib/rubocop/cop/rspec/shared_examples.rb +7 -7
  73. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +3 -1
  74. data/lib/rubocop/cop/rspec/subject_stub.rb +1 -1
  75. data/lib/rubocop/cop/rspec/unspecified_exception.rb +5 -3
  76. data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -2
  77. data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
  78. data/lib/rubocop/cop/rspec/yield.rb +2 -4
  79. data/lib/rubocop/cop/rspec_cops.rb +3 -0
  80. data/lib/rubocop/rspec.rb +2 -0
  81. data/lib/rubocop/rspec/blank_line_separation.rb +3 -1
  82. data/lib/rubocop/rspec/config_formatter.rb +3 -1
  83. data/lib/rubocop/rspec/description_extractor.rb +3 -1
  84. data/lib/rubocop/rspec/factory_bot.rb +58 -0
  85. data/lib/rubocop/rspec/final_end_location.rb +2 -0
  86. data/lib/rubocop/rspec/inject.rb +2 -0
  87. data/lib/rubocop/rspec/language.rb +9 -2
  88. data/lib/rubocop/rspec/top_level_describe.rb +2 -0
  89. data/lib/rubocop/rspec/version.rb +1 -1
  90. data/rubocop-rspec.gemspec +3 -1
  91. data/spec/project/changelog_spec.rb +2 -0
  92. data/spec/project/default_config_spec.rb +2 -0
  93. data/spec/project/project_requires_spec.rb +2 -0
  94. data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +22 -37
  95. data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +21 -36
  96. data/spec/rubocop/cop/rspec/any_instance_spec.rb +2 -0
  97. data/spec/rubocop/cop/rspec/around_block_spec.rb +2 -0
  98. data/spec/rubocop/cop/rspec/be_eql_spec.rb +25 -4
  99. data/spec/rubocop/cop/rspec/be_spec.rb +2 -0
  100. data/spec/rubocop/cop/rspec/before_after_all_spec.rb +2 -0
  101. data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +2 -0
  102. data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +2 -0
  103. data/spec/rubocop/cop/rspec/context_wording_spec.rb +32 -0
  104. data/spec/rubocop/cop/rspec/describe_class_spec.rb +2 -0
  105. data/spec/rubocop/cop/rspec/describe_method_spec.rb +2 -0
  106. data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +2 -0
  107. data/spec/rubocop/cop/rspec/described_class_spec.rb +4 -1
  108. data/spec/rubocop/cop/rspec/dialect_spec.rb +78 -0
  109. data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +40 -21
  110. data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +77 -69
  111. data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +24 -19
  112. data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +16 -19
  113. data/spec/rubocop/cop/rspec/example_length_spec.rb +2 -0
  114. data/spec/rubocop/cop/rspec/example_without_description_spec.rb +2 -0
  115. data/spec/rubocop/cop/rspec/example_wording_spec.rb +45 -24
  116. data/spec/rubocop/cop/rspec/expect_change_spec.rb +22 -14
  117. data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +36 -0
  118. data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +2 -0
  119. data/spec/rubocop/cop/rspec/file_path_spec.rb +2 -0
  120. data/spec/rubocop/cop/rspec/focus_spec.rb +2 -2
  121. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +2 -0
  122. data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +47 -32
  123. data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +20 -19
  124. data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +56 -68
  125. data/spec/rubocop/cop/rspec/instance_spy_spec.rb +16 -15
  126. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +2 -0
  127. data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +2 -0
  128. data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +10 -12
  129. data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +2 -0
  130. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +31 -47
  131. data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +27 -26
  132. data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -0
  133. data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +2 -0
  134. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +2 -0
  135. data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +24 -37
  136. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +22 -32
  137. data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +2 -0
  138. data/spec/rubocop/cop/rspec/pending_spec.rb +2 -0
  139. data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +2 -0
  140. data/spec/rubocop/cop/rspec/receive_counts_spec.rb +47 -8
  141. data/spec/rubocop/cop/rspec/receive_never_spec.rb +16 -4
  142. data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +95 -72
  143. data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -0
  144. data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +2 -0
  145. data/spec/rubocop/cop/rspec/shared_context_spec.rb +29 -34
  146. data/spec/rubocop/cop/rspec/shared_examples_spec.rb +16 -34
  147. data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +44 -48
  148. data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +2 -0
  149. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +2 -0
  150. data/spec/rubocop/cop/rspec/void_expect_spec.rb +2 -0
  151. data/spec/rubocop/cop/rspec/yield_spec.rb +22 -21
  152. data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
  153. data/spec/rubocop/rspec/description_extractor_spec.rb +2 -0
  154. data/spec/rubocop/rspec/language/selector_set_spec.rb +2 -0
  155. data/spec/rubocop/rspec/util/one_spec.rb +2 -0
  156. data/spec/rubocop/rspec/wording_spec.rb +2 -0
  157. data/spec/shared/autocorrect_behavior.rb +2 -0
  158. data/spec/shared/detects_style_behavior.rb +2 -0
  159. data/spec/shared/smoke_test_examples.rb +2 -0
  160. data/spec/spec_helper.rb +2 -0
  161. data/spec/support/expect_offense.rb +3 -1
  162. metadata +8 -4
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::UnspecifiedException do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do
2
4
  subject(:cop) { described_class.new(config) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::VoidExpect do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::Yield do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -6,6 +8,10 @@ RSpec.describe RuboCop::Cop::RSpec::Yield do
6
8
  allow(foo).to receive(:bar) { |&block| block.call }
7
9
  ^^^^^^^^^^^^^^^^^^^^^^^ Use `.and_yield`.
8
10
  RUBY
11
+
12
+ expect_correction(<<-RUBY)
13
+ allow(foo).to receive(:bar).and_yield
14
+ RUBY
9
15
  end
10
16
 
11
17
  it 'flags multiple `block.call`' do
@@ -16,6 +22,10 @@ RSpec.describe RuboCop::Cop::RSpec::Yield do
16
22
  block.call
17
23
  end
18
24
  RUBY
25
+
26
+ expect_correction(<<-RUBY)
27
+ allow(foo).to receive(:bar).and_yield.and_yield
28
+ RUBY
19
29
  end
20
30
 
21
31
  it 'flags `block.call` with arguments' do
@@ -23,6 +33,10 @@ RSpec.describe RuboCop::Cop::RSpec::Yield do
23
33
  allow(foo).to receive(:bar) { |&block| block.call(1, 2) }
24
34
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `.and_yield`.
25
35
  RUBY
36
+
37
+ expect_correction(<<-RUBY)
38
+ allow(foo).to receive(:bar).and_yield(1, 2)
39
+ RUBY
26
40
  end
27
41
 
28
42
  it 'flags multiple `block.call` with arguments' do
@@ -33,6 +47,10 @@ RSpec.describe RuboCop::Cop::RSpec::Yield do
33
47
  block.call(2)
34
48
  end
35
49
  RUBY
50
+
51
+ expect_correction(<<-RUBY)
52
+ allow(foo).to receive(:bar).and_yield(1).and_yield(2)
53
+ RUBY
36
54
  end
37
55
 
38
56
  it 'flags `block.call` when `receive` is chained' do
@@ -40,6 +58,10 @@ RSpec.describe RuboCop::Cop::RSpec::Yield do
40
58
  allow(foo).to receive(:bar).with(anything) { |&block| block.call }
41
59
  ^^^^^^^^^^^^^^^^^^^^^^^ Use `.and_yield`.
42
60
  RUBY
61
+
62
+ expect_correction(<<-RUBY)
63
+ allow(foo).to receive(:bar).with(anything).and_yield
64
+ RUBY
43
65
  end
44
66
 
45
67
  it 'ignores `receive` with no block arguments' do
@@ -56,25 +78,4 @@ RSpec.describe RuboCop::Cop::RSpec::Yield do
56
78
  end
57
79
  RUBY
58
80
  end
59
-
60
- include_examples 'autocorrect',
61
- 'allow(foo).to receive(:bar) { |&block| block.call }',
62
- 'allow(foo).to receive(:bar).and_yield'
63
-
64
- include_examples 'autocorrect',
65
- 'allow(foo).to receive(:bar) { |&block| block.call(1, 2) }',
66
- 'allow(foo).to receive(:bar).and_yield(1, 2)'
67
-
68
- bad_code = <<-RUBY
69
- allow(foo).to receive(:bar) do |&block|
70
- block.call(1)
71
- block.call(2)
72
- end
73
- RUBY
74
-
75
- good_code = <<-RUBY
76
- allow(foo).to receive(:bar).and_yield(1).and_yield(2)
77
- RUBY
78
-
79
- include_examples 'autocorrect', bad_code, good_code
80
81
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubocop/rspec/config_formatter'
2
4
 
3
5
  RSpec.describe RuboCop::RSpec::ConfigFormatter do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yard'
2
4
 
3
5
  require 'rubocop/rspec/description_extractor'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::RSpec::Language::SelectorSet do
2
4
  subject(:selector_set) { described_class.new(%i[foo bar]) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::RSpec::Util, '.one' do
2
4
  let(:first) { instance_double(Object) }
3
5
  let(:array) { instance_double(Array, one?: true, first: first) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::RSpec::Wording do
2
4
  let(:replacements) { { 'have' => 'has' } }
3
5
  let(:ignores) { %w[only really] }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_examples 'autocorrect' do |original, corrected|
2
4
  it "autocorrects `#{original}` to `#{corrected}`" do
3
5
  autocorrected = autocorrect_source(original, 'spec/foo_spec.rb')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_examples 'detects style' do |source, style, filename: 'x_spec.rb'|
2
4
  it 'generates a todo based on the detected style' do
3
5
  inspect_source(source, filename)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_examples 'smoke test', type: :cop_spec do
2
4
  context 'with default configuration' do
3
5
  # This is overridden to avoid a number of specs that define `cop_config`
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubocop'
2
4
 
3
5
  require 'rubocop/rspec/support'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # rubocop-rspec gem extension of RuboCop's ExpectOffense module.
2
4
  #
3
5
  # This mixin is the same as rubocop's ExpectOffense except the default
@@ -5,7 +7,7 @@
5
7
  module ExpectOffense
6
8
  include RuboCop::RSpec::ExpectOffense
7
9
 
8
- DEFAULT_FILENAME = 'example_spec.rb'.freeze
10
+ DEFAULT_FILENAME = 'example_spec.rb'
9
11
 
10
12
  def expect_offense(source, filename = DEFAULT_FILENAME)
11
13
  super
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.32.0
4
+ version: 1.33.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: 2019-01-27 00:00:00.000000000 Z
13
+ date: 2019-05-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -131,6 +131,7 @@ files:
131
131
  - lib/rubocop/cop/rspec/describe_method.rb
132
132
  - lib/rubocop/cop/rspec/describe_symbol.rb
133
133
  - lib/rubocop/cop/rspec/described_class.rb
134
+ - lib/rubocop/cop/rspec/dialect.rb
134
135
  - lib/rubocop/cop/rspec/empty_example_group.rb
135
136
  - lib/rubocop/cop/rspec/empty_line_after_example_group.rb
136
137
  - lib/rubocop/cop/rspec/empty_line_after_final_let.rb
@@ -197,6 +198,7 @@ files:
197
198
  - lib/rubocop/rspec/description_extractor.rb
198
199
  - lib/rubocop/rspec/example.rb
199
200
  - lib/rubocop/rspec/example_group.rb
201
+ - lib/rubocop/rspec/factory_bot.rb
200
202
  - lib/rubocop/rspec/final_end_location.rb
201
203
  - lib/rubocop/rspec/hook.rb
202
204
  - lib/rubocop/rspec/inject.rb
@@ -226,6 +228,7 @@ files:
226
228
  - spec/rubocop/cop/rspec/describe_method_spec.rb
227
229
  - spec/rubocop/cop/rspec/describe_symbol_spec.rb
228
230
  - spec/rubocop/cop/rspec/described_class_spec.rb
231
+ - spec/rubocop/cop/rspec/dialect_spec.rb
229
232
  - spec/rubocop/cop/rspec/empty_example_group_spec.rb
230
233
  - spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb
231
234
  - spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb
@@ -314,14 +317,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
314
317
  requirements:
315
318
  - - ">="
316
319
  - !ruby/object:Gem::Version
317
- version: 2.2.0
320
+ version: 2.3.0
318
321
  required_rubygems_version: !ruby/object:Gem::Requirement
319
322
  requirements:
320
323
  - - ">="
321
324
  - !ruby/object:Gem::Version
322
325
  version: '0'
323
326
  requirements: []
324
- rubygems_version: 3.0.1
327
+ rubygems_version: 3.0.3
325
328
  signing_key:
326
329
  specification_version: 4
327
330
  summary: Code style checking for RSpec files
@@ -344,6 +347,7 @@ test_files:
344
347
  - spec/rubocop/cop/rspec/describe_method_spec.rb
345
348
  - spec/rubocop/cop/rspec/describe_symbol_spec.rb
346
349
  - spec/rubocop/cop/rspec/described_class_spec.rb
350
+ - spec/rubocop/cop/rspec/dialect_spec.rb
347
351
  - spec/rubocop/cop/rspec/empty_example_group_spec.rb
348
352
  - spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb
349
353
  - spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb