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,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::ScatteredLet do
4
- subject(:cop) { described_class.new }
5
-
6
- it 'flags `let` after the first different node ' do
7
- expect_offense(<<-RUBY)
8
- RSpec.describe User do
9
- let(:a) { a }
10
- subject { User }
11
- let(:b) { b }
12
- ^^^^^^^^^^^^^ Group all let/let! blocks in the example group together.
13
- end
14
- RUBY
15
- end
16
-
17
- it 'doesnt flag `let!` in the middle of multiple `let`s' do
18
- expect_no_offenses(<<-RUBY)
19
- RSpec.describe User do
20
- subject { User }
21
-
22
- let(:a) { a }
23
- let!(:b) { b }
24
- let(:c) { c }
25
- end
26
- RUBY
27
- end
28
- end
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::ScatteredSetup do
4
- subject(:cop) { described_class.new }
5
-
6
- it 'flags multiple hooks in the same example group' do
7
- expect_offense(<<-RUBY)
8
- describe Foo do
9
- before { bar }
10
- ^^^^^^^^^^^^^^ Do not define multiple hooks in the same example group.
11
- before { baz }
12
- ^^^^^^^^^^^^^^ Do not define multiple hooks in the same example group.
13
- end
14
- RUBY
15
- end
16
-
17
- it 'flags multiple hooks of the same scope with different symbols' do
18
- expect_offense(<<-RUBY)
19
- describe Foo do
20
- before { bar }
21
- ^^^^^^^^^^^^^^ Do not define multiple hooks in the same example group.
22
- before(:each) { baz }
23
- ^^^^^^^^^^^^^^^^^^^^^ Do not define multiple hooks in the same example group.
24
- before(:example) { baz }
25
- ^^^^^^^^^^^^^^^^^^^^^^^^ Do not define multiple hooks in the same example group.
26
- end
27
- RUBY
28
- end
29
-
30
- it 'flags multiple before(:all) hooks in the same example group' do
31
- expect_offense(<<-RUBY)
32
- describe Foo do
33
- before(:all) { bar }
34
- ^^^^^^^^^^^^^^^^^^^^ Do not define multiple hooks in the same example group.
35
- before(:all) { baz }
36
- ^^^^^^^^^^^^^^^^^^^^ Do not define multiple hooks in the same example group.
37
- end
38
- RUBY
39
- end
40
-
41
- it 'does not flag different hooks' do
42
- expect_no_offenses(<<-RUBY)
43
- describe Foo do
44
- before { bar }
45
- after { baz }
46
- around { qux }
47
- end
48
- RUBY
49
- end
50
-
51
- it 'does not flag different hook types' do
52
- expect_no_offenses(<<-RUBY)
53
- describe Foo do
54
- before { bar }
55
- before(:all) { baz }
56
- before(:suite) { baz }
57
- end
58
- RUBY
59
- end
60
-
61
- it 'does not flag hooks in different example groups' do
62
- expect_no_offenses(<<-RUBY)
63
- describe Foo do
64
- before { bar }
65
-
66
- describe '.baz' do
67
- before { baz }
68
- end
69
- end
70
- RUBY
71
- end
72
-
73
- it 'does not flag hooks in different shared contexts' do
74
- expect_no_offenses(<<-RUBY)
75
- describe Foo do
76
- shared_context 'one' do
77
- before { bar }
78
- end
79
-
80
- shared_context 'two' do
81
- before { baz }
82
- end
83
- end
84
- RUBY
85
- end
86
-
87
- it 'does not flag similar method names inside of examples' do
88
- expect_no_offenses(<<-RUBY)
89
- describe Foo do
90
- before { bar }
91
-
92
- it 'uses an instance method called before' do
93
- expect(before { tricky }).to_not confuse_rubocop_rspec
94
- end
95
- end
96
- RUBY
97
- end
98
- end
@@ -1,137 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::SharedContext do
4
- subject(:cop) { described_class.new }
5
-
6
- describe 'shared_context' do
7
- it 'does not register an offense for empty contexts' do
8
- expect_no_offenses(<<-RUBY)
9
- shared_context 'empty' do
10
- end
11
- RUBY
12
- end
13
-
14
- it 'registers an offense for shared_context with only examples' do
15
- expect_offense(<<-RUBY)
16
- shared_context 'foo' do
17
- ^^^^^^^^^^^^^^^^^^^^ Use `shared_examples` when you don't define context.
18
- it 'performs actions' do
19
- end
20
- end
21
- RUBY
22
-
23
- expect_correction(<<-RUBY)
24
- shared_examples 'foo' do
25
- it 'performs actions' do
26
- end
27
- end
28
- RUBY
29
- end
30
-
31
- it 'does not register an offense for `shared_context` with let' do
32
- expect_no_offenses(<<-RUBY)
33
- shared_context 'foo' do
34
- let(:foo) { :bar }
35
-
36
- it 'performs actions' do
37
- end
38
- end
39
- RUBY
40
- end
41
-
42
- it 'does not register an offense for `shared_context` with subject' do
43
- expect_no_offenses(<<-RUBY)
44
- shared_context 'foo' do
45
- subject(:foo) { :bar }
46
-
47
- it 'performs actions' do
48
- end
49
- end
50
- RUBY
51
- end
52
-
53
- it 'does not register an offense for `shared_context` with before' do
54
- expect_no_offenses(<<-RUBY)
55
- shared_context 'foo' do
56
- before do
57
- something
58
- end
59
-
60
- it 'performs actions' do
61
- end
62
- end
63
- RUBY
64
- end
65
- end
66
-
67
- describe 'shared_examples' do
68
- it 'does not register an offense for empty examples' do
69
- expect_no_offenses(<<-RUBY)
70
- shared_examples 'empty' do
71
- end
72
- RUBY
73
- end
74
-
75
- it 'registers an offense for shared_examples with only let' do
76
- expect_offense(<<-RUBY)
77
- shared_examples 'foo' do
78
- ^^^^^^^^^^^^^^^^^^^^^ Use `shared_context` when you don't define examples.
79
- let(:foo) { :bar }
80
- end
81
- RUBY
82
-
83
- expect_correction(<<-RUBY)
84
- shared_context 'foo' do
85
- let(:foo) { :bar }
86
- end
87
- RUBY
88
- end
89
-
90
- it 'registers an offense for shared_examples with only subject' do
91
- expect_offense(<<-RUBY)
92
- shared_examples 'foo' do
93
- ^^^^^^^^^^^^^^^^^^^^^ Use `shared_context` when you don't define examples.
94
- subject(:foo) { :bar }
95
- end
96
- RUBY
97
-
98
- expect_correction(<<-RUBY)
99
- shared_context 'foo' do
100
- subject(:foo) { :bar }
101
- end
102
- RUBY
103
- end
104
-
105
- it 'registers an offense for shared_examples with only hooks' do
106
- expect_offense(<<-RUBY)
107
- shared_examples 'foo' do
108
- ^^^^^^^^^^^^^^^^^^^^^ Use `shared_context` when you don't define examples.
109
- before do
110
- foo
111
- end
112
- end
113
- RUBY
114
-
115
- expect_correction(<<-RUBY)
116
- shared_context 'foo' do
117
- before do
118
- foo
119
- end
120
- end
121
- RUBY
122
- end
123
-
124
- it 'does not register an offense for `shared_examples` with it' do
125
- expect_no_offenses(<<-RUBY)
126
- shared_examples 'foo' do
127
- subject(:foo) { 'foo' }
128
- let(:bar) { :baz }
129
- before { initialize }
130
-
131
- it 'works' do
132
- end
133
- end
134
- RUBY
135
- end
136
- end
137
- end
@@ -1,75 +0,0 @@
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, 'foo', 'bar' 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
-
30
- expect_correction(<<-RUBY)
31
- it_behaves_like 'foo bar baz'
32
- it_should_behave_like 'foo bar baz'
33
- shared_examples 'foo bar baz'
34
- shared_examples_for 'foo bar baz'
35
- include_examples 'foo bar baz'
36
- include_examples 'foo bar baz', 'foo', 'bar'
37
-
38
- shared_examples 'foo bar baz', 'foo', 'bar' do |param|
39
- # ...
40
- end
41
-
42
- RSpec.shared_examples 'foo bar baz'
43
- RUBY
44
- end
45
-
46
- it 'does not register an offense when using string title' do
47
- expect_no_offenses(<<-RUBY)
48
- it_behaves_like 'foo bar baz'
49
- it_should_behave_like 'foo bar baz'
50
- shared_examples 'foo bar baz'
51
- shared_examples_for 'foo bar baz'
52
- include_examples 'foo bar baz'
53
- include_examples 'foo bar baz', 'foo', 'bar'
54
-
55
- shared_examples 'foo bar baz', 'foo', 'bar' do |param|
56
- # ...
57
- end
58
- RUBY
59
- end
60
-
61
- it 'does not register an offense when using Module/Class title' do
62
- expect_no_offenses(<<-RUBY)
63
- it_behaves_like FooBarBaz
64
- it_should_behave_like FooBarBaz
65
- shared_examples FooBarBaz
66
- shared_examples_for FooBarBaz
67
- include_examples FooBarBaz
68
- include_examples FooBarBaz, 'foo', 'bar'
69
-
70
- shared_examples FooBarBaz, 'foo', 'bar' do |param|
71
- # ...
72
- end
73
- RUBY
74
- end
75
- end
@@ -1,178 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::RSpec::SingleArgumentMessageChain do
4
- subject(:cop) { described_class.new }
5
-
6
- describe 'receive_message_chain' do
7
- it 'reports single-argument calls' do
8
- expect_offense(<<-RUBY)
9
- before do
10
- allow(foo).to receive_message_chain(:one) { :two }
11
- ^^^^^^^^^^^^^^^^^^^^^ Use `receive` instead of calling `receive_message_chain` with a single argument.
12
- end
13
- RUBY
14
-
15
- expect_correction(<<-RUBY)
16
- before do
17
- allow(foo).to receive(:one) { :two }
18
- end
19
- RUBY
20
- end
21
-
22
- it 'accepts multi-argument calls' do
23
- expect_no_offenses(<<-RUBY)
24
- before do
25
- allow(foo).to receive_message_chain(:one, :two) { :three }
26
- end
27
- RUBY
28
- end
29
-
30
- it 'reports single-argument string calls' do
31
- expect_offense(<<-RUBY)
32
- before do
33
- allow(foo).to receive_message_chain("one") { :two }
34
- ^^^^^^^^^^^^^^^^^^^^^ Use `receive` instead of calling `receive_message_chain` with a single argument.
35
- end
36
- RUBY
37
-
38
- expect_correction(<<-RUBY)
39
- before do
40
- allow(foo).to receive("one") { :two }
41
- end
42
- RUBY
43
- end
44
-
45
- it 'accepts multi-argument string calls' do
46
- expect_no_offenses(<<-RUBY)
47
- before do
48
- allow(foo).to receive_message_chain("one.two") { :three }
49
- end
50
- RUBY
51
- end
52
-
53
- it 'accepts single-argument calls with variable' do
54
- expect_no_offenses(<<-RUBY)
55
- before do
56
- foo = %i[:one :two]
57
- allow(foo).to receive_message_chain(foo) { :many }
58
- end
59
- RUBY
60
- end
61
-
62
- it 'accepts single-argument calls with send node' do
63
- expect_no_offenses(<<-RUBY)
64
- before do
65
- allow(foo).to receive_message_chain(foo) { :many }
66
- end
67
- RUBY
68
- end
69
-
70
- context 'with single-element array argument' do
71
- it 'reports an offense' do
72
- expect_offense(<<-RUBY)
73
- before do
74
- allow(foo).to receive_message_chain([:one]) { :two }
75
- ^^^^^^^^^^^^^^^^^^^^^ Use `receive` instead of calling `receive_message_chain` with a single argument.
76
- end
77
- RUBY
78
-
79
- expect_correction(<<-RUBY)
80
- before do
81
- allow(foo).to receive(:one) { :two }
82
- end
83
- RUBY
84
- end
85
- end
86
-
87
- context 'with multiple-element array argument' do
88
- it "doesn't report an offense" do
89
- expect_no_offenses(<<-RUBY)
90
- before do
91
- allow(foo).to receive_message_chain([:one, :two]) { :many }
92
- end
93
- RUBY
94
- end
95
- end
96
-
97
- context 'with single-key hash argument' do
98
- it 'reports an offense' do
99
- expect_offense(<<-RUBY)
100
- before do
101
- allow(foo).to receive_message_chain(bar: 42)
102
- ^^^^^^^^^^^^^^^^^^^^^ Use `receive` instead of calling `receive_message_chain` with a single argument.
103
- allow(foo).to receive_message_chain("bar" => 42)
104
- ^^^^^^^^^^^^^^^^^^^^^ Use `receive` instead of calling `receive_message_chain` with a single argument.
105
- allow(foo).to receive_message_chain(:"\#{foo}" => 42)
106
- ^^^^^^^^^^^^^^^^^^^^^ Use `receive` instead of calling `receive_message_chain` with a single argument.
107
- end
108
- RUBY
109
-
110
- expect_correction(<<-RUBY)
111
- before do
112
- allow(foo).to receive(:bar).and_return(42)
113
- allow(foo).to receive("bar").and_return(42)
114
- allow(foo).to receive(:"\#{foo}").and_return(42)
115
- end
116
- RUBY
117
- end
118
- end
119
-
120
- context 'with multiple keys hash argument' do
121
- it "doesn't report an offense" do
122
- expect_no_offenses(<<-RUBY)
123
- before do
124
- allow(foo).to receive_message_chain(bar: 42, baz: 42)
125
- end
126
- RUBY
127
- end
128
- end
129
- end
130
-
131
- describe 'stub_chain' do
132
- it 'reports single-argument calls' do
133
- expect_offense(<<-RUBY)
134
- before do
135
- foo.stub_chain(:one) { :two }
136
- ^^^^^^^^^^ Use `stub` instead of calling `stub_chain` with a single argument.
137
- end
138
- RUBY
139
-
140
- expect_correction(<<-RUBY)
141
- before do
142
- foo.stub(:one) { :two }
143
- end
144
- RUBY
145
- end
146
-
147
- it 'accepts multi-argument calls' do
148
- expect_no_offenses(<<-RUBY)
149
- before do
150
- foo.stub_chain(:one, :two) { :three }
151
- end
152
- RUBY
153
- end
154
-
155
- it 'reports single-argument string calls' do
156
- expect_offense(<<-RUBY)
157
- before do
158
- foo.stub_chain("one") { :two }
159
- ^^^^^^^^^^ Use `stub` instead of calling `stub_chain` with a single argument.
160
- end
161
- RUBY
162
-
163
- expect_correction(<<-RUBY)
164
- before do
165
- foo.stub("one") { :two }
166
- end
167
- RUBY
168
- end
169
-
170
- it 'accepts multi-argument string calls' do
171
- expect_no_offenses(<<-RUBY)
172
- before do
173
- foo.stub_chain("one.two") { :three }
174
- end
175
- RUBY
176
- end
177
- end
178
- end