rubocop-rspec 1.7.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +955 -79
- data/CODE_OF_CONDUCT.md +17 -0
- data/MIT-LICENSE.md +1 -2
- data/README.md +35 -35
- data/config/default.yml +940 -52
- data/config/obsoletion.yml +30 -0
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +49 -0
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +49 -0
- data/lib/rubocop/cop/rspec/any_instance.rb +10 -13
- data/lib/rubocop/cop/rspec/around_block.rb +97 -0
- data/lib/rubocop/cop/rspec/base.rb +26 -0
- data/lib/rubocop/cop/rspec/be.rb +39 -0
- data/lib/rubocop/cop/rspec/be_empty.rb +45 -0
- data/lib/rubocop/cop/rspec/be_eq.rb +47 -0
- data/lib/rubocop/cop/rspec/be_eql.rb +18 -15
- data/lib/rubocop/cop/rspec/be_nil.rb +74 -0
- data/lib/rubocop/cop/rspec/before_after_all.rb +45 -0
- data/lib/rubocop/cop/rspec/change_by_zero.rb +184 -0
- data/lib/rubocop/cop/rspec/class_check.rb +101 -0
- data/lib/rubocop/cop/rspec/contain_exactly.rb +56 -0
- data/lib/rubocop/cop/rspec/context_method.rb +57 -0
- data/lib/rubocop/cop/rspec/context_wording.rb +117 -0
- data/lib/rubocop/cop/rspec/describe_class.rb +52 -21
- data/lib/rubocop/cop/rspec/describe_method.rb +26 -11
- data/lib/rubocop/cop/rspec/describe_symbol.rb +37 -0
- data/lib/rubocop/cop/rspec/described_class.rb +181 -34
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +38 -0
- data/lib/rubocop/cop/rspec/dialect.rb +84 -0
- data/lib/rubocop/cop/rspec/duplicated_metadata.rb +58 -0
- data/lib/rubocop/cop/rspec/empty_example_group.rb +134 -47
- data/lib/rubocop/cop/rspec/empty_hook.rb +49 -0
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +82 -0
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +42 -0
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +40 -0
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +82 -0
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +36 -0
- data/lib/rubocop/cop/rspec/empty_metadata.rb +46 -0
- data/lib/rubocop/cop/rspec/empty_output.rb +47 -0
- data/lib/rubocop/cop/rspec/eq.rb +47 -0
- data/lib/rubocop/cop/rspec/example_length.rb +38 -20
- data/lib/rubocop/cop/rspec/example_without_description.rb +98 -0
- data/lib/rubocop/cop/rspec/example_wording.rb +117 -27
- data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +110 -0
- data/lib/rubocop/cop/rspec/expect_actual.rb +46 -20
- data/lib/rubocop/cop/rspec/expect_change.rb +86 -0
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +50 -0
- data/lib/rubocop/cop/rspec/expect_in_let.rb +42 -0
- data/lib/rubocop/cop/rspec/expect_output.rb +50 -0
- data/lib/rubocop/cop/rspec/focus.rb +79 -25
- data/lib/rubocop/cop/rspec/hook_argument.rb +48 -36
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +81 -0
- data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +37 -0
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +68 -0
- data/lib/rubocop/cop/rspec/implicit_expect.rb +100 -0
- data/lib/rubocop/cop/rspec/implicit_subject.rb +167 -0
- data/lib/rubocop/cop/rspec/indexed_let.rb +112 -0
- data/lib/rubocop/cop/rspec/instance_spy.rb +74 -0
- data/lib/rubocop/cop/rspec/instance_variable.rb +28 -14
- data/lib/rubocop/cop/rspec/is_expected_specify.rb +45 -0
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +49 -0
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +74 -0
- data/lib/rubocop/cop/rspec/leading_subject.rb +57 -29
- data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +127 -0
- data/lib/rubocop/cop/rspec/let_before_examples.rb +101 -0
- data/lib/rubocop/cop/rspec/let_setup.rb +32 -16
- data/lib/rubocop/cop/rspec/match_array.rb +59 -0
- data/lib/rubocop/cop/rspec/message_chain.rb +10 -15
- data/lib/rubocop/cop/rspec/message_expectation.rb +12 -9
- data/lib/rubocop/cop/rspec/message_spies.rb +88 -0
- data/lib/rubocop/cop/rspec/metadata_style.rb +202 -0
- data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +35 -0
- data/lib/rubocop/cop/rspec/missing_expectation_target_method.rb +54 -0
- data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
- data/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb +59 -0
- data/lib/rubocop/cop/rspec/mixin/file_help.rb +14 -0
- data/lib/rubocop/cop/rspec/mixin/final_end_location.rb +19 -0
- data/lib/rubocop/cop/rspec/mixin/inside_example_group.rb +29 -0
- data/lib/rubocop/cop/rspec/mixin/location_help.rb +37 -0
- data/lib/rubocop/cop/rspec/mixin/metadata.rb +63 -0
- data/lib/rubocop/cop/rspec/mixin/namespace.rb +23 -0
- data/lib/rubocop/cop/rspec/mixin/skip_or_pending.rb +39 -0
- data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +54 -0
- data/lib/rubocop/cop/rspec/mixin/variable.rb +21 -0
- data/lib/rubocop/cop/rspec/multiple_describes.rb +14 -12
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +86 -26
- data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +146 -0
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +97 -0
- data/lib/rubocop/cop/rspec/named_subject.rb +107 -27
- data/lib/rubocop/cop/rspec/nested_groups.rb +84 -47
- data/lib/rubocop/cop/rspec/no_expectation_example.rb +102 -0
- data/lib/rubocop/cop/rspec/not_to_not.rb +30 -27
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +74 -0
- data/lib/rubocop/cop/rspec/pending.rb +80 -0
- data/lib/rubocop/cop/rspec/pending_without_reason.rb +159 -0
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +341 -0
- data/lib/rubocop/cop/rspec/receive_counts.rb +89 -0
- data/lib/rubocop/cop/rspec/receive_messages.rb +161 -0
- data/lib/rubocop/cop/rspec/receive_never.rb +41 -0
- data/lib/rubocop/cop/rspec/redundant_around.rb +65 -0
- data/lib/rubocop/cop/rspec/redundant_predicate_matcher.rb +67 -0
- data/lib/rubocop/cop/rspec/remove_const.rb +39 -0
- data/lib/rubocop/cop/rspec/repeated_description.rb +98 -0
- data/lib/rubocop/cop/rspec/repeated_example.rb +53 -0
- data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +100 -0
- data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +96 -0
- data/lib/rubocop/cop/rspec/repeated_include_example.rb +105 -0
- data/lib/rubocop/cop/rspec/repeated_subject_call.rb +125 -0
- data/lib/rubocop/cop/rspec/return_from_stub.rb +169 -0
- data/lib/rubocop/cop/rspec/scattered_let.rb +59 -0
- data/lib/rubocop/cop/rspec/scattered_setup.rb +92 -0
- data/lib/rubocop/cop/rspec/shared_context.rb +107 -0
- data/lib/rubocop/cop/rspec/shared_examples.rb +125 -0
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +93 -0
- data/lib/rubocop/cop/rspec/skip_block_inside_example.rb +46 -0
- data/lib/rubocop/cop/rspec/sort_metadata.rb +71 -0
- data/lib/rubocop/cop/rspec/spec_file_path_format.rb +133 -0
- data/lib/rubocop/cop/rspec/spec_file_path_suffix.rb +40 -0
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +176 -0
- data/lib/rubocop/cop/rspec/subject_declaration.rb +46 -0
- data/lib/rubocop/cop/rspec/subject_stub.rb +93 -74
- data/lib/rubocop/cop/rspec/undescriptive_literals_description.rb +69 -0
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +67 -0
- data/lib/rubocop/cop/rspec/variable_definition.rb +77 -0
- data/lib/rubocop/cop/rspec/variable_name.rb +68 -0
- data/lib/rubocop/cop/rspec/verified_double_reference.rb +111 -0
- data/lib/rubocop/cop/rspec/verified_doubles.rb +28 -14
- data/lib/rubocop/cop/rspec/void_expect.rb +60 -0
- data/lib/rubocop/cop/rspec/yield.rb +82 -0
- data/lib/rubocop/cop/rspec_cops.rb +112 -0
- data/lib/rubocop/rspec/align_let_brace.rb +63 -0
- data/lib/rubocop/rspec/concept.rb +33 -0
- data/lib/rubocop/rspec/config_formatter.rb +27 -4
- data/lib/rubocop/rspec/cop/generator.rb +25 -0
- data/lib/rubocop/rspec/corrector/move_node.rb +51 -0
- data/lib/rubocop/rspec/description_extractor.rb +60 -18
- data/lib/rubocop/rspec/example.rb +37 -0
- data/lib/rubocop/rspec/example_group.rb +67 -0
- data/lib/rubocop/rspec/hook.rb +79 -0
- data/lib/rubocop/rspec/inject.rb +3 -1
- data/lib/rubocop/rspec/language.rb +184 -41
- data/lib/rubocop/rspec/node.rb +19 -0
- data/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +29 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/lib/rubocop/rspec/wording.rb +61 -19
- data/lib/rubocop/rspec.rb +6 -2
- data/lib/rubocop-rspec.rb +45 -34
- metadata +130 -195
- data/Gemfile +0 -13
- data/Rakefile +0 -48
- data/lib/rubocop/cop/rspec/file_path.rb +0 -83
- data/lib/rubocop/rspec/language/node_pattern.rb +0 -16
- data/lib/rubocop/rspec/spec_only.rb +0 -61
- data/lib/rubocop/rspec/top_level_describe.rb +0 -61
- data/lib/rubocop/rspec/util.rb +0 -19
- data/rubocop-rspec.gemspec +0 -42
- data/spec/expect_violation/expectation_spec.rb +0 -85
- data/spec/project/changelog_spec.rb +0 -81
- data/spec/project/default_config_spec.rb +0 -52
- data/spec/project/project_requires_spec.rb +0 -8
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +0 -30
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +0 -59
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +0 -113
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +0 -32
- data/spec/rubocop/cop/rspec/described_class_spec.rb +0 -219
- data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +0 -79
- data/spec/rubocop/cop/rspec/example_length_spec.rb +0 -117
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +0 -82
- data/spec/rubocop/cop/rspec/expect_actual_spec.rb +0 -136
- data/spec/rubocop/cop/rspec/file_path_spec.rb +0 -236
- data/spec/rubocop/cop/rspec/focus_spec.rb +0 -130
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +0 -189
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +0 -75
- data/spec/rubocop/cop/rspec/leading_subject_spec.rb +0 -54
- data/spec/rubocop/cop/rspec/let_setup_spec.rb +0 -66
- data/spec/rubocop/cop/rspec/message_chain_spec.rb +0 -21
- data/spec/rubocop/cop/rspec/message_expectation_spec.rb +0 -63
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +0 -28
- data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +0 -84
- data/spec/rubocop/cop/rspec/named_subject_spec.rb +0 -62
- data/spec/rubocop/cop/rspec/nested_groups_spec.rb +0 -55
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +0 -57
- data/spec/rubocop/cop/rspec/subject_stub_spec.rb +0 -183
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +0 -71
- data/spec/rubocop/rspec/config_formatter_spec.rb +0 -48
- data/spec/rubocop/rspec/description_extractor_spec.rb +0 -35
- data/spec/rubocop/rspec/language/selector_set_spec.rb +0 -29
- data/spec/rubocop/rspec/spec_only_spec.rb +0 -97
- data/spec/rubocop/rspec/util/one_spec.rb +0 -21
- data/spec/rubocop/rspec/wording_spec.rb +0 -44
- data/spec/shared/rspec_only_cop_behavior.rb +0 -68
- data/spec/spec_helper.rb +0 -41
- data/spec/support/expect_violation.rb +0 -166
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
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_violation(<<-RUBY)
|
8
|
-
describe Foo do
|
9
|
-
let!(:foo) { bar }
|
10
|
-
^^^^^^^^^^ Do not use `let!` for test setup.
|
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_violations(<<-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_violations(<<-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_violation(<<-RUBY)
|
50
|
-
describe Foo do
|
51
|
-
context 'when something special happens' do
|
52
|
-
let!(:foo) { bar }
|
53
|
-
^^^^^^^^^^ Do not use `let!` for test setup.
|
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,21 +0,0 @@
|
|
1
|
-
describe RuboCop::Cop::RSpec::MessageChain do
|
2
|
-
subject(:cop) { described_class.new }
|
3
|
-
|
4
|
-
it 'finds `receive_message_chain`' do
|
5
|
-
expect_violation(<<-RUBY)
|
6
|
-
before do
|
7
|
-
allow(foo).to receive_message_chain(:one, :two) { :three }
|
8
|
-
^^^^^^^^^^^^^^^^^^^^^ Avoid stubbing using `receive_message_chain`
|
9
|
-
end
|
10
|
-
RUBY
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'finds old `stub_chain` syntax' do
|
14
|
-
expect_violation(<<-RUBY)
|
15
|
-
before do
|
16
|
-
foo.stub_chain(:one, :two).and_return(:three)
|
17
|
-
^^^^^^^^^^ Avoid stubbing using `stub_chain`
|
18
|
-
end
|
19
|
-
RUBY
|
20
|
-
end
|
21
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
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_violation(<<-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_violations('allow(foo).to receive(:bar)')
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'generates a todo based on the usage of the correct style' do
|
23
|
-
inspect_source(cop, 'allow(foo).to receive(:bar)', 'foo_spec.rb')
|
24
|
-
|
25
|
-
expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'allow')
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'generates a todo based on the usage of the alternate style' do
|
29
|
-
inspect_source(cop, 'expect(foo).to receive(:bar)', 'foo_spec.rb')
|
30
|
-
|
31
|
-
expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'expect')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when EnforcedStyle is expect' do
|
36
|
-
let(:cop_config) do
|
37
|
-
{ 'EnforcedStyle' => 'expect' }
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'flags allow(...).to receive' do
|
41
|
-
expect_violation(<<-RUBY)
|
42
|
-
allow(foo).to receive(:bar)
|
43
|
-
^^^^^ Prefer `expect` for setting message expectations.
|
44
|
-
RUBY
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'approves of expect(...).to receive' do
|
48
|
-
expect_no_violations('expect(foo).to receive(:bar)')
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'generates a todo based on the usage of the correct style' do
|
52
|
-
inspect_source(cop, 'expect(foo).to receive(:bar)', 'foo_spec.rb')
|
53
|
-
|
54
|
-
expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'expect')
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'generates a todo based on the usage of the alternate style' do
|
58
|
-
inspect_source(cop, 'allow(foo).to receive(:bar)', 'foo_spec.rb')
|
59
|
-
|
60
|
-
expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'allow')
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
describe RuboCop::Cop::RSpec::MultipleDescribes do
|
2
|
-
subject(:cop) { described_class.new }
|
3
|
-
|
4
|
-
it 'finds multiple top level describes with class and method' do
|
5
|
-
expect_violation(<<-RUBY)
|
6
|
-
describe MyClass, '.do_something' do; end
|
7
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use multiple top level describes - try to nest them.
|
8
|
-
describe MyClass, '.do_something_else' do; end
|
9
|
-
RUBY
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'finds multiple top level describes only with class' do
|
13
|
-
expect_violation(<<-RUBY)
|
14
|
-
describe MyClass do; end
|
15
|
-
^^^^^^^^^^^^^^^^ Do not use multiple top level describes - try to nest them.
|
16
|
-
describe MyOtherClass do; end
|
17
|
-
RUBY
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'skips single top level describe' do
|
21
|
-
expect_no_violations(<<-RUBY)
|
22
|
-
require 'spec_helper'
|
23
|
-
|
24
|
-
describe MyClass do
|
25
|
-
end
|
26
|
-
RUBY
|
27
|
-
end
|
28
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe RuboCop::Cop::RSpec::MultipleExpectations, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
context 'without configuration' do
|
7
|
-
let(:cop_config) { Hash.new }
|
8
|
-
|
9
|
-
it 'flags multiple expectations' do
|
10
|
-
expect_violation(<<-RUBY)
|
11
|
-
describe Foo do
|
12
|
-
it 'uses expect twice' do
|
13
|
-
^^^^^^^^^^^^^^^^^^^^^^ Too many expectations.
|
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_violations(<<-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
|
-
end
|
35
|
-
|
36
|
-
context 'with configuration' do
|
37
|
-
let(:cop_config) do
|
38
|
-
{ 'Max' => '2' }
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'permits two expectations' do
|
42
|
-
expect_no_violations(<<-RUBY)
|
43
|
-
describe Foo do
|
44
|
-
it 'uses expect twice' do
|
45
|
-
expect(foo).to eq(bar)
|
46
|
-
expect(baz).to eq(bar)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
RUBY
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'flags three expectations' do
|
53
|
-
expect_violation(<<-RUBY)
|
54
|
-
describe Foo do
|
55
|
-
it 'uses expect three times' do
|
56
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Too many expectations.
|
57
|
-
expect(foo).to eq(bar)
|
58
|
-
expect(baz).to eq(bar)
|
59
|
-
expect(qux).to eq(bar)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
RUBY
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'generates a todo based on the worst violation' do
|
67
|
-
inspect_source(cop, <<-RUBY, 'spec/foo_spec.rb')
|
68
|
-
describe Foo do
|
69
|
-
it 'uses expect twice' do
|
70
|
-
expect(foo).to eq(bar)
|
71
|
-
expect(baz).to eq(bar)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'uses expect three times' do
|
75
|
-
expect(foo).to eq(bar)
|
76
|
-
expect(baz).to eq(bar)
|
77
|
-
expect(qux).to eq(bar)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
RUBY
|
81
|
-
|
82
|
-
expect(cop.config_to_allow_offenses).to eq('Max' => 3)
|
83
|
-
end
|
84
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::NamedSubject do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'checks `it` and `specify` for explicit subject usage' do
|
7
|
-
expect_violation(<<-RUBY)
|
8
|
-
RSpec.describe User do
|
9
|
-
subject { described_class.new }
|
10
|
-
|
11
|
-
it "is valid" do
|
12
|
-
expect(subject.valid?).to be(true)
|
13
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
14
|
-
end
|
15
|
-
|
16
|
-
specify do
|
17
|
-
expect(subject.valid?).to be(true)
|
18
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
19
|
-
end
|
20
|
-
end
|
21
|
-
RUBY
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'checks before and after for explicit subject usage' do
|
25
|
-
expect_violation(<<-RUBY)
|
26
|
-
RSpec.describe User do
|
27
|
-
subject { described_class.new }
|
28
|
-
|
29
|
-
before(:each) do
|
30
|
-
do_something_with(subject)
|
31
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
32
|
-
end
|
33
|
-
|
34
|
-
after do
|
35
|
-
do_something_with(subject)
|
36
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
37
|
-
end
|
38
|
-
end
|
39
|
-
RUBY
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'checks around(:each) for explicit subject usage' do
|
43
|
-
expect_violation(<<-RUBY)
|
44
|
-
RSpec.describe User do
|
45
|
-
subject { described_class.new }
|
46
|
-
|
47
|
-
around(:each) do |test|
|
48
|
-
do_something_with(subject)
|
49
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
50
|
-
end
|
51
|
-
end
|
52
|
-
RUBY
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'ignores subject when not wrapped inside a test' do
|
56
|
-
expect_no_violations(<<-RUBY)
|
57
|
-
def foo
|
58
|
-
it(subject)
|
59
|
-
end
|
60
|
-
RUBY
|
61
|
-
end
|
62
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe RuboCop::Cop::RSpec::NestedGroups, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
it 'flags nested contexts' do
|
7
|
-
expect_violation(<<-RUBY)
|
8
|
-
describe MyClass do
|
9
|
-
context 'when foo' do
|
10
|
-
context 'when bar' do
|
11
|
-
^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded
|
12
|
-
context 'when baz' do
|
13
|
-
^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when qux' do
|
19
|
-
context 'when norf' do
|
20
|
-
^^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
RUBY
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'ignores non-spec context methods' do
|
28
|
-
expect_no_violations(<<-RUBY)
|
29
|
-
class MyThingy
|
30
|
-
context 'this is not rspec' do
|
31
|
-
context 'but it uses contexts' do
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
RUBY
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when MaxNesting is configured as 2' do
|
39
|
-
let(:cop_config) { { 'MaxNesting' => '3' } }
|
40
|
-
|
41
|
-
it 'only flags third level of nesting' do
|
42
|
-
expect_violation(<<-RUBY)
|
43
|
-
describe MyClass do
|
44
|
-
context 'when foo' do
|
45
|
-
context 'when bar' do
|
46
|
-
context 'when baz' do
|
47
|
-
^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
RUBY
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
describe RuboCop::Cop::RSpec::NotToNot, :config do
|
2
|
-
subject(:cop) { described_class.new(config) }
|
3
|
-
|
4
|
-
context 'when EnforcedStyle is `not_to`' do
|
5
|
-
let(:cop_config) { { 'EnforcedStyle' => 'not_to' } }
|
6
|
-
|
7
|
-
it 'detects the `to_not` offense' do
|
8
|
-
expect_violation(<<-RUBY)
|
9
|
-
it { expect(false).to_not be_true }
|
10
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `not_to` over `to_not`
|
11
|
-
RUBY
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'detects no offense when using `not_to`' do
|
15
|
-
expect_no_violations(<<-RUBY)
|
16
|
-
it { expect(false).not_to be_true }
|
17
|
-
RUBY
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'auto-corrects `to_not` to `not_to`' do
|
21
|
-
corrected =
|
22
|
-
autocorrect_source(
|
23
|
-
cop,
|
24
|
-
['it { expect(0).to_not equal 1 }'],
|
25
|
-
'spec/foo_spec.rb'
|
26
|
-
)
|
27
|
-
expect(corrected).to eq 'it { expect(0).not_to equal 1 }'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when AcceptedMethod is `to_not`' do
|
32
|
-
let(:cop_config) { { 'EnforcedStyle' => 'to_not' } }
|
33
|
-
|
34
|
-
it 'detects the `not_to` offense' do
|
35
|
-
expect_violation(<<-RUBY)
|
36
|
-
it { expect(false).not_to be_true }
|
37
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `to_not` over `not_to`
|
38
|
-
RUBY
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'detects no offense when using `to_not`' do
|
42
|
-
expect_no_violations(<<-RUBY)
|
43
|
-
it { expect(false).to_not be_true }
|
44
|
-
RUBY
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'auto-corrects `not_to` to `to_not`' do
|
48
|
-
corrected =
|
49
|
-
autocorrect_source(
|
50
|
-
cop,
|
51
|
-
['it { expect(0).not_to equal 1 }'],
|
52
|
-
'spec/foo_spec.rb'
|
53
|
-
)
|
54
|
-
expect(corrected).to eq 'it { expect(0).to_not equal 1 }'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,183 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe RuboCop::Cop::RSpec::SubjectStub do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'complains when subject is stubbed' do
|
7
|
-
expect_violation(<<-RUBY)
|
8
|
-
describe Foo do
|
9
|
-
subject(:foo) { described_class.new }
|
10
|
-
|
11
|
-
before do
|
12
|
-
allow(foo).to receive(:bar).and_return(baz)
|
13
|
-
^^^^^^^^^^ Do not stub your test subject.
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'uses expect twice' do
|
17
|
-
expect(foo.bar).to eq(baz)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
RUBY
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'complains when subject is mocked' do
|
24
|
-
expect_violation(<<-RUBY)
|
25
|
-
describe Foo do
|
26
|
-
subject(:foo) { described_class.new }
|
27
|
-
|
28
|
-
before do
|
29
|
-
expect(foo).to receive(:bar).and_return(baz)
|
30
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
|
31
|
-
expect(foo).to receive(:bar)
|
32
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
|
33
|
-
expect(foo).to receive(:bar).with(1)
|
34
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
|
35
|
-
expect(foo).to receive(:bar).with(1).and_return(2)
|
36
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'uses expect twice' do
|
40
|
-
expect(foo.bar).to eq(baz)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
RUBY
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'ignores stub within context where subject name changed' do
|
47
|
-
expect_no_violations(<<-RUBY)
|
48
|
-
describe Foo do
|
49
|
-
subject(:foo) { described_class.new }
|
50
|
-
|
51
|
-
context 'when I shake things up' do
|
52
|
-
subject(:bar) { described_class.new }
|
53
|
-
|
54
|
-
it 'tries to trick rubocop-rspec' do
|
55
|
-
allow(foo).to receive(:baz)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
RUBY
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'flags nested subject stubs when nested subject uses same name' do
|
63
|
-
expect_violation(<<-RUBY)
|
64
|
-
describe Foo do
|
65
|
-
subject(:foo) { described_class.new }
|
66
|
-
|
67
|
-
context 'when I shake things up' do
|
68
|
-
subject(:foo) { described_class.new }
|
69
|
-
|
70
|
-
before do
|
71
|
-
allow(foo).to receive(:wow)
|
72
|
-
^^^^^^^^^^ Do not stub your test subject.
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'tries to trick rubocop-rspec' do
|
76
|
-
expect(foo).to eql(:neat)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
RUBY
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'ignores nested stubs when nested subject is anonymous' do
|
84
|
-
expect_no_violations(<<-RUBY)
|
85
|
-
describe Foo do
|
86
|
-
subject(:foo) { described_class.new }
|
87
|
-
|
88
|
-
context 'when I shake things up' do
|
89
|
-
subject { described_class.new }
|
90
|
-
|
91
|
-
before do
|
92
|
-
allow(foo).to receive(:wow)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'tries to trick rubocop-rspec' do
|
96
|
-
expect(foo).to eql(:neat)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
RUBY
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'flags nested subject stubs when example group does not define subject' do
|
104
|
-
expect_violation(<<-RUBY)
|
105
|
-
describe Foo do
|
106
|
-
subject(:foo) { described_class.new }
|
107
|
-
|
108
|
-
context 'when I shake things up' do
|
109
|
-
before do
|
110
|
-
allow(foo).to receive(:wow)
|
111
|
-
^^^^^^^^^^ Do not stub your test subject.
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'tries to trick rubocop-rspec' do
|
115
|
-
expect(foo).to eql(:neat)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
RUBY
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'flags nested subject stubs' do
|
123
|
-
expect_violation(<<-RUBY)
|
124
|
-
describe Foo do
|
125
|
-
subject(:foo) { described_class.new }
|
126
|
-
|
127
|
-
context 'when I shake things up' do
|
128
|
-
subject(:bar) { described_class.new }
|
129
|
-
|
130
|
-
before do
|
131
|
-
allow(foo).to receive(:wow)
|
132
|
-
allow(bar).to receive(:wow)
|
133
|
-
^^^^^^^^^^ Do not stub your test subject.
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'tries to trick rubocop-rspec' do
|
137
|
-
expect(bar).to eql(foo)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
RUBY
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'flags nested subject stubs when adjacent context redefines' do
|
145
|
-
expect_violation(<<-RUBY)
|
146
|
-
describe Foo do
|
147
|
-
subject(:foo) { described_class.new }
|
148
|
-
|
149
|
-
context 'when I do something in a context' do
|
150
|
-
subject { blah }
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'still flags this test' do
|
154
|
-
allow(foo).to receive(:blah)
|
155
|
-
^^^^^^^^^^ Do not stub your test subject.
|
156
|
-
end
|
157
|
-
end
|
158
|
-
RUBY
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'flags deeply nested subject stubs' do
|
162
|
-
expect_violation(<<-RUBY)
|
163
|
-
describe Foo do
|
164
|
-
subject(:foo) { described_class.new }
|
165
|
-
|
166
|
-
context 'level 1' do
|
167
|
-
subject(:bar) { described_class.new }
|
168
|
-
|
169
|
-
context 'level 2' do
|
170
|
-
subject(:baz) { described_class.new }
|
171
|
-
|
172
|
-
before do
|
173
|
-
allow(foo).to receive(:wow)
|
174
|
-
allow(bar).to receive(:wow)
|
175
|
-
allow(baz).to receive(:wow)
|
176
|
-
^^^^^^^^^^ Do not stub your test subject.
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
RUBY
|
182
|
-
end
|
183
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do
|
2
|
-
subject(:cop) { described_class.new(config) }
|
3
|
-
|
4
|
-
it 'finds a `double` instead of an `instance_double`' do
|
5
|
-
expect_violation(<<-RUBY)
|
6
|
-
it do
|
7
|
-
foo = double("Widget")
|
8
|
-
^^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
|
9
|
-
end
|
10
|
-
RUBY
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'when configuration does not specify IgnoreSymbolicNames' do
|
14
|
-
let(:cop_config) { Hash.new }
|
15
|
-
|
16
|
-
it 'find doubles whose name is a symbol' do
|
17
|
-
expect_violation(<<-RUBY)
|
18
|
-
it do
|
19
|
-
foo = double(:widget)
|
20
|
-
^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
|
21
|
-
end
|
22
|
-
RUBY
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'finds a `spy` instead of an `instance_spy`' do
|
26
|
-
expect_violation(<<-RUBY)
|
27
|
-
it do
|
28
|
-
foo = spy("Widget")
|
29
|
-
^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
|
30
|
-
end
|
31
|
-
RUBY
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when configured to ignore symbolic names' do
|
36
|
-
let(:cop_config) { { 'IgnoreSymbolicNames' => true } }
|
37
|
-
|
38
|
-
it 'ignores doubles whose name is a symbol' do
|
39
|
-
expect_no_violations(<<-RUBY)
|
40
|
-
it do
|
41
|
-
foo = double(:widget)
|
42
|
-
end
|
43
|
-
RUBY
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'still flags doubles whose name is a string' do
|
47
|
-
expect_violation(<<-RUBY)
|
48
|
-
it do
|
49
|
-
foo = double("widget")
|
50
|
-
^^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
|
51
|
-
end
|
52
|
-
RUBY
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'ignores doubles without a name' do
|
57
|
-
expect_no_violations(<<-RUBY)
|
58
|
-
it do
|
59
|
-
foo = double
|
60
|
-
end
|
61
|
-
RUBY
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'ignores instance_doubles' do
|
65
|
-
expect_no_violations(<<-RUBY)
|
66
|
-
it do
|
67
|
-
foo = instance_double("Foo")
|
68
|
-
end
|
69
|
-
RUBY
|
70
|
-
end
|
71
|
-
end
|