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,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::LetSetup do
4
- subject(:cop) { described_class.new }
5
-
6
- it 'complains when let! is used and not referenced' do
7
- expect_offense(<<-RUBY)
8
- describe Foo do
9
- let!(:foo) { bar }
10
- ^^^^^^^^^^ Do not use `let!` to setup objects not referenced in tests.
11
-
12
- it 'does not use foo' do
13
- expect(baz).to eq(qux)
14
- end
15
- end
16
- RUBY
17
- end
18
-
19
- it 'ignores let! when used in `before`' do
20
- expect_no_offenses(<<-RUBY)
21
- describe Foo do
22
- let!(:foo) { bar }
23
-
24
- before do
25
- foo
26
- end
27
-
28
- it 'does not use foo' do
29
- expect(baz).to eq(qux)
30
- end
31
- end
32
- RUBY
33
- end
34
-
35
- it 'ignores let! when used in example' do
36
- expect_no_offenses(<<-RUBY)
37
- describe Foo do
38
- let!(:foo) { bar }
39
-
40
- it 'uses foo' do
41
- foo
42
- expect(baz).to eq(qux)
43
- end
44
- end
45
- RUBY
46
- end
47
-
48
- it 'complains when let! is used and not referenced within nested group' do
49
- expect_offense(<<-RUBY)
50
- describe Foo do
51
- context 'when something special happens' do
52
- let!(:foo) { bar }
53
- ^^^^^^^^^^ Do not use `let!` to setup objects not referenced in tests.
54
-
55
- it 'does not use foo' do
56
- expect(baz).to eq(qux)
57
- end
58
- end
59
-
60
- it 'references some other foo' do
61
- foo
62
- end
63
- end
64
- RUBY
65
- end
66
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::MessageChain do
4
- subject(:cop) { described_class.new }
5
-
6
- it 'finds `receive_message_chain`' do
7
- expect_offense(<<-RUBY)
8
- before do
9
- allow(foo).to receive_message_chain(:one, :two) { :three }
10
- ^^^^^^^^^^^^^^^^^^^^^ Avoid stubbing using `receive_message_chain`.
11
- end
12
- RUBY
13
- end
14
-
15
- it 'finds old `stub_chain` syntax' do
16
- expect_offense(<<-RUBY)
17
- before do
18
- foo.stub_chain(:one, :two).and_return(:three)
19
- ^^^^^^^^^^ Avoid stubbing using `stub_chain`.
20
- end
21
- RUBY
22
- end
23
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::MessageExpectation, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- context 'when EnforcedStyle is allow' do
7
- let(:cop_config) do
8
- { 'EnforcedStyle' => 'allow' }
9
- end
10
-
11
- it 'flags expect(...).to receive' do
12
- expect_offense(<<-RUBY)
13
- expect(foo).to receive(:bar)
14
- ^^^^^^ Prefer `allow` for setting message expectations.
15
- RUBY
16
- end
17
-
18
- it 'approves of allow(...).to receive' do
19
- expect_no_offenses('allow(foo).to receive(:bar)')
20
- end
21
-
22
- include_examples 'detects style', 'allow(foo).to receive(:bar)', 'allow'
23
- include_examples 'detects style', 'expect(foo).to receive(:bar)', 'expect'
24
- end
25
-
26
- context 'when EnforcedStyle is expect' do
27
- let(:cop_config) do
28
- { 'EnforcedStyle' => 'expect' }
29
- end
30
-
31
- it 'flags allow(...).to receive' do
32
- expect_offense(<<-RUBY)
33
- allow(foo).to receive(:bar)
34
- ^^^^^ Prefer `expect` for setting message expectations.
35
- RUBY
36
- end
37
-
38
- it 'approves of expect(...).to receive' do
39
- expect_no_offenses('expect(foo).to receive(:bar)')
40
- end
41
-
42
- include_examples 'detects style', 'expect(foo).to receive(:bar)', 'expect'
43
- include_examples 'detects style', 'allow(foo).to receive(:bar)', 'allow'
44
- end
45
- end
@@ -1,151 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::MessageSpies, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- context 'when EnforcedStyle is have_received' do
7
- let(:cop_config) do
8
- { 'EnforcedStyle' => 'have_received' }
9
- end
10
-
11
- it 'flags expect(send).to receive' do
12
- expect_offense(<<-RUBY)
13
- expect(foo).to receive(:bar)
14
- ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
15
- RUBY
16
- end
17
-
18
- it 'flags expect(lvar).to receive' do
19
- expect_offense(<<-RUBY)
20
- foo = baz
21
- expect(foo).to receive(:bar)
22
- ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
23
- RUBY
24
- end
25
-
26
- it 'flags expect(ivar).to receive' do
27
- expect_offense(<<-RUBY)
28
- expect(@foo).to receive(:bar)
29
- ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `@foo` as a spy using `allow` or `instance_spy`.
30
- RUBY
31
- end
32
-
33
- it 'flags expect(const).to receive' do
34
- expect_offense(<<-RUBY)
35
- expect(Foo).to receive(:bar)
36
- ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `Foo` as a spy using `allow` or `instance_spy`.
37
- RUBY
38
- end
39
-
40
- it 'flags expect(...).not_to receive' do
41
- expect_offense(<<-RUBY)
42
- expect(foo).not_to receive(:bar)
43
- ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
44
- RUBY
45
- end
46
-
47
- it 'flags expect(...).to_not receive' do
48
- expect_offense(<<-RUBY)
49
- expect(foo).to_not receive(:bar)
50
- ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
51
- RUBY
52
- end
53
-
54
- it 'flags expect(...).to receive with' do
55
- expect_offense(<<-RUBY)
56
- expect(foo).to receive(:bar).with(:baz)
57
- ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
58
- RUBY
59
- end
60
-
61
- it 'flags expect(...).to receive at_most' do
62
- expect_offense(<<-RUBY)
63
- expect(foo).to receive(:bar).at_most(42).times
64
- ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
65
- RUBY
66
- end
67
-
68
- it 'approves of expect(...).to have_received' do
69
- expect_no_offenses('expect(foo).to have_received(:bar)')
70
- end
71
-
72
- include_examples 'detects style', 'expect(foo).to receive(:bar)', 'receive'
73
-
74
- include_examples 'detects style',
75
- 'expect(foo).to have_received(:bar)',
76
- 'have_received'
77
- end
78
-
79
- context 'when EnforcedStyle is receive' do
80
- let(:cop_config) do
81
- { 'EnforcedStyle' => 'receive' }
82
- end
83
-
84
- it 'flags expect(send).to have_received' do
85
- expect_offense(<<-RUBY)
86
- expect(foo).to have_received(:bar)
87
- ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
88
- RUBY
89
- end
90
-
91
- it 'flags expect(lvar).to have_received' do
92
- expect_offense(<<-RUBY)
93
- foo = baz
94
- expect(foo).to have_received(:bar)
95
- ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
96
- RUBY
97
- end
98
-
99
- it 'flags expect(ivar).to have_received' do
100
- expect_offense(<<-RUBY)
101
- expect(@foo).to have_received(:bar)
102
- ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
103
- RUBY
104
- end
105
-
106
- it 'flags expect(const).to have_received' do
107
- expect_offense(<<-RUBY)
108
- expect(Foo).to have_received(:bar)
109
- ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
110
- RUBY
111
- end
112
-
113
- it 'flags expect(...).not_to have_received' do
114
- expect_offense(<<-RUBY)
115
- expect(foo).not_to have_received(:bar)
116
- ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
117
- RUBY
118
- end
119
-
120
- it 'flags expect(...).to_not have_received' do
121
- expect_offense(<<-RUBY)
122
- expect(foo).to_not have_received(:bar)
123
- ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
124
- RUBY
125
- end
126
-
127
- it 'flags expect(...).to have_received with' do
128
- expect_offense(<<-RUBY)
129
- expect(foo).to have_received(:bar).with(:baz)
130
- ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
131
- RUBY
132
- end
133
-
134
- it 'flags expect(...).to have_received at_most' do
135
- expect_offense(<<-RUBY)
136
- expect(foo).to have_received(:bar).at_most(42).times
137
- ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
138
- RUBY
139
- end
140
-
141
- it 'approves of expect(...).to receive' do
142
- expect_no_offenses('expect(foo).to receive(:bar)')
143
- end
144
-
145
- include_examples 'detects style', 'expect(foo).to receive(:bar)', 'receive'
146
-
147
- include_examples 'detects style',
148
- 'expect(foo).to have_received(:bar)',
149
- 'have_received'
150
- end
151
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::MissingExampleGroupArgument do
4
- subject(:cop) { described_class.new }
5
-
6
- it 'accepts describe with an argument' do
7
- expect_no_offenses(<<-RUBY)
8
- describe FooClass do
9
- end
10
-
11
- RSpec.describe FooClass do
12
- end
13
- RUBY
14
- end
15
-
16
- it 'accepts methods with a name like an example block' do
17
- expect_no_offenses(<<-RUBY)
18
- Scenario.context do
19
- 'static'
20
- end
21
- RUBY
22
- end
23
-
24
- it 'checks first argument of describe' do
25
- expect_offense(<<-RUBY)
26
- describe do
27
- ^^^^^^^^^^^ The first argument to `describe` should not be empty.
28
- end
29
-
30
- RSpec.describe do
31
- ^^^^^^^^^^^^^^^^^ The first argument to `describe` should not be empty.
32
- end
33
- RUBY
34
- end
35
-
36
- it 'checks first argument of nested describe' do
37
- expect_offense(<<-RUBY)
38
- describe FooClass do
39
- describe do
40
- ^^^^^^^^^^^ The first argument to `describe` should not be empty.
41
- end
42
-
43
- RSpec.describe do
44
- ^^^^^^^^^^^^^^^^^ The first argument to `describe` should not be empty.
45
- end
46
- end
47
- RUBY
48
- end
49
-
50
- it 'checks first argument of context' do
51
- expect_offense(<<-RUBY)
52
- context do
53
- ^^^^^^^^^^ The first argument to `context` should not be empty.
54
- end
55
- RUBY
56
- end
57
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::MultipleDescribes do
4
- subject(:cop) { described_class.new }
5
-
6
- it 'finds multiple top level describes with class and method' do
7
- expect_offense(<<-RUBY)
8
- describe MyClass, '.do_something' do; end
9
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use multiple top level describes - try to nest them.
10
- describe MyClass, '.do_something_else' do; end
11
- RUBY
12
- end
13
-
14
- it 'finds multiple top level describes only with class' do
15
- expect_offense(<<-RUBY)
16
- describe MyClass do; end
17
- ^^^^^^^^^^^^^^^^ Do not use multiple top level describes - try to nest them.
18
- describe MyOtherClass do; end
19
- RUBY
20
- end
21
-
22
- it 'skips single top level describe' do
23
- expect_no_offenses(<<-RUBY)
24
- require 'spec_helper'
25
-
26
- describe MyClass do
27
- end
28
- RUBY
29
- end
30
- end
@@ -1,261 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::MultipleExpectations, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- context 'without configuration' do
7
- let(:cop_config) { {} }
8
-
9
- it 'flags multiple expectations' do
10
- expect_offense(<<-RUBY)
11
- describe Foo do
12
- it 'uses expect twice' do
13
- ^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
14
- expect(foo).to eq(bar)
15
- expect(baz).to eq(bar)
16
- end
17
- end
18
- RUBY
19
- end
20
-
21
- it 'approves of one expectation per example' do
22
- expect_no_offenses(<<-RUBY)
23
- describe Foo do
24
- it 'does something neat' do
25
- expect(neat).to be(true)
26
- end
27
-
28
- it 'does something cool' do
29
- expect(cool).to be(true)
30
- end
31
- end
32
- RUBY
33
- end
34
-
35
- it 'flags multiple expect_any_instance_of' do
36
- expect_offense(<<-RUBY)
37
- describe Foo do
38
- it 'uses expect_any_instance_of twice' do
39
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
40
- expect_any_instance_of(Foo).to receive(:bar)
41
- expect_any_instance_of(Foo).to receive(:baz)
42
- end
43
- end
44
- RUBY
45
- end
46
-
47
- it 'flags multiple is_expected' do
48
- expect_offense(<<-RUBY)
49
- describe Foo do
50
- it 'uses expect_any_instance_of twice' do
51
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
52
- is_expected.to receive(:bar)
53
- is_expected.to receive(:baz)
54
- end
55
- end
56
- RUBY
57
- end
58
-
59
- it 'flags multiple expects with blocks' do
60
- expect_offense(<<-RUBY)
61
- describe Foo do
62
- it 'uses expect with block twice' do
63
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
64
- expect { something }.to change(Foo.count)
65
- expect { something }.to change(Bar.count)
66
- end
67
- end
68
- RUBY
69
- end
70
-
71
- it 'counts aggregate_failures as one expectation' do
72
- expect_no_offenses(<<-RUBY)
73
- describe Foo do
74
- it 'aggregates failures' do
75
- aggregate_failures do
76
- expect(foo).to eq(bar)
77
- expect(baz).to eq(bar)
78
- end
79
- end
80
- end
81
- RUBY
82
- end
83
-
84
- it 'counts every aggregate_failures as an expectation' do
85
- expect_offense(<<-RUBY)
86
- describe Foo do
87
- it 'has multiple aggregate_failures calls' do
88
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
89
- aggregate_failures do
90
- end
91
- aggregate_failures do
92
- end
93
- end
94
- end
95
- RUBY
96
- end
97
- end
98
-
99
- context 'with metadata' do
100
- it 'ignores examples with `:aggregate_failures`' do
101
- expect_no_offenses(<<-RUBY)
102
- describe Foo do
103
- it 'uses expect twice', :foo, :aggregate_failures do
104
- expect(foo).to eq(bar)
105
- expect(baz).to eq(bar)
106
- end
107
- end
108
- RUBY
109
- end
110
-
111
- it 'ignores example groups with `:aggregate_failures`' do
112
- expect_no_offenses(<<-RUBY)
113
- describe Foo, :foo, :aggregate_failures do
114
- it 'uses expect twice' do
115
- expect(foo).to eq(bar)
116
- expect(baz).to eq(bar)
117
- end
118
- end
119
- RUBY
120
- end
121
-
122
- it 'ignores examples with `aggregate_failures: true`' do
123
- expect_no_offenses(<<-RUBY)
124
- describe Foo do
125
- it 'uses expect twice', :foo, bar: 1, aggregate_failures: true do
126
- expect(foo).to eq(bar)
127
- expect(baz).to eq(bar)
128
- end
129
- end
130
- RUBY
131
- end
132
-
133
- it 'ignores example groups with `aggregate_failures: true`' do
134
- expect_no_offenses(<<-RUBY)
135
- describe Foo, :foo, bar: 1, aggregate_failures: true do
136
- it 'uses expect twice' do
137
- expect(foo).to eq(bar)
138
- expect(baz).to eq(bar)
139
- end
140
- end
141
- RUBY
142
- end
143
-
144
- it 'prefers example metadata over example group metadata' do
145
- expect_offense(<<-RUBY)
146
- describe Foo, aggregate_failures: true do
147
- it 'uses expect twice', aggregate_failures: false do
148
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
149
- expect(foo).to eq(bar)
150
- expect(baz).to eq(bar)
151
- end
152
- end
153
- RUBY
154
- end
155
-
156
- it 'checks examples with `aggregate_failures: false`' do
157
- expect_offense(<<-RUBY)
158
- describe Foo do
159
- it 'uses expect twice', aggregate_failures: false do
160
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
161
- expect(foo).to eq(bar)
162
- expect(baz).to eq(bar)
163
- end
164
- end
165
- RUBY
166
- end
167
-
168
- it 'checks example groups with `aggregate_failures: false`' do
169
- expect_offense(<<-RUBY)
170
- describe Foo, aggregate_failures: false do
171
- it 'uses expect twice' do
172
- ^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
173
- expect(foo).to eq(bar)
174
- expect(baz).to eq(bar)
175
- end
176
- end
177
- RUBY
178
- end
179
-
180
- it 'checks examples with siblings with `aggregate_failures: true`' do
181
- expect_offense(<<-RUBY)
182
- describe Foo do
183
- it 'uses expect twice' do
184
- ^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
185
- expect(foo).to eq(bar)
186
- expect(baz).to eq(bar)
187
- end
188
- it 'with aggregate_failures', aggregate_failures: true do
189
- expect(foo).to eq(bar)
190
- expect(baz).to eq(bar)
191
- end
192
- end
193
- RUBY
194
- end
195
-
196
- it 'ignores examples with `aggregate_failures: true` defined deeply' do
197
- expect_no_offenses(<<-RUBY)
198
- describe Bar, aggregate_failures: true do
199
- describe Foo do
200
- it 'uses expect twice' do
201
- expect(foo).to eq(bar)
202
- expect(baz).to eq(bar)
203
- end
204
- it 'with aggregate_failures', aggregate_failures: false do
205
- expect(foo).to eq(bar)
206
- end
207
- end
208
- end
209
- RUBY
210
- end
211
- end
212
-
213
- context 'with Max configuration' do
214
- let(:cop_config) do
215
- { 'Max' => '2' }
216
- end
217
-
218
- it 'permits two expectations' do
219
- expect_no_offenses(<<-RUBY)
220
- describe Foo do
221
- it 'uses expect twice' do
222
- expect(foo).to eq(bar)
223
- expect(baz).to eq(bar)
224
- end
225
- end
226
- RUBY
227
- end
228
-
229
- it 'flags three expectations' do
230
- expect_offense(<<-RUBY)
231
- describe Foo do
232
- it 'uses expect three times' do
233
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [3/2].
234
- expect(foo).to eq(bar)
235
- expect(baz).to eq(bar)
236
- expect(qux).to eq(bar)
237
- end
238
- end
239
- RUBY
240
- end
241
- end
242
-
243
- it 'generates a todo based on the worst violation' do
244
- inspect_source(<<-RUBY, 'spec/foo_spec.rb')
245
- describe Foo do
246
- it 'uses expect twice' do
247
- expect(foo).to eq(bar)
248
- expect(baz).to eq(bar)
249
- end
250
-
251
- it 'uses expect three times' do
252
- expect(foo).to eq(bar)
253
- expect(baz).to eq(bar)
254
- expect(qux).to eq(bar)
255
- end
256
- end
257
- RUBY
258
-
259
- expect(cop.config_to_allow_offenses[:exclude_limit]).to eq('Max' => 3)
260
- end
261
- end