lib/rubocop/cop/rspec/described_class.rb in rubocop-rspec-1.6.0 vs lib/rubocop/cop/rspec/described_class.rb in rubocop-rspec-1.7.0

- old
+ new

@@ -1,10 +1,12 @@ # frozen_string_literal: true module RuboCop module Cop module RSpec + # Checks that tests use `described_class`. + # # If the first argument of describe is a class, the class is exposed to # each example via described_class - this should be used instead of # repeating the class. # # @example @@ -16,48 +18,15 @@ # # good # describe MyClass do # subject { described_class.do_something } # end class DescribedClass < Cop - include RuboCop::RSpec::TopLevelDescribe + include RuboCop::RSpec::SpecOnly, RuboCop::RSpec::TopLevelDescribe DESCRIBED_CLASS = 'described_class'.freeze MSG = "Use `#{DESCRIBED_CLASS}` instead of `%s`".freeze - RSPEC_BLOCK_METHODS = ' - :after - :around - :before - :context - :describe - :example - :example_group - :fcontext - :fdescribe - :feature - :fexample - :ffeature - :fit - :focus - :fscenario - :fspecify - :it - :let - :let! - :scenario - :specify - :xcontext - :xdescribe - :xexample - :xfeature - :xit - :xscenario - :xspecify - '.freeze - - def_node_matcher :described_constant, <<-PATTERN - (block $(send _ :describe $(const ...)) (args) $_) - PATTERN + RSPEC_BLOCK_METHODS = RuboCop::RSpec::Language::ALL.to_node_pattern def_node_matcher :common_instance_exec_closure?, <<-PATTERN (block (send (const nil {:Class :Module}) :new ...) ...) PATTERN