Merge pull request #12635 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-rspec-2.7.0

build(deps): bump rubocop-rspec from 2.6.0 to 2.7.0 in /Library/Homebrew
This commit is contained in:
Bo Anderson 2021-12-27 19:52:57 +00:00 committed by GitHub
commit d3e5a157bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
120 changed files with 211 additions and 36 deletions

View File

@ -142,7 +142,7 @@ GEM
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-rspec (2.6.0)
rubocop-rspec (2.7.0)
rubocop (~> 1.19)
rubocop-sorbet (0.6.5)
rubocop (>= 0.90.0)

View File

@ -151,21 +151,18 @@ RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation::MSG = T.let(T.unsafe(nil)
RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
class RuboCop::Cop::RSpec::Capybara::FeatureMethods < ::RuboCop::Cop::RSpec::Base
include ::RuboCop::Cop::RSpec::InsideExampleGroup
extend ::RuboCop::Cop::AutoCorrector
def capybara_speak(param0 = T.unsafe(nil)); end
def feature_method(param0 = T.unsafe(nil)); end
def message(range); end
def on_block(node); end
def spec?(param0 = T.unsafe(nil)); end
private
def enabled?(method_name); end
def enabled_methods; end
def inside_spec?(node); end
def root_node?(node); end
def root_with_siblings?(node); end
end
RuboCop::Cop::RSpec::Capybara::FeatureMethods::MAP = T.let(T.unsafe(nil), Hash)
@ -573,6 +570,7 @@ RuboCop::Cop::RSpec::FactoryBot::AttributeDefinedStatically::MSG = T.let(T.unsaf
class RuboCop::Cop::RSpec::FactoryBot::CreateList < ::RuboCop::Cop::RSpec::Base
include ::RuboCop::Cop::ConfigurableEnforcedStyle
include ::RuboCop::RSpec::FactoryBot::Language
extend ::RuboCop::Cop::AutoCorrector
def factory_call(param0 = T.unsafe(nil)); end
@ -644,6 +642,23 @@ RuboCop::Cop::RSpec::FactoryBot::FactoryClassName::ALLOWED_CONSTANTS = T.let(T.u
RuboCop::Cop::RSpec::FactoryBot::FactoryClassName::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::RSpec::FactoryBot::FactoryClassName::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
class RuboCop::Cop::RSpec::FactoryBot::SyntaxMethods < ::RuboCop::Cop::RSpec::Base
include ::RuboCop::Cop::RSpec::InsideExampleGroup
include ::RuboCop::Cop::RangeHelp
include ::RuboCop::RSpec::FactoryBot::Language
extend ::RuboCop::Cop::AutoCorrector
def on_send(node); end
private
def crime_scene(node); end
def offense(node); end
end
RuboCop::Cop::RSpec::FactoryBot::SyntaxMethods::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::RSpec::FactoryBot::SyntaxMethods::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Set)
class RuboCop::Cop::RSpec::FilePath < ::RuboCop::Cop::RSpec::Base
include ::RuboCop::Cop::RSpec::TopLevelGroup
@ -808,6 +823,14 @@ end
RuboCop::Cop::RSpec::InflectedHelper::MSG_INFLECTED = T.let(T.unsafe(nil), String)
module RuboCop::Cop::RSpec::InsideExampleGroup
private
def example_group_root?(node); end
def example_group_root_with_siblings?(node); end
def inside_example_group?(node); end
end
class RuboCop::Cop::RSpec::InstanceSpy < ::RuboCop::Cop::RSpec::Base
extend ::RuboCop::Cop::AutoCorrector
@ -1677,6 +1700,13 @@ end
RuboCop::RSpec::FactoryBot::ATTRIBUTE_DEFINING_METHODS = T.let(T.unsafe(nil), Array)
RuboCop::RSpec::FactoryBot::DEFINITION_PROXY_METHODS = T.let(T.unsafe(nil), Array)
module RuboCop::RSpec::FactoryBot::Language
extend ::RuboCop::AST::NodePattern::Macros
def factory_bot?(param0 = T.unsafe(nil)); end
end
RuboCop::RSpec::FactoryBot::RESERVED_METHODS = T.let(T.unsafe(nil), Array)
RuboCop::RSpec::FactoryBot::UNPROXIED_METHODS = T.let(T.unsafe(nil), Array)

View File

@ -89,7 +89,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.24.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.12.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.12.4/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.6.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.7.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.5/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.5.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-html-0.12.3/lib"

View File

@ -196,8 +196,9 @@ RSpec/DescribeClass:
- system
- mailbox
- aruba
- task
VersionAdded: '1.0'
VersionChanged: '2.5'
VersionChanged: '2.7'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass
RSpec/DescribeMethod:
@ -816,6 +817,13 @@ RSpec/FactoryBot/FactoryClassName:
VersionChanged: '2.0'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryClassName
RSpec/FactoryBot/SyntaxMethods:
Description: Use shorthands from `FactoryBot::Syntax::Methods` in your specs.
Enabled: pending
SafeAutoCorrect: false
VersionAdded: '2.7'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/SyntaxMethods
RSpec/Rails:
Enabled: true
Include: *1

View File

@ -12,11 +12,14 @@ require_relative 'rubocop/rspec/wording'
require_relative 'rubocop/rspec/language/node_pattern'
require_relative 'rubocop/rspec/language'
require_relative 'rubocop/rspec/factory_bot/language'
require_relative 'rubocop/cop/rspec/mixin/top_level_group'
require_relative 'rubocop/cop/rspec/mixin/variable'
require_relative 'rubocop/cop/rspec/mixin/final_end_location'
require_relative 'rubocop/cop/rspec/mixin/comments_help'
require_relative 'rubocop/cop/rspec/mixin/empty_line_separation'
require_relative 'rubocop/cop/rspec/mixin/inside_example_group'
require_relative 'rubocop/rspec/concept'
require_relative 'rubocop/rspec/example_group'
@ -31,8 +34,8 @@ 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
# We have to register our autocorrect incompatibilities in RuboCop's cops
# as well so we do not hit infinite loops
module RuboCop
module Cop

View File

@ -42,6 +42,7 @@ module RuboCop
# end
class FeatureMethods < Base
extend AutoCorrector
include InsideExampleGroup
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'
@ -60,13 +61,6 @@ module RuboCop
{#{MAP.keys.map(&:inspect).join(' ')}}
PATTERN
# @!method spec?(node)
def_node_matcher :spec?, <<-PATTERN
(block
(send #rspec? {:describe :feature} ...)
...)
PATTERN
# @!method feature_method(node)
def_node_matcher :feature_method, <<-PATTERN
(block
@ -75,7 +69,7 @@ module RuboCop
PATTERN
def on_block(node)
return unless inside_spec?(node)
return unless inside_example_group?(node)
feature_method(node) do |send_node, match|
next if enabled?(match)
@ -93,21 +87,6 @@ module RuboCop
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

View File

@ -27,6 +27,7 @@ module RuboCop
class CreateList < Base
extend AutoCorrector
include ConfigurableEnforcedStyle
include RuboCop::RSpec::FactoryBot::Language
MSG_CREATE_LIST = 'Prefer create_list.'
MSG_N_TIMES = 'Prefer %<number>s.times.'
@ -43,12 +44,12 @@ module RuboCop
# @!method factory_call(node)
def_node_matcher :factory_call, <<-PATTERN
(send ${(const nil? {:FactoryGirl :FactoryBot}) nil?} :create (sym $_) $...)
(send ${nil? #factory_bot?} :create (sym $_) $...)
PATTERN
# @!method factory_list_call(node)
def_node_matcher :factory_list_call, <<-PATTERN
(send {(const nil? {:FactoryGirl :FactoryBot}) nil?} :create_list (sym _) (int $_) ...)
(send {nil? #factory_bot?} :create_list (sym _) (int $_) ...)
PATTERN
def on_block(node)
@ -160,7 +161,7 @@ module RuboCop
def call_with_block_replacement(node)
block = node.body
arguments = build_arguments(block, node.receiver.source)
replacement = format_receiver(block.send_node.receiver)
replacement = format_receiver(block.receiver)
replacement += format_method_call(block, 'create_list', arguments)
replacement += format_block(block)
replacement

View File

@ -0,0 +1,107 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
module FactoryBot
# Use shorthands from `FactoryBot::Syntax::Methods` in your specs.
#
# @safety
# The auto-correction is marked as unsafe because the cop
# cannot verify whether you already include
# `FactoryBot::Syntax::Methods` in your test suite.
#
# If you're using Rails, add the following configuration to
# `spec/support/factory_bot.rb` and be sure to require that file in
# `rails_helper.rb`:
#
# [source,ruby]
# ----
# RSpec.configure do |config|
# config.include FactoryBot::Syntax::Methods
# end
# ----
#
# If you're not using Rails:
#
# [source,ruby]
# ----
# RSpec.configure do |config|
# config.include FactoryBot::Syntax::Methods
#
# config.before(:suite) do
# FactoryBot.find_definitions
# end
# end
# ----
#
# @example
# # bad
# FactoryBot.create(:bar)
# FactoryBot.build(:bar)
# FactoryBot.attributes_for(:bar)
#
# # good
# create(:bar)
# build(:bar)
# attributes_for(:bar)
#
class SyntaxMethods < Base
extend AutoCorrector
include InsideExampleGroup
include RangeHelp
include RuboCop::RSpec::FactoryBot::Language
MSG = 'Use `%<method>s` from `FactoryBot::Syntax::Methods`.'
RESTRICT_ON_SEND = %i[
attributes_for
attributes_for_list
attributes_for_pair
build
build_list
build_pair
build_stubbed
build_stubbed_list
build_stubbed_pair
create
create_list
create_pair
generate
generate_list
null
null_list
null_pair
].to_set.freeze
def on_send(node)
return unless factory_bot?(node.receiver)
return unless inside_example_group?(node)
message = format(MSG, method: node.method_name)
add_offense(crime_scene(node), message: message) do |corrector|
corrector.remove(offense(node))
end
end
private
def crime_scene(node)
range_between(
node.loc.expression.begin_pos,
node.loc.selector.end_pos
)
end
def offense(node)
range_between(
node.loc.expression.begin_pos,
node.loc.selector.begin_pos
)
end
end
end
end
end
end

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# Helps you identify whether a given node
# is within an example group or not.
module InsideExampleGroup
private
def inside_example_group?(node)
return example_group?(node) if example_group_root?(node)
root = node.ancestors.find { |parent| example_group_root?(parent) }
example_group?(root)
end
def example_group_root?(node)
node.parent.nil? || example_group_root_with_siblings?(node.parent)
end
def example_group_root_with_siblings?(node)
node.begin_type? && node.parent.nil?
end
end
end
end
end

Some files were not shown because too many files have changed in this diff Show More