From 7b43684f6813df52eae8b6b50d7cf347a0465410 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Sun, 24 May 2020 21:10:19 +0200 Subject: [PATCH] Remove explicit `subject(:cop)` from specs In https://github.com/rubocop-hq/rubocop/pull/7970 the shared context `config` was updated to include the following: let(:cop) do cop_class.new(config, cop_options) .tap { |cop| cop.processed_source = processed_source } end This is functionally equivalent to what we have all over our specs: subject(:cop) { described_class.new(config) } The downside is that our specs become a less explicit. Actually they now have a mystery guest, which may be considered a smell. --- spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb | 2 -- spec/rubocop/cop/rspec/context_wording_spec.rb | 2 -- spec/rubocop/cop/rspec/described_class_spec.rb | 2 -- spec/rubocop/cop/rspec/dialect_spec.rb | 2 -- spec/rubocop/cop/rspec/empty_example_group_spec.rb | 2 -- spec/rubocop/cop/rspec/empty_line_after_example_spec.rb | 2 -- spec/rubocop/cop/rspec/example_length_spec.rb | 2 -- spec/rubocop/cop/rspec/example_without_description_spec.rb | 2 -- spec/rubocop/cop/rspec/example_wording_spec.rb | 2 -- spec/rubocop/cop/rspec/expect_actual_spec.rb | 2 -- spec/rubocop/cop/rspec/expect_change_spec.rb | 2 -- spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb | 2 -- spec/rubocop/cop/rspec/file_path_spec.rb | 2 -- spec/rubocop/cop/rspec/hook_argument_spec.rb | 2 -- spec/rubocop/cop/rspec/implicit_expect_spec.rb | 2 -- spec/rubocop/cop/rspec/implicit_subject_spec.rb | 2 -- spec/rubocop/cop/rspec/instance_variable_spec.rb | 2 -- spec/rubocop/cop/rspec/it_behaves_like_spec.rb | 2 -- spec/rubocop/cop/rspec/message_expectation_spec.rb | 2 -- spec/rubocop/cop/rspec/message_spies_spec.rb | 2 -- spec/rubocop/cop/rspec/multiple_expectations_spec.rb | 2 -- spec/rubocop/cop/rspec/named_subject_spec.rb | 2 -- spec/rubocop/cop/rspec/nested_groups_spec.rb | 2 -- spec/rubocop/cop/rspec/not_to_not_spec.rb | 2 -- spec/rubocop/cop/rspec/predicate_matcher_spec.rb | 2 -- spec/rubocop/cop/rspec/rails/http_status_spec.rb | 2 -- spec/rubocop/cop/rspec/return_from_stub_spec.rb | 2 -- spec/rubocop/cop/rspec/variable_definition_spec.rb | 2 -- spec/rubocop/cop/rspec/variable_name_spec.rb | 2 -- spec/rubocop/cop/rspec/verified_doubles_spec.rb | 2 -- 30 files changed, 60 deletions(-) diff --git a/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb b/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb index d6851b833..e7dfc0dff 100644 --- a/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +++ b/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::Capybara::FeatureMethods, :config do - subject(:cop) { described_class.new(config) } - it 'flags violations for `background`' do expect_offense(<<-RUBY) describe 'some feature' do diff --git a/spec/rubocop/cop/rspec/context_wording_spec.rb b/spec/rubocop/cop/rspec/context_wording_spec.rb index 53979c05d..2b2314ec4 100644 --- a/spec/rubocop/cop/rspec/context_wording_spec.rb +++ b/spec/rubocop/cop/rspec/context_wording_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ContextWording, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) { { 'Prefixes' => %w[when with] } } it 'skips describe blocks' do diff --git a/spec/rubocop/cop/rspec/described_class_spec.rb b/spec/rubocop/cop/rspec/described_class_spec.rb index 95d0895b3..ef928b48f 100644 --- a/spec/rubocop/cop/rspec/described_class_spec.rb +++ b/spec/rubocop/cop/rspec/described_class_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::DescribedClass, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) { {} } context 'when SkipBlocks is `true`' do diff --git a/spec/rubocop/cop/rspec/dialect_spec.rb b/spec/rubocop/cop/rspec/dialect_spec.rb index a1fcb2d7e..7ddb32525 100644 --- a/spec/rubocop/cop/rspec/dialect_spec.rb +++ b/spec/rubocop/cop/rspec/dialect_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::Dialect, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'PreferredMethods' => { diff --git a/spec/rubocop/cop/rspec/empty_example_group_spec.rb b/spec/rubocop/cop/rspec/empty_example_group_spec.rb index 33fe29670..ae5a8596d 100644 --- a/spec/rubocop/cop/rspec/empty_example_group_spec.rb +++ b/spec/rubocop/cop/rspec/empty_example_group_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::EmptyExampleGroup, :config do - subject(:cop) { described_class.new(config) } - it 'flags an empty context' do expect_offense(<<-RUBY) describe Foo do diff --git a/spec/rubocop/cop/rspec/empty_line_after_example_spec.rb b/spec/rubocop/cop/rspec/empty_line_after_example_spec.rb index 35af6b805..4ed8c1534 100644 --- a/spec/rubocop/cop/rspec/empty_line_after_example_spec.rb +++ b/spec/rubocop/cop/rspec/empty_line_after_example_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterExample, :config do - subject(:cop) { described_class.new(config) } - it 'flags a missing empty line after `it`' do expect_offense(<<-RUBY) RSpec.describe Foo do diff --git a/spec/rubocop/cop/rspec/example_length_spec.rb b/spec/rubocop/cop/rspec/example_length_spec.rb index b01f88e7f..99395f51a 100644 --- a/spec/rubocop/cop/rspec/example_length_spec.rb +++ b/spec/rubocop/cop/rspec/example_length_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ExampleLength, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) { { 'Max' => 3 } } it 'ignores non-spec blocks' do diff --git a/spec/rubocop/cop/rspec/example_without_description_spec.rb b/spec/rubocop/cop/rspec/example_without_description_spec.rb index a480ad301..30f9a6822 100644 --- a/spec/rubocop/cop/rspec/example_without_description_spec.rb +++ b/spec/rubocop/cop/rspec/example_without_description_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ExampleWithoutDescription, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'EnforcedStyle' => enforced_style } end diff --git a/spec/rubocop/cop/rspec/example_wording_spec.rb b/spec/rubocop/cop/rspec/example_wording_spec.rb index 0248dce33..0341c4584 100644 --- a/spec/rubocop/cop/rspec/example_wording_spec.rb +++ b/spec/rubocop/cop/rspec/example_wording_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do - subject(:cop) { described_class.new(config) } - context 'with configuration' do let(:cop_config) do { diff --git a/spec/rubocop/cop/rspec/expect_actual_spec.rb b/spec/rubocop/cop/rspec/expect_actual_spec.rb index 852c1c5c8..fdb5c8b1d 100644 --- a/spec/rubocop/cop/rspec/expect_actual_spec.rb +++ b/spec/rubocop/cop/rspec/expect_actual_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ExpectActual, :config do - subject(:cop) { described_class.new(config) } - it 'flags numeric literal values within expect(...)' do expect_offense(<<-RUBY) describe Foo do diff --git a/spec/rubocop/cop/rspec/expect_change_spec.rb b/spec/rubocop/cop/rspec/expect_change_spec.rb index e284983fa..9985e89a1 100644 --- a/spec/rubocop/cop/rspec/expect_change_spec.rb +++ b/spec/rubocop/cop/rspec/expect_change_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ExpectChange, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'EnforcedStyle' => enforced_style } end diff --git a/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb b/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb index 31e08eaa7..10af6187a 100644 --- a/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +++ b/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::FactoryBot::CreateList, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'EnforcedStyle' => enforced_style } end diff --git a/spec/rubocop/cop/rspec/file_path_spec.rb b/spec/rubocop/cop/rspec/file_path_spec.rb index fd1193c14..c9d96eba8 100644 --- a/spec/rubocop/cop/rspec/file_path_spec.rb +++ b/spec/rubocop/cop/rspec/file_path_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::FilePath, :config do - subject(:cop) { described_class.new(config) } - it 'registers an offense for a bad path' do expect_offense(<<-RUBY, 'wrong_path_foo_spec.rb') describe MyClass, 'foo' do; end diff --git a/spec/rubocop/cop/rspec/hook_argument_spec.rb b/spec/rubocop/cop/rspec/hook_argument_spec.rb index e07c051b1..187df850a 100644 --- a/spec/rubocop/cop/rspec/hook_argument_spec.rb +++ b/spec/rubocop/cop/rspec/hook_argument_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::HookArgument, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'EnforcedStyle' => enforced_style } end diff --git a/spec/rubocop/cop/rspec/implicit_expect_spec.rb b/spec/rubocop/cop/rspec/implicit_expect_spec.rb index 876a090fa..1c2df2fda 100644 --- a/spec/rubocop/cop/rspec/implicit_expect_spec.rb +++ b/spec/rubocop/cop/rspec/implicit_expect_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do - subject(:cop) { described_class.new(config) } - context 'when EnforcedStyle is is_expected' do let(:cop_config) do { 'EnforcedStyle' => 'is_expected' } diff --git a/spec/rubocop/cop/rspec/implicit_subject_spec.rb b/spec/rubocop/cop/rspec/implicit_subject_spec.rb index b1c04e388..a9fc73874 100644 --- a/spec/rubocop/cop/rspec/implicit_subject_spec.rb +++ b/spec/rubocop/cop/rspec/implicit_subject_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'EnforcedStyle' => enforced_style } end diff --git a/spec/rubocop/cop/rspec/instance_variable_spec.rb b/spec/rubocop/cop/rspec/instance_variable_spec.rb index 0e398c0d0..b9ba3a2e4 100644 --- a/spec/rubocop/cop/rspec/instance_variable_spec.rb +++ b/spec/rubocop/cop/rspec/instance_variable_spec.rb @@ -131,8 +131,6 @@ def serialize end context 'when configured with AssignmentOnly', :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'AssignmentOnly' => true } end diff --git a/spec/rubocop/cop/rspec/it_behaves_like_spec.rb b/spec/rubocop/cop/rspec/it_behaves_like_spec.rb index 6ef27ba2d..d49120c43 100644 --- a/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +++ b/spec/rubocop/cop/rspec/it_behaves_like_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ItBehavesLike, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'EnforcedStyle' => enforced_style } end diff --git a/spec/rubocop/cop/rspec/message_expectation_spec.rb b/spec/rubocop/cop/rspec/message_expectation_spec.rb index 3d7a63dfc..71051dd0f 100644 --- a/spec/rubocop/cop/rspec/message_expectation_spec.rb +++ b/spec/rubocop/cop/rspec/message_expectation_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::MessageExpectation, :config do - subject(:cop) { described_class.new(config) } - context 'when EnforcedStyle is allow' do let(:cop_config) do { 'EnforcedStyle' => 'allow' } diff --git a/spec/rubocop/cop/rspec/message_spies_spec.rb b/spec/rubocop/cop/rspec/message_spies_spec.rb index fe6bce12f..3905036ca 100644 --- a/spec/rubocop/cop/rspec/message_spies_spec.rb +++ b/spec/rubocop/cop/rspec/message_spies_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::MessageSpies, :config do - subject(:cop) { described_class.new(config) } - context 'when EnforcedStyle is have_received' do let(:cop_config) do { 'EnforcedStyle' => 'have_received' } diff --git a/spec/rubocop/cop/rspec/multiple_expectations_spec.rb b/spec/rubocop/cop/rspec/multiple_expectations_spec.rb index ded0b91a9..7d8d2363e 100644 --- a/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +++ b/spec/rubocop/cop/rspec/multiple_expectations_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::MultipleExpectations, :config do - subject(:cop) { described_class.new(config) } - context 'without configuration' do let(:cop_config) { {} } diff --git a/spec/rubocop/cop/rspec/named_subject_spec.rb b/spec/rubocop/cop/rspec/named_subject_spec.rb index a4bda0014..ae89c0a31 100644 --- a/spec/rubocop/cop/rspec/named_subject_spec.rb +++ b/spec/rubocop/cop/rspec/named_subject_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::NamedSubject, :config do - subject(:cop) { described_class.new(config) } - shared_examples_for 'checking subject outside of shared examples' do it 'checks `it` and `specify` for explicit subject usage' do expect_offense(<<-RUBY) diff --git a/spec/rubocop/cop/rspec/nested_groups_spec.rb b/spec/rubocop/cop/rspec/nested_groups_spec.rb index 48b01b168..e9d47f617 100644 --- a/spec/rubocop/cop/rspec/nested_groups_spec.rb +++ b/spec/rubocop/cop/rspec/nested_groups_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::NestedGroups, :config do - subject(:cop) { described_class.new(config) } - it 'flags nested contexts' do expect_offense(<<-RUBY) describe MyClass do diff --git a/spec/rubocop/cop/rspec/not_to_not_spec.rb b/spec/rubocop/cop/rspec/not_to_not_spec.rb index 2e937f158..93706b6c3 100644 --- a/spec/rubocop/cop/rspec/not_to_not_spec.rb +++ b/spec/rubocop/cop/rspec/not_to_not_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::NotToNot, :config do - subject(:cop) { described_class.new(config) } - context 'when EnforcedStyle is `not_to`' do let(:cop_config) { { 'EnforcedStyle' => 'not_to' } } diff --git a/spec/rubocop/cop/rspec/predicate_matcher_spec.rb b/spec/rubocop/cop/rspec/predicate_matcher_spec.rb index 1d1935dda..02fe996fd 100644 --- a/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +++ b/spec/rubocop/cop/rspec/predicate_matcher_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::PredicateMatcher, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'EnforcedStyle' => enforced_style, 'Strict' => strict, diff --git a/spec/rubocop/cop/rspec/rails/http_status_spec.rb b/spec/rubocop/cop/rspec/rails/http_status_spec.rb index 410a69c81..d4ca57c8e 100644 --- a/spec/rubocop/cop/rspec/rails/http_status_spec.rb +++ b/spec/rubocop/cop/rspec/rails/http_status_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::Rails::HttpStatus, :config do - subject(:cop) { described_class.new(config) } - context 'when EnforcedStyle is `symbolic`' do let(:cop_config) { { 'EnforcedStyle' => 'symbolic' } } diff --git a/spec/rubocop/cop/rspec/return_from_stub_spec.rb b/spec/rubocop/cop/rspec/return_from_stub_spec.rb index b9294d770..253191911 100644 --- a/spec/rubocop/cop/rspec/return_from_stub_spec.rb +++ b/spec/rubocop/cop/rspec/return_from_stub_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::ReturnFromStub, :config do - subject(:cop) { described_class.new(config) } - let(:cop_config) do { 'EnforcedStyle' => enforced_style } end diff --git a/spec/rubocop/cop/rspec/variable_definition_spec.rb b/spec/rubocop/cop/rspec/variable_definition_spec.rb index 2a0452523..7b1c90993 100644 --- a/spec/rubocop/cop/rspec/variable_definition_spec.rb +++ b/spec/rubocop/cop/rspec/variable_definition_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::VariableDefinition, :config do - subject(:cop) { described_class.new(config) } - context 'when EnforcedStyle is `symbols`' do let(:cop_config) { { 'EnforcedStyle' => 'symbols' } } diff --git a/spec/rubocop/cop/rspec/variable_name_spec.rb b/spec/rubocop/cop/rspec/variable_name_spec.rb index 64b12d3be..5796baff9 100644 --- a/spec/rubocop/cop/rspec/variable_name_spec.rb +++ b/spec/rubocop/cop/rspec/variable_name_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::VariableName, :config do - subject(:cop) { described_class.new(config) } - context 'when configured for `snake_case`' do let(:cop_config) { { 'EnforcedStyle' => 'snake_case' } } diff --git a/spec/rubocop/cop/rspec/verified_doubles_spec.rb b/spec/rubocop/cop/rspec/verified_doubles_spec.rb index 5b8291c30..2b56ce87c 100644 --- a/spec/rubocop/cop/rspec/verified_doubles_spec.rb +++ b/spec/rubocop/cop/rspec/verified_doubles_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do - subject(:cop) { described_class.new(config) } - it 'finds a `double` instead of an `instance_double`' do expect_offense(<<-RUBY) it do