mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #7475 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-rspec-1.39.0
build(deps): bump rubocop-rspec from 1.38.1 to 1.39.0 in /Library/Homebrew
This commit is contained in:
commit
7f69550e00
@ -91,7 +91,7 @@ GEM
|
||||
unicode-display_width (>= 1.4.0, < 2.0)
|
||||
rubocop-performance (1.5.2)
|
||||
rubocop (>= 0.71.0)
|
||||
rubocop-rspec (1.38.1)
|
||||
rubocop-rspec (1.39.0)
|
||||
rubocop (>= 0.68.1)
|
||||
ruby-macho (2.2.0)
|
||||
ruby-progressbar (1.10.1)
|
||||
|
24
Library/Homebrew/vendor/bundle/bundler/setup.rb
vendored
24
Library/Homebrew/vendor/bundle/bundler/setup.rb
vendored
@ -13,32 +13,32 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/activesupport-6.0.2.2
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ast-2.4.0/lib"
|
||||
$:.unshift "#{path}/"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/connection_pool-2.2.2/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/json-2.3.0"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-13/2.6.0-static/json-2.3.0"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/json-2.3.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/docile-1.3.2/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-html-0.10.2/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-0.16.1/lib"
|
||||
$:.unshift "#{path}/../../../../../../../../Library/Ruby/Gems/2.6.0/gems/sync-0.5.0/lib"
|
||||
$:.unshift "#{path}/../../portable-ruby/2.6.3/lib/ruby/gems/2.6.0/gems/sync-0.5.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tins-1.24.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/term-ansicolor-1.7.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/thor-1.0.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/coveralls-0.8.23/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/diff-lcs-1.3/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/unf_ext-0.0.7.7"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-13/2.6.0-static/unf_ext-0.0.7.7"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unf_ext-0.0.7.7/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unf-0.1.4/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/domain_name-0.5.20190701/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/hpricot-0.8.6"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-13/2.6.0-static/hpricot-0.8.6"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/hpricot-0.8.6/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/http-cookie-1.0.3/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/jaro_winkler-1.5.4"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-13/2.6.0-static/jaro_winkler-1.5.4"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/jaro_winkler-1.5.4/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/mime-types-data-3.2019.1009/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/mime-types-data-3.2020.0425/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/mime-types-3.3.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/net-http-digest_auth-1.4.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/net-http-persistent-3.1.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/net-http-persistent-4.0.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/mini_portile2-2.4.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/nokogiri-1.10.9"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-13/2.6.0-static/nokogiri-1.10.9"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/nokogiri-1.10.9/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ntlm-http-0.1.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/webrobots-0.1.2/lib"
|
||||
@ -46,10 +46,10 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/mechanize-2.7.6/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/mustache-1.1.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parallel-1.19.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parallel_tests-2.32.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parser-2.7.1.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parser-2.7.1.2/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/plist-3.5.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rainbow-3.0.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/rdiscount-2.2.0.1"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-13/2.6.0-static/rdiscount-2.2.0.1"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rdiscount-2.2.0.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rexml-3.2.4/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ronn-0.7.3/lib"
|
||||
@ -63,7 +63,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-retry-0.6.2/lib
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-wait-0.0.9/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.10.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.7.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.81.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.82.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.5.2/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.38.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.39.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.2.0/lib"
|
||||
|
@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module RSpec
|
||||
# Utility methods
|
||||
module Util
|
||||
# Error raised by `Util.one` if size is less than zero or greater than one
|
||||
SizeError = Class.new(IndexError)
|
||||
|
||||
# Return only element in array if it contains exactly one member
|
||||
def one(array)
|
||||
return array.first if array.one?
|
||||
|
||||
raise SizeError,
|
||||
"expected size to be exactly 1 but size was #{array.size}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -105,6 +105,12 @@ RSpec/EmptyExampleGroup:
|
||||
CustomIncludeMethods: []
|
||||
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup
|
||||
|
||||
RSpec/EmptyHook:
|
||||
Description: Checks for empty before and after hooks.
|
||||
Enabled: true
|
||||
VersionAdded: 1.39.0
|
||||
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyHook
|
||||
|
||||
RSpec/EmptyLineAfterExample:
|
||||
Description: Checks if there is an empty line after example blocks.
|
||||
Enabled: true
|
||||
@ -324,7 +330,6 @@ RSpec/MultipleExpectations:
|
||||
Description: Checks if examples contain too many `expect` calls.
|
||||
Enabled: true
|
||||
Max: 1
|
||||
AggregateFailuresByDefault: false
|
||||
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleExpectations
|
||||
|
||||
RSpec/MultipleSubjects:
|
||||
@ -417,6 +422,7 @@ RSpec/ScatteredLet:
|
||||
Description: Checks for let scattered across the example group.
|
||||
Enabled: true
|
||||
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredLet
|
||||
VersionChanged: '1.39'
|
||||
|
||||
RSpec/ScatteredSetup:
|
||||
Description: Checks for setup scattered across multiple hooks in an example group.
|
||||
@ -476,6 +482,12 @@ Capybara/FeatureMethods:
|
||||
EnabledMethods: []
|
||||
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods
|
||||
|
||||
Capybara/VisibilityMatcher:
|
||||
Description: Checks for boolean visibility in capybara finders.
|
||||
Enabled: true
|
||||
VersionAdded: '1.39'
|
||||
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/VisibilityMatcher
|
||||
|
||||
FactoryBot/AttributeDefinedStatically:
|
||||
Description: Always declare attribute values as blocks.
|
||||
Enabled: true
|
@ -11,7 +11,6 @@ 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'
|
||||
@ -23,6 +22,7 @@ require_relative 'rubocop/rspec/align_let_brace'
|
||||
require_relative 'rubocop/rspec/factory_bot'
|
||||
require_relative 'rubocop/rspec/final_end_location'
|
||||
require_relative 'rubocop/rspec/blank_line_separation'
|
||||
require_relative 'rubocop/rspec/corrector/move_node'
|
||||
|
||||
RuboCop::RSpec::Inject.defaults!
|
||||
|
@ -0,0 +1,54 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module RSpec
|
||||
module Capybara
|
||||
# Checks for boolean visibility in capybara finders.
|
||||
#
|
||||
# Capybara lets you find elements that match a certain visibility using
|
||||
# the `:visible` option. `:visible` accepts both boolean and symbols as
|
||||
# values, however using booleans can have unwanted effects. `visible:
|
||||
# false` does not find just invisible elements, but both visible and
|
||||
# invisible elements. For expressiveness and clarity, use one of the
|
||||
# symbol values, `:all`, `:hidden` or `:visible`.
|
||||
# (https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all)
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# # bad
|
||||
# expect(page).to have_selector('.foo', visible: false)
|
||||
#
|
||||
# # bad
|
||||
# expect(page).to have_selector('.foo', visible: true)
|
||||
#
|
||||
# # good
|
||||
# expect(page).to have_selector('.foo', visible: :all)
|
||||
#
|
||||
# # good
|
||||
# expect(page).to have_selector('.foo', visible: :hidden)
|
||||
#
|
||||
# # good
|
||||
# expect(page).to have_selector('.foo', visible: :visible)
|
||||
#
|
||||
class VisibilityMatcher < Cop
|
||||
MSG_FALSE = 'Use `:all` or `:hidden` instead of `false`.'
|
||||
MSG_TRUE = 'Use `:visible` instead of `true`.'
|
||||
|
||||
def_node_matcher :visible_true?, <<~PATTERN
|
||||
(send nil? :have_selector ... (hash <$(pair (sym :visible) true) ...>))
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :visible_false?, <<~PATTERN
|
||||
(send nil? :have_selector ... (hash <$(pair (sym :visible) false) ...>))
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
visible_false?(node) { |arg| add_offense(arg, message: MSG_FALSE) }
|
||||
visible_true?(node) { |arg| add_offense(arg, message: MSG_TRUE) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop # rubocop:disable Style/Documentation
|
||||
module Cop
|
||||
WorkaroundCop = Cop.dup
|
||||
|
||||
# Clone of the the normal RuboCop::Cop::Cop class so we can rewrite
|
@ -12,6 +12,11 @@ module RuboCop
|
||||
#
|
||||
# # good
|
||||
# describe TestedClass do
|
||||
# subject { described_class }
|
||||
# end
|
||||
#
|
||||
# describe 'TestedClass::VERSION' do
|
||||
# subject { Object.const_get(self.class.description) }
|
||||
# end
|
||||
#
|
||||
# describe "A feature example", type: :feature do
|
||||
@ -44,12 +49,20 @@ module RuboCop
|
||||
|
||||
def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern
|
||||
|
||||
def on_top_level_describe(node, args)
|
||||
def on_top_level_describe(node, (described_value, _))
|
||||
return if shared_group?(root_node)
|
||||
return if valid_describe?(node)
|
||||
return if describe_with_rails_metadata?(node)
|
||||
return if string_constant_describe?(described_value)
|
||||
|
||||
add_offense(args.first)
|
||||
add_offense(described_value)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def string_constant_describe?(described_value)
|
||||
described_value.str_type? &&
|
||||
described_value.value =~ /^((::)?[A-Z]\w*)+$/
|
||||
end
|
||||
end
|
||||
end
|
@ -18,7 +18,6 @@ module RuboCop
|
||||
# end
|
||||
class DescribeMethod < Cop
|
||||
include RuboCop::RSpec::TopLevelDescribe
|
||||
include RuboCop::RSpec::Util
|
||||
|
||||
MSG = 'The second argument to describe should be the method '\
|
||||
"being tested. '#instance' or '.class'."
|
@ -0,0 +1,50 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module RSpec
|
||||
# Checks for empty before and after hooks.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# before {}
|
||||
# after do; end
|
||||
# before(:all) do
|
||||
# end
|
||||
# after(:all) { }
|
||||
#
|
||||
# # good
|
||||
# before { create_users }
|
||||
# after do
|
||||
# cleanup_users
|
||||
# end
|
||||
# before(:all) do
|
||||
# create_feed
|
||||
# end
|
||||
# after(:all) { cleanup_feed }
|
||||
class EmptyHook < Cop
|
||||
include RuboCop::Cop::RangeHelp
|
||||
|
||||
MSG = 'Empty hook detected.'
|
||||
|
||||
def_node_matcher :empty_hook?, <<~PATTERN
|
||||
(block $#{Hooks::ALL.send_pattern} _ nil?)
|
||||
PATTERN
|
||||
|
||||
def on_block(node)
|
||||
empty_hook?(node) do |hook|
|
||||
add_offense(hook)
|
||||
end
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
block = node.parent
|
||||
range = range_with_surrounding_space(range: block.loc.expression)
|
||||
corrector.remove(range)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -103,7 +103,9 @@ module RuboCop
|
||||
end
|
||||
|
||||
def filename_ends_with?(glob)
|
||||
File.fnmatch?("*#{glob}", processed_source.buffer.name)
|
||||
filename =
|
||||
RuboCop::PathUtil.relative_path(processed_source.buffer.name)
|
||||
File.fnmatch?("*#{glob}", filename)
|
||||
end
|
||||
|
||||
def relevant_rubocop_rspec_file?(_file)
|
@ -24,9 +24,6 @@ module RuboCop
|
||||
# end
|
||||
#
|
||||
class HooksBeforeExamples < Cop
|
||||
include RangeHelp
|
||||
include RuboCop::RSpec::FinalEndLocation
|
||||
|
||||
MSG = 'Move `%<hook>s` above the examples in the group.'
|
||||
|
||||
def_node_matcher :example_or_group?, <<-PATTERN
|
||||
@ -45,11 +42,9 @@ module RuboCop
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
first_example = find_first_example(node.parent)
|
||||
first_example_pos = first_example.loc.expression
|
||||
indent = "\n" + ' ' * first_example.loc.column
|
||||
|
||||
corrector.insert_before(first_example_pos, source(node) + indent)
|
||||
corrector.remove(node_range_with_surrounding_space(node))
|
||||
RuboCop::RSpec::Corrector::MoveNode.new(
|
||||
node, corrector, processed_source
|
||||
).move_before(first_example)
|
||||
end
|
||||
end
|
||||
|
||||
@ -77,19 +72,6 @@ module RuboCop
|
||||
def find_first_example(node)
|
||||
node.children.find { |sibling| example_or_group?(sibling) }
|
||||
end
|
||||
|
||||
def node_range_with_surrounding_space(node)
|
||||
range = node_range(node)
|
||||
range_by_whole_lines(range, include_final_newline: true)
|
||||
end
|
||||
|
||||
def source(node)
|
||||
node_range(node).source
|
||||
end
|
||||
|
||||
def node_range(node)
|
||||
node.loc.expression.with(end_pos: final_end_location(node).end_pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -32,8 +32,6 @@ module RuboCop
|
||||
# it { expect_something_else }
|
||||
#
|
||||
class LeadingSubject < Cop
|
||||
include RangeHelp
|
||||
|
||||
MSG = 'Declare `subject` above any other `%<offending>s` declarations.'
|
||||
|
||||
def on_block(node)
|
||||
@ -58,10 +56,9 @@ module RuboCop
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
first_node = find_first_offending_node(node)
|
||||
first_node_position = first_node.loc.expression
|
||||
indent = "\n" + ' ' * first_node.loc.column
|
||||
corrector.insert_before(first_node_position, node.source + indent)
|
||||
corrector.remove(node_range(node))
|
||||
RuboCop::RSpec::Corrector::MoveNode.new(
|
||||
node, corrector, processed_source
|
||||
).move_before(first_node)
|
||||
end
|
||||
end
|
||||
|
||||
@ -75,10 +72,6 @@ module RuboCop
|
||||
node.parent.children.find { |sibling| offending?(sibling) }
|
||||
end
|
||||
|
||||
def node_range(node)
|
||||
range_by_whole_lines(node.source_range, include_final_newline: true)
|
||||
end
|
||||
|
||||
def in_spec_block?(node)
|
||||
node.each_ancestor(:block).any? do |ancestor|
|
||||
example?(ancestor)
|
@ -31,9 +31,6 @@ module RuboCop
|
||||
# expect(some).to be
|
||||
# end
|
||||
class LetBeforeExamples < Cop
|
||||
include RangeHelp
|
||||
include RuboCop::RSpec::FinalEndLocation
|
||||
|
||||
MSG = 'Move `let` before the examples in the group.'
|
||||
|
||||
def_node_matcher :example_or_group?, <<-PATTERN
|
||||
@ -52,11 +49,9 @@ module RuboCop
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
first_example = find_first_example(node.parent)
|
||||
first_example_pos = first_example.loc.expression
|
||||
indent = "\n" + ' ' * first_example.loc.column
|
||||
|
||||
corrector.insert_before(first_example_pos, source(node) + indent)
|
||||
corrector.remove(node_range_with_surrounding_space(node))
|
||||
RuboCop::RSpec::Corrector::MoveNode.new(
|
||||
node, corrector, processed_source
|
||||
).move_before(first_example)
|
||||
end
|
||||
end
|
||||
|
||||
@ -80,19 +75,6 @@ module RuboCop
|
||||
def find_first_example(node)
|
||||
node.children.find { |sibling| example_or_group?(sibling) }
|
||||
end
|
||||
|
||||
def node_range_with_surrounding_space(node)
|
||||
range = node_range(node)
|
||||
range_by_whole_lines(range, include_final_newline: true)
|
||||
end
|
||||
|
||||
def source(node)
|
||||
node_range(node).source
|
||||
end
|
||||
|
||||
def node_range(node)
|
||||
node.loc.expression.with(end_pos: final_end_location(node).end_pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -6,11 +6,11 @@ module RuboCop
|
||||
# Checks for explicitly referenced test subjects.
|
||||
#
|
||||
# RSpec lets you declare an "implicit subject" using `subject { ... }`
|
||||
# which allows for tests like `it { should be_valid }`. If you need to
|
||||
# reference your test subject you should explicitly name it using
|
||||
# `subject(:your_subject_name) { ... }`. Your test subjects should be
|
||||
# the most important object in your tests so they deserve a descriptive
|
||||
# name.
|
||||
# which allows for tests like `it { is_expected.to be_valid }`.
|
||||
# If you need to reference your test subject you should explicitly
|
||||
# name it using `subject(:your_subject_name) { ... }`. Your test subjects
|
||||
# should be the most important object in your tests so they deserve
|
||||
# a descriptive name.
|
||||
#
|
||||
# This cop can be configured in your configuration using the
|
||||
# `IgnoreSharedExamples` which will not report offenses for implicit
|
||||
@ -39,7 +39,7 @@ module RuboCop
|
||||
# RSpec.describe Foo do
|
||||
# subject(:user) { described_class.new }
|
||||
#
|
||||
# it { should be_valid }
|
||||
# it { is_expected.to be_valid }
|
||||
# end
|
||||
class NamedSubject < Cop
|
||||
MSG = 'Name your test subject if you need '\
|
@ -35,6 +35,15 @@ module RuboCop
|
||||
check_let_declarations(node.body)
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
first_let = find_first_let(node.parent)
|
||||
RuboCop::RSpec::Corrector::MoveNode.new(
|
||||
node, corrector, processed_source
|
||||
).move_after(first_let)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_let_declarations(body)
|
||||
@ -47,6 +56,10 @@ module RuboCop
|
||||
add_offense(node)
|
||||
end
|
||||
end
|
||||
|
||||
def find_first_let(node)
|
||||
node.children.find { |child| let?(child) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -2,6 +2,7 @@
|
||||
|
||||
require_relative 'rspec/capybara/current_path_expectation'
|
||||
require_relative 'rspec/capybara/feature_methods'
|
||||
require_relative 'rspec/capybara/visibility_matcher'
|
||||
|
||||
require_relative 'rspec/factory_bot/attribute_defined_statically'
|
||||
require_relative 'rspec/factory_bot/create_list'
|
||||
@ -9,7 +10,7 @@ require_relative 'rspec/factory_bot/factory_class_name'
|
||||
|
||||
begin
|
||||
require_relative 'rspec/rails/http_status'
|
||||
rescue LoadError # rubocop:disable Lint/SuppressedException
|
||||
rescue LoadError
|
||||
# Rails/HttpStatus cannot be loaded if rack/utils is unavailable.
|
||||
end
|
||||
|
||||
@ -29,6 +30,7 @@ require_relative 'rspec/described_class'
|
||||
require_relative 'rspec/described_class_module_wrapping'
|
||||
require_relative 'rspec/dialect'
|
||||
require_relative 'rspec/empty_example_group'
|
||||
require_relative 'rspec/empty_hook'
|
||||
require_relative 'rspec/empty_line_after_example'
|
||||
require_relative 'rspec/empty_line_after_example_group'
|
||||
require_relative 'rspec/empty_line_after_final_let'
|
@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module RSpec
|
||||
module Corrector
|
||||
# Helper methods to move a node
|
||||
class MoveNode
|
||||
include RuboCop::Cop::RangeHelp
|
||||
include RuboCop::RSpec::FinalEndLocation
|
||||
|
||||
attr_reader :original, :corrector, :processed_source
|
||||
|
||||
def initialize(node, corrector, processed_source)
|
||||
@original = node
|
||||
@corrector = corrector
|
||||
@processed_source = processed_source # used by RangeHelp
|
||||
end
|
||||
|
||||
def move_before(other) # rubocop:disable Metrics/AbcSize
|
||||
position = other.loc.expression
|
||||
indent = "\n" + ' ' * other.loc.column
|
||||
|
||||
corrector.insert_before(position, source(original) + indent)
|
||||
corrector.remove(node_range_with_surrounding_space(original))
|
||||
end
|
||||
|
||||
def move_after(other)
|
||||
position = final_end_location(other)
|
||||
indent = "\n" + ' ' * other.loc.column
|
||||
|
||||
corrector.insert_after(position, indent + source(original))
|
||||
corrector.remove(node_range_with_surrounding_space(original))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def source(node)
|
||||
node_range(node).source
|
||||
end
|
||||
|
||||
def node_range(node)
|
||||
node.loc.expression.with(end_pos: final_end_location(node).end_pos)
|
||||
end
|
||||
|
||||
def node_range_with_surrounding_space(node)
|
||||
range = node_range(node)
|
||||
range_by_whole_lines(range, include_final_newline: true)
|
||||
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