Skip to content
Snippets Groups Projects
Unverified Commit 800853a2 authored by Mike McQuaid's avatar Mike McQuaid
Browse files

Vendor rubocop-rspec

We aren't going to vendor its dependencies because we already require
a systemwide installation of `rubocop` to work in your editor. This
avoids requiring users to manually do another
`gem install rubocop-rspec` to have their editor integration behave as
expected.
parent f04b0b31
No related branches found
No related tags found
No related merge requests found
Showing
with 1224 additions and 5 deletions
......@@ -23,7 +23,9 @@
**/.bundle/cache
**/vendor/bundle
**/vendor/ruby
**/vendor/bundle-standalone/ruby/*/bin
**/vendor/bundle-standalone/ruby/*/cache
**/vendor/bundle-standalone/ruby/*/extensions
**/vendor/bundle-standalone/ruby/*/gems/*/*
**/vendor/bundle-standalone/ruby/*/specifications
......@@ -39,6 +41,17 @@
**/vendor/bundle-standalone/ruby/*/gems/thread_safe-*/lib
**/vendor/bundle-standalone/ruby/*/gems/tzinfo-*/lib
# Ignore rubocop dependencies we don't wish to vendor
**/vendor/bundle-standalone/ruby/*/gems/ast-*/
**/vendor/bundle-standalone/ruby/*/gems/jaro_winkler-*/
**/vendor/bundle-standalone/ruby/*/gems/parallel-*/
**/vendor/bundle-standalone/ruby/*/gems/parser-*/
**/vendor/bundle-standalone/ruby/*/gems/powerpack-*/
**/vendor/bundle-standalone/ruby/*/gems/rainbow-*/
**/vendor/bundle-standalone/ruby/*/gems/rubocop-*/
**/vendor/bundle-standalone/ruby/*/gems/ruby-progressbar-*/
**/vendor/bundle-standalone/ruby/*/gems/unicode-display_width-*/
# Ignore `bin` contents (again).
/bin
......
......@@ -5,9 +5,7 @@ AllCops:
- '**/vendor/**/*'
DisplayCopNames: false
require:
- ./Homebrew/rubocops.rb
- rubocop-rspec
require: ./Homebrew/rubocops.rb
# enable all formulae audits
FormulaAudit:
......
require_relative "load_path"
require "rubocop-rspec"
require "rubocops/formula_desc_cop"
require "rubocops/components_order_cop"
require "rubocops/components_redundancy_cop"
......
......@@ -8,7 +8,6 @@ gem "rspec-its", require: false
gem "rspec-retry", require: false
gem "rspec-wait", require: false
gem "rubocop", HOMEBREW_RUBOCOP_VERSION
gem "rubocop-rspec", require: false
group :development do
gem "ronn", require: false
......
......@@ -5,3 +5,8 @@ gem "concurrent-ruby"
gem "backports"
gem "plist"
gem "ruby-macho"
gem "rubocop-rspec"
# not actually vendored but used to ensure the version matches here.
require_relative "../constants"
gem "rubocop", HOMEBREW_RUBOCOP_VERSION
......@@ -6,16 +6,35 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
ast (2.4.0)
backports (3.11.4)
concurrent-ruby (1.0.5)
i18n (1.1.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1)
minitest (5.11.3)
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
plist (3.4.0)
powerpack (0.1.2)
rainbow (3.0.0)
rubocop (0.59.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.30.0)
rubocop (>= 0.58.0)
ruby-macho (2.1.0)
ruby-progressbar (1.10.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.4.0)
PLATFORMS
ruby
......@@ -25,7 +44,9 @@ DEPENDENCIES
backports
concurrent-ruby
plist
rubocop (= 0.59.1)
rubocop-rspec
ruby-macho
BUNDLED WITH
1.16.4
1.16.6
......@@ -9,7 +9,18 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/minitest-5.11.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/thread_safe-0.3.6/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tzinfo-1.2.5/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/activesupport-5.2.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ast-2.4.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/backports-3.11.4/lib"
$:.unshift "#{path}/"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-18/2.3.0/jaro_winkler-1.5.1"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/jaro_winkler-1.5.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parallel-1.12.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parser-2.5.1.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/plist-3.4.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/powerpack-0.1.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rainbow-3.0.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.10.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.4.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.59.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.30.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.1.0/lib"
---
AllCops:
RSpec:
Patterns:
- _spec.rb
- "(?:^|/)spec/"
RSpec/FactoryBot:
Patterns:
- spec/factories.rb
- spec/factories/**/*.rb
- features/support/factories/**/*.rb
RSpec/AlignLeftLetBrace:
Description: Checks that left braces for adjacent single line lets are aligned.
Enabled: false
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AlignLeftLetBrace
RSpec/AlignRightLetBrace:
Description: Checks that right braces for adjacent single line lets are aligned.
Enabled: false
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AlignRightLetBrace
RSpec/AnyInstance:
Description: Check that instances are not being stubbed globally.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AnyInstance
RSpec/AroundBlock:
Description: Checks that around blocks actually run the test.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AroundBlock
RSpec/Be:
Description: Check for expectations where `be` is used without argument.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Be
RSpec/BeEql:
Description: Check for expectations where `be(...)` can replace `eql(...)`.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEql
RSpec/BeforeAfterAll:
Description: Check that before/after(:all) isn't being used.
Enabled: true
Exclude:
- spec/spec_helper.rb
- spec/rails_helper.rb
- spec/support/**/*.rb
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll
RSpec/ContextWording:
Description: "`context` block descriptions should start with 'when', or 'with'."
Enabled: true
Prefixes:
- when
- with
- without
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContextWording
RSpec/DescribeClass:
Description: Check that the first argument to the top level describe is a constant.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass
RSpec/DescribeMethod:
Description: Checks that the second argument to `describe` specifies a method.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeMethod
RSpec/DescribeSymbol:
Description: Avoid describing symbols.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeSymbol
RSpec/DescribedClass:
Description: Checks that tests use `described_class`.
SkipBlocks: false
Enabled: true
EnforcedStyle: described_class
SupportedStyles:
- described_class
- explicit
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass
RSpec/EmptyExampleGroup:
Description: Checks if an example group does not include any tests.
Enabled: true
CustomIncludeMethods: []
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup
RSpec/EmptyLineAfterExampleGroup:
Description: Checks if there is an empty line after example group blocks.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExampleGroup
RSpec/EmptyLineAfterFinalLet:
Description: Checks if there is an empty line after the last let block.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet
RSpec/EmptyLineAfterHook:
Description: Checks if there is an empty line after hook blocks.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterHook
RSpec/EmptyLineAfterSubject:
Description: Checks if there is an empty line after subject block.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterSubject
RSpec/ExampleLength:
Description: Checks for long examples.
Enabled: true
Max: 5
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleLength
RSpec/ExampleWithoutDescription:
Description: Checks for examples without a description.
Enabled: true
EnforcedStyle: always_allow
SupportedStyles:
- always_allow
- single_line_only
- disallow
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWithoutDescription
RSpec/ExampleWording:
Description: Checks for common mistakes in example descriptions.
Enabled: true
CustomTransform:
be: is
BE: IS
have: has
HAVE: HAS
IgnoredWords: []
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWording
RSpec/ExpectActual:
Description: Checks for `expect(...)` calls containing literal values.
Enabled: true
Exclude:
- spec/routing/**/*
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectActual
RSpec/ExpectChange:
Description: Checks for consistent style of change matcher.
Enabled: true
EnforcedStyle: method_call
SupportedStyles:
- method_call
- block
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectChange
RSpec/ExpectInHook:
Enabled: true
Description: Do not use `expect` in hooks such as `before`.
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectInHook
RSpec/ExpectOutput:
Description: Checks for opportunities to use `expect { ... }.to output`.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectOutput
RSpec/FilePath:
Description: Checks that spec file paths are consistent with the test subject.
Enabled: true
CustomTransform:
RuboCop: rubocop
RSpec: rspec
IgnoreMethods: false
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FilePath
RSpec/Focus:
Description: Checks if examples are focused.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Focus
RSpec/HookArgument:
Description: Checks the arguments passed to `before`, `around`, and `after`.
Enabled: true
EnforcedStyle: implicit
SupportedStyles:
- implicit
- each
- example
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HookArgument
RSpec/HooksBeforeExamples:
Enabled: true
Description: Checks for before/around/after hooks that come after an example.
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HooksBeforeExamples
RSpec/ImplicitExpect:
Description: Check that a consistent implicit expectation style is used.
Enabled: true
EnforcedStyle: is_expected
SupportedStyles:
- is_expected
- should
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitExpect
RSpec/ImplicitSubject:
Enabled: true
Description: Checks for usage of implicit subject (`is_expected` / `should`).
EnforcedStyle: single_line_only
SupportedStyles:
- single_line_only
- single_statement_only
- disallow
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitSubject
RSpec/InstanceSpy:
Description: Checks for `instance_double` used with `have_received`.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceSpy
RSpec/InstanceVariable:
Description: Checks for instance variable usage in specs.
AssignmentOnly: false
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceVariable
RSpec/InvalidPredicateMatcher:
Description: Checks invalid usage for predicate matcher.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InvalidPredicateMatcher
RSpec/ItBehavesLike:
Description: Checks that only one `it_behaves_like` style is used.
Enabled: true
EnforcedStyle: it_behaves_like
SupportedStyles:
- it_behaves_like
- it_should_behave_like
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ItBehavesLike
RSpec/IteratedExpectation:
Description: Check that `all` matcher is used instead of iterating over an array.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IteratedExpectation
RSpec/LeadingSubject:
Description: Enforce that subject is the first definition in the test.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LeadingSubject
RSpec/LetBeforeExamples:
Description: Checks for `let` definitions that come after an example.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetBeforeExamples
RSpec/LetSetup:
Description: Checks unreferenced `let!` calls being used for test setup.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetSetup
RSpec/MessageChain:
Description: Check that chains of messages are not being stubbed.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageChain
RSpec/MessageExpectation:
Description: Checks for consistent message expectation style.
Enabled: false
EnforcedStyle: allow
SupportedStyles:
- allow
- expect
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageExpectation
RSpec/MessageSpies:
Description: Checks that message expectations are set using spies.
Enabled: true
EnforcedStyle: have_received
SupportedStyles:
- have_received
- receive
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageSpies
RSpec/MissingExampleGroupArgument:
Description: Checks that the first argument to an example group is not empty.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MissingExampleGroupArgument
RSpec/MultipleDescribes:
Description: Checks for multiple top level describes.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleDescribes
RSpec/MultipleExpectations:
Description: Checks if examples contain too many `expect` calls.
Enabled: true
Max: 1
AggregateFailuresByDefault: false
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleExpectations
RSpec/MultipleSubjects:
Description: Checks if an example group defines `subject` multiple times.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleSubjects
RSpec/NamedSubject:
Description: Checks for explicitly referenced test subjects.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NamedSubject
RSpec/NestedGroups:
Description: Checks for nested example groups.
Enabled: true
Max: 3
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NestedGroups
RSpec/NotToNot:
Description: Checks for consistent method usage for negating expectations.
EnforcedStyle: not_to
SupportedStyles:
- not_to
- to_not
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NotToNot
RSpec/OverwritingSetup:
Enabled: true
Description: Checks if there is a let/subject that overwrites an existing one.
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/OverwritingSetup
RSpec/Pending:
Enabled: false
Description: Checks for any pending or skipped examples.
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Pending
RSpec/PredicateMatcher:
Description: Prefer using predicate matcher over using predicate method directly.
Enabled: true
Strict: true
EnforcedStyle: inflected
SupportedStyles:
- inflected
- explicit
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/PredicateMatcher
RSpec/ReceiveCounts:
Enabled: true
Description: Check for `once` and `twice` receive counts matchers usage.
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveCounts
RSpec/ReceiveNever:
Enabled: true
Description: Prefer `not_to receive(...)` over `receive(...).never`.
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveNever
RSpec/RepeatedDescription:
Enabled: true
Description: Check for repeated description strings in example groups.
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedDescription
RSpec/RepeatedExample:
Enabled: true
Description: Check for repeated examples within example groups.
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExample
RSpec/ReturnFromStub:
Enabled: true
Description: Checks for consistent style of stub's return setting.
EnforcedStyle: and_return
SupportedStyles:
- and_return
- block
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReturnFromStub
RSpec/ScatteredLet:
Description: Checks for let scattered across the example group.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredLet
RSpec/ScatteredSetup:
Description: Checks for setup scattered across multiple hooks in an example group.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredSetup
RSpec/SharedContext:
Description: Checks for proper shared_context and shared_examples usage.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SharedContext
RSpec/SharedExamples:
Description: Enforces use of string to titleize shared examples.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SharedExamples
RSpec/SingleArgumentMessageChain:
Description: Checks that chains of messages contain more than one element.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SingleArgumentMessageChain
RSpec/SubjectStub:
Description: Checks for stubbed test subjects.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SubjectStub
RSpec/UnspecifiedException:
Description: Checks for a specified error in checking raised errors.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/UnspecifiedException
RSpec/VerifiedDoubles:
Description: Prefer using verifying doubles over normal doubles.
Enabled: true
IgnoreNameless: true
IgnoreSymbolicNames: false
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubles
RSpec/VoidExpect:
Description: This cop checks void `expect()`.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VoidExpect
Capybara/CurrentPathExpectation:
Description: Checks that no expectations are set on Capybara's `current_path`.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/CurrentPathExpectation
Capybara/FeatureMethods:
Description: Checks for consistent method usage in feature specs.
Enabled: true
EnabledMethods: []
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods
FactoryBot/AttributeDefinedStatically:
Description: Always declare attribute values as blocks.
Enabled: true
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/AttributeDefinedStatically
FactoryBot/CreateList:
Description: Checks for create_list usage.
Enabled: true
EnforcedStyle: create_list
SupportedStyles:
- create_list
- n_times
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/CreateList
Rails/HttpStatus:
Description: Enforces use of symbolic or numeric value to describe HTTP status.
Enabled: true
EnforcedStyle: symbolic
SupportedStyles:
- numeric
- symbolic
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus
require 'pathname'
require 'yaml'
require 'rubocop'
require_relative 'rubocop/rspec'
require_relative 'rubocop/rspec/version'
require_relative 'rubocop/rspec/inject'
require_relative 'rubocop/rspec/node'
require_relative 'rubocop/rspec/top_level_describe'
require_relative 'rubocop/rspec/wording'
require_relative 'rubocop/rspec/util'
require_relative 'rubocop/rspec/language'
require_relative 'rubocop/rspec/language/node_pattern'
require_relative 'rubocop/rspec/concept'
require_relative 'rubocop/rspec/example_group'
require_relative 'rubocop/rspec/example'
require_relative 'rubocop/rspec/hook'
require_relative 'rubocop/cop/rspec/cop'
require_relative 'rubocop/rspec/align_let_brace'
require_relative 'rubocop/rspec/final_end_location'
require_relative 'rubocop/rspec/blank_line_separation'
RuboCop::RSpec::Inject.defaults!
require_relative 'rubocop/cop/rspec_cops'
# We have to register our autocorrect incompatibilies in RuboCop's cops as well
# so we do not hit infinite loops
module RuboCop
module Cop
module Layout
class ExtraSpacing # rubocop:disable Style/Documentation
def self.autocorrect_incompatible_with
[RSpec::AlignLeftLetBrace, RSpec::AlignRightLetBrace]
end
end
end
end
end
RuboCop::AST::Node.include(RuboCop::RSpec::Node)
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# Checks that left braces for adjacent single line lets are aligned.
#
# @example
#
# # bad
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
# # good
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
class AlignLeftLetBrace < Cop
MSG = 'Align left let brace'.freeze
def self.autocorrect_incompatible_with
[Layout::ExtraSpacing]
end
def investigate(_processed_source)
return if processed_source.blank?
token_aligner.offending_tokens.each do |let|
add_offense(let, location: :begin)
end
end
def autocorrect(let)
lambda do |corrector|
corrector.insert_before(
let.loc.begin,
token_aligner.indent_for(let)
)
end
end
private
def token_aligner
@token_aligner ||=
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :begin)
end
end
end
end
end
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# Checks that right braces for adjacent single line lets are aligned.
#
# @example
#
# # bad
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
# # good
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
class AlignRightLetBrace < Cop
MSG = 'Align right let brace'.freeze
def self.autocorrect_incompatible_with
[Layout::ExtraSpacing]
end
def investigate(_processed_source)
return if processed_source.blank?
token_aligner.offending_tokens.each do |let|
add_offense(let, location: :end)
end
end
def autocorrect(let)
lambda do |corrector|
corrector.insert_before(
let.loc.end,
token_aligner.indent_for(let)
)
end
end
private
def token_aligner
@token_aligner ||=
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :end)
end
end
end
end
end
module RuboCop
module Cop
module RSpec
# Check that instances are not being stubbed globally.
#
# Prefer instance doubles over stubbing any instance of a class
#
# @example
# # bad
# describe MyClass do
# before { allow_any_instance_of(MyClass).to receive(:foo) }
# end
#
# # good
# describe MyClass do
# let(:my_instance) { instance_double(MyClass) }
#
# before do
# allow(MyClass).to receive(:new).and_return(my_instance)
# allow(my_instance).to receive(:foo)
# end
# end
class AnyInstance < Cop
MSG = 'Avoid stubbing using `%<method>s`.'.freeze
def_node_matcher :disallowed_stub, <<-PATTERN
(send _ ${:any_instance :allow_any_instance_of :expect_any_instance_of} ...)
PATTERN
def on_send(node)
disallowed_stub(node) do |method|
add_offense(
node,
location: :expression,
message: format(MSG, method: method)
)
end
end
end
end
end
end
module RuboCop
module Cop
module RSpec
# Checks that around blocks actually run the test.
#
# @example
# # bad
# around do
# some_method
# end
#
# around do |test|
# some_method
# end
#
# # good
# around do |test|
# some_method
# test.call
# end
#
# around do |test|
# some_method
# test.run
# end
class AroundBlock < Cop
MSG_NO_ARG = 'Test object should be passed to around block.'.freeze
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
'or `%<arg>s.run`.'.freeze
def_node_matcher :hook, <<-PATTERN
(block {(send nil? :around) (send nil? :around sym)} (args $...) ...)
PATTERN
def_node_search :find_arg_usage, <<-PATTERN
{(send $... {:call :run}) (send _ _ $...) (yield $...) (block-pass $...)}
PATTERN
def on_block(node)
hook(node) do |(example_proxy)|
if example_proxy.nil?
add_no_arg_offense(node)
else
check_for_unused_proxy(node, example_proxy)
end
end
end
private
def add_no_arg_offense(node)
add_offense(node, location: :expression, message: MSG_NO_ARG)
end
def check_for_unused_proxy(block, proxy)
name, = *proxy
find_arg_usage(block) do |usage|
return if usage.include?(s(:lvar, name))
end
add_offense(
proxy,
location: :expression,
message: format(MSG_UNUSED_ARG, arg: name)
)
end
end
end
end
end
module RuboCop
module Cop
module RSpec
# Check for expectations where `be` is used without argument.
#
# The `be` matcher is too generic, as it pass on everything that is not
# nil or false. If that is the exact intend, use `be_truthy`. In all other
# cases it's better to specify what exactly is the expected value.
#
# @example
#
# # bad
# expect(foo).to be
#
# # good
# expect(foo).to be_truthy
# expect(foo).to be 1.0
# expect(foo).to be(true)
#
class Be < Cop
MSG = 'Don\'t use `be` without an argument.'.freeze
def_node_matcher :be_without_args, <<-PATTERN
(send _ {:to :not_to :to_not} $(send nil? :be))
PATTERN
def on_send(node)
be_without_args(node) do |matcher|
add_offense(matcher, location: :selector)
end
end
end
end
end
end
module RuboCop
module Cop
module RSpec
# Check for expectations where `be(...)` can replace `eql(...)`.
#
# The `be` matcher compares by identity while the `eql` matcher
# compares using `eql?`. Integers, floats, booleans, symbols, and nil
# can be compared by identity and therefore the `be` matcher is
# preferable as it is a more strict test.
#
# @example
#
# # bad
# expect(foo).to eql(1)
# expect(foo).to eql(1.0)
# expect(foo).to eql(true)
# expect(foo).to eql(false)
# expect(foo).to eql(:bar)
# expect(foo).to eql(nil)
#
# # good
# expect(foo).to be(1)
# expect(foo).to be(1.0)
# expect(foo).to be(true)
# expect(foo).to be(false)
# expect(foo).to be(:bar)
# expect(foo).to be(nil)
#
# This cop only looks for instances of `expect(...).to eql(...)`. We
# do not check `to_not` or `not_to` since `!eql?` is more strict
# than `!equal?`. We also do not try to flag `eq` because if
# `a == b`, and `b` is comparable by identity, `a` is still not
# necessarily the same type as `b` since the `#==` operator can
# coerce objects for comparison.
#
class BeEql < Cop
MSG = 'Prefer `be` over `eql`.'.freeze
def_node_matcher :eql_type_with_identity, <<-PATTERN
(send _ :to $(send nil? :eql {true false int float sym nil_type?}))
PATTERN
def on_send(node)
eql_type_with_identity(node) do |eql|
add_offense(eql, location: :selector)
end
end
def autocorrect(node)
->(corrector) { corrector.replace(node.loc.selector, 'be') }
end
end
end
end
end
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# Check that before/after(:all) isn't being used.
#
# @example
# # bad
# #
# # Faster but risk of state leaking between examples
# #
# describe MyClass do
# before(:all) { Widget.create }
# after(:all) { Widget.delete_all }
# end
#
# # good
# #
# # Slower but examples are properly isolated
# #
# describe MyClass do
# before(:each) { Widget.create }
# after(:each) { Widget.delete_all }
# end
class BeforeAfterAll < Cop
MSG = 'Beware of using `%<hook>s` as it may cause state to leak '\
'between tests. If you are using `rspec-rails`, and '\
'`use_transactional_fixtures` is enabled, then records created '\
'in `%<hook>s` are not automatically rolled back.'.freeze
def_node_matcher :before_or_after_all, <<-PATTERN
$(send _ {:before :after} (sym {:all :context}))
PATTERN
def on_send(node)
before_or_after_all(node) do |hook|
add_offense(
node,
location: :expression,
message: format(MSG, hook: hook.source)
)
end
end
end
end
end
end
module RuboCop
module Cop
module RSpec
module Capybara
# Checks that no expectations are set on Capybara's `current_path`.
#
# The `have_current_path` matcher (http://www.rubydoc.info/github/
# teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-
# instance_method) should be used on `page` to set expectations on
# Capybara's current path, since it uses Capybara's waiting
# functionality (https://github.com/teamcapybara/capybara/blob/master/
# README.md#asynchronous-javascript-ajax-and-friends) which ensures that
# preceding actions (like `click_link`) have completed.
#
# @example
# # bad
# expect(current_path).to eq('/callback')
# expect(page.current_path).to match(/widgets/)
#
# # good
# expect(page).to have_current_path("/callback")
# expect(page).to have_current_path(/widgets/)
#
class CurrentPathExpectation < Cop
MSG = 'Do not set an RSpec expectation on `current_path` in ' \
'Capybara feature specs - instead, use the ' \
'`have_current_path` matcher on `page`'.freeze
def_node_matcher :expectation_set_on_current_path, <<-PATTERN
(send nil? :expect (send {(send nil? :page) nil?} :current_path))
PATTERN
def on_send(node)
expectation_set_on_current_path(node) do
add_offense(node, location: :selector)
end
end
end
end
end
end
end
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
module Capybara
# Checks for consistent method usage in feature specs.
#
# By default, the cop disables all Capybara-specific methods that have
# the same native RSpec method (e.g. are just aliases). Some teams
# however may prefer using some of the Capybara methods (like `feature`)
# to make it obvious that the test uses Capybara, while still disable
# the rest of the methods, like `given` (alias for `let`), `background`
# (alias for `before`), etc. You can configure which of the methods to
# be enabled by using the EnabledMethods configuration option.
#
# @example
# # bad
# feature 'User logs in' do
# given(:user) { User.new }
#
# background do
# visit new_session_path
# end
#
# scenario 'with OAuth' do
# # ...
# end
# end
#
# # good
# describe 'User logs in' do
# let(:user) { User.new }
#
# before do
# visit new_session_path
# end
#
# it 'with OAuth' do
# # ...
# end
# end
class FeatureMethods < Cop
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'.freeze
# https://git.io/v7Kwr
MAP = {
background: :before,
scenario: :it,
xscenario: :xit,
given: :let,
given!: :let!,
feature: :describe
}.freeze
def_node_matcher :spec?, <<-PATTERN
(block
(send {(const nil? :RSpec) nil?} {:describe :feature} ...)
...)
PATTERN
def_node_matcher :feature_method, <<-PATTERN
(block
$(send {(const nil? :RSpec) nil?} ${#{MAP.keys.map(&:inspect).join(' ')}} ...)
...)
PATTERN
def on_block(node)
return unless inside_spec?(node)
feature_method(node) do |send_node, match|
next if enabled?(match)
add_offense(
send_node,
location: :selector,
message: format(MSG, method: match, replacement: MAP[match])
)
end
end
def autocorrect(node)
lambda do |corrector|
corrector.replace(node.loc.selector, MAP[node.method_name].to_s)
end
end
private
def inside_spec?(node)
return spec?(node) if root_node?(node)
root = node.ancestors.find { |parent| root_node?(parent) }
spec?(root)
end
def root_node?(node)
node.parent.nil? || root_with_siblings?(node.parent)
end
def root_with_siblings?(node)
node.begin_type? && node.parent.nil?
end
def enabled?(method_name)
enabled_methods.include?(method_name)
end
def enabled_methods
cop_config
.fetch('EnabledMethods', [])
.map(&:to_sym)
end
end
end
end
end
end
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# `context` block descriptions should start with 'when', or 'with'.
#
# @see https://github.com/reachlocal/rspec-style-guide#context-descriptions
# @see http://www.betterspecs.org/#contexts
#
# @example `Prefixes` configuration option, defaults: 'when', 'with', and
# 'without'
# Prefixes:
# - when
# - with
# - without
# - if
#
# @example
# # bad
# context 'the display name not present' do
# # ...
# end
#
# # good
# context 'when the display name is not present' do
# # ...
# end
class ContextWording < Cop
MSG = 'Start context description with %<prefixes>s.'.freeze
def_node_matcher :context_wording, <<-PATTERN
(block (send _ { :context :shared_context } $(str #bad_prefix?)) ...)
PATTERN
def on_block(node)
context_wording(node) do |context|
add_offense(context, message: message)
end
end
private
def bad_prefix?(description)
!prefixes.include?(description.split.first)
end
def prefixes
cop_config['Prefixes'] || []
end
def message
format(MSG, prefixes: joined_prefixes)
end
def joined_prefixes
quoted = prefixes.map { |prefix| "'#{prefix}'" }
return quoted.first if quoted.size == 1
quoted << "or #{quoted.pop}"
quoted.join(', ')
end
end
end
end
end
# frozen_string_literal: true
module RuboCop
module Cop # rubocop:disable Style/Documentation
WorkaroundCop = Cop.dup
# Clone of the the normal RuboCop::Cop::Cop class so we can rewrite
# the inherited method without breaking functionality
class WorkaroundCop
# Remove the Cop.inherited method to be a noop. Our RSpec::Cop
# class will invoke the inherited hook instead
class << self
undef inherited
def inherited(*) end
end
# Special case `Module#<` so that the rspec support rubocop exports
# is compatible with our subclass
def self.<(other)
other.equal?(RuboCop::Cop::Cop) || super
end
end
private_constant(:WorkaroundCop)
module RSpec
# @abstract parent class to rspec cops
#
# 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:
#
# @example configuring analyzed paths
#
# AllCops:
# RSpec:
# Patterns:
# - '_test.rb$'
# - '(?:^|/)test/'
class Cop < WorkaroundCop
include RuboCop::RSpec::Language
include RuboCop::RSpec::Language::NodePattern
DEFAULT_CONFIGURATION =
RuboCop::RSpec::CONFIG.fetch('AllCops').fetch('RSpec')
DEFAULT_PATTERN_RE = Regexp.union(
DEFAULT_CONFIGURATION.fetch('Patterns')
.map(&Regexp.public_method(:new))
)
# Invoke the original inherited hook so our cops are recognized
def self.inherited(subclass)
RuboCop::Cop::Cop.inherited(subclass)
end
def relevant_file?(file)
relevant_rubocop_rspec_file?(file) && super
end
private
def relevant_rubocop_rspec_file?(file)
rspec_pattern =~ file
end
def rspec_pattern
if rspec_pattern_config?
Regexp.union(rspec_pattern_config.map(&Regexp.public_method(:new)))
else
DEFAULT_PATTERN_RE
end
end
def all_cops_config
config
.for_all_cops
end
def rspec_pattern_config?
return unless all_cops_config.key?('RSpec')
all_cops_config.fetch('RSpec').key?('Patterns')
end
def rspec_pattern_config
all_cops_config
.fetch('RSpec', DEFAULT_CONFIGURATION)
.fetch('Patterns')
end
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment