Module: RuboCop::RSpec::SpecOnly
- Included in:
- Cop::RSpec::AnyInstance, Cop::RSpec::BeEql, Cop::RSpec::DescribeClass, Cop::RSpec::DescribeMethod, Cop::RSpec::DescribedClass, Cop::RSpec::EmptyExampleGroup, Cop::RSpec::ExampleLength, Cop::RSpec::ExampleWording, Cop::RSpec::ExpectActual, Cop::RSpec::FilePath, Cop::RSpec::Focus, Cop::RSpec::HookArgument, Cop::RSpec::InstanceVariable, Cop::RSpec::LeadingSubject, Cop::RSpec::LetSetup, Cop::RSpec::MessageChain, Cop::RSpec::MessageExpectation, Cop::RSpec::MultipleDescribes, Cop::RSpec::MultipleExpectations, Cop::RSpec::NamedSubject, Cop::RSpec::NestedGroups, Cop::RSpec::NotToNot, Cop::RSpec::SubjectStub, Cop::RSpec::VerifiedDoubles
- Defined in:
- lib/rubocop/rspec/spec_only.rb
Overview
this functionality is implemented via this mixin instead of a subclass of ‘RuboCop::Cop::Cop` because the `Cop` class assumes that it will be the direct superclass of all cops. For example, if the ancestry of a cop looked like this:
class RuboCop::RSpec::Cop < RuboCop::Cop::Cop
end
class RuboCop::RSpec::SpecCop < RuboCop::RSpec::Cop
end
then ‘SpecCop` will fail to be registered on the class instance variable of `Cop` which tracks all descendants via `.inherited`.
While we could match this behavior and provide a rubocop-rspec Cop parent class, it would rely heavily on the implementation details of RuboCop itself which is largly private API. This would be irresponsible since any patch level release of rubocop could break integrations for users of rubocop-rspec
Mixin for cops that skips non-spec files
The criteria for whether rubocop-rspec analyzes a certain ruby file is configured via ‘AllCops/RSpec`. For example, if you want to customize your project to scan all files within a `test/` directory then you could add this to your configuration:
Constant Summary collapse
- DEFAULT_CONFIGURATION =
CONFIG.fetch('AllCops').fetch('RSpec')
Instance Method Summary collapse
Instance Method Details
#relevant_file?(file) ⇒ Boolean
43 44 45 |
# File 'lib/rubocop/rspec/spec_only.rb', line 43 def relevant_file?(file) rspec_pattern =~ file && super end |