brew vendor-gems: commit updates.
This commit is contained in:
parent
73e353a00e
commit
c596b3fcdf
@ -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"
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
Loading…
x
Reference in New Issue
Block a user