brew vendor-gems: commit updates.
This commit is contained in:
parent
1dae1c4875
commit
0e0f00f44c
@ -89,7 +89,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.31.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.31.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.14.2/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.14.2/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.15.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.15.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.11.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.12.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.11/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.11/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-3.0.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-3.0.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-html-0.12.3/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-html-0.12.3/lib"
|
||||||
|
|||||||
@ -783,11 +783,13 @@ RSpec/VariableName:
|
|||||||
RSpec/VerifiedDoubleReference:
|
RSpec/VerifiedDoubleReference:
|
||||||
Description: Checks for consistent verified double reference style.
|
Description: Checks for consistent verified double reference style.
|
||||||
Enabled: pending
|
Enabled: pending
|
||||||
|
SafeAutoCorrect: false
|
||||||
EnforcedStyle: constant
|
EnforcedStyle: constant
|
||||||
SupportedStyles:
|
SupportedStyles:
|
||||||
- constant
|
- constant
|
||||||
- string
|
- string
|
||||||
VersionAdded: 2.10.0
|
VersionAdded: 2.10.0
|
||||||
|
VersionChanged: '2.12'
|
||||||
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubleReference
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubleReference
|
||||||
|
|
||||||
RSpec/VerifiedDoubles:
|
RSpec/VerifiedDoubles:
|
||||||
@ -832,6 +834,12 @@ RSpec/Capybara/FeatureMethods:
|
|||||||
VersionChanged: '2.0'
|
VersionChanged: '2.0'
|
||||||
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods
|
||||||
|
|
||||||
|
RSpec/Capybara/SpecificMatcher:
|
||||||
|
Description: Checks for there is a more specific matcher offered by Capybara.
|
||||||
|
Enabled: pending
|
||||||
|
VersionAdded: '2.12'
|
||||||
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/SpecificMatcher
|
||||||
|
|
||||||
RSpec/Capybara/VisibilityMatcher:
|
RSpec/Capybara/VisibilityMatcher:
|
||||||
Description: Checks for boolean visibility in Capybara finders.
|
Description: Checks for boolean visibility in Capybara finders.
|
||||||
Enabled: true
|
Enabled: true
|
||||||
@ -901,6 +909,13 @@ RSpec/Rails/AvoidSetupHook:
|
|||||||
VersionAdded: '2.4'
|
VersionAdded: '2.4'
|
||||||
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/AvoidSetupHook
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/AvoidSetupHook
|
||||||
|
|
||||||
|
RSpec/Rails/HaveHttpStatus:
|
||||||
|
Description: Checks that tests use `have_http_status` instead of equality matchers.
|
||||||
|
Enabled: pending
|
||||||
|
SafeAutoCorrect: false
|
||||||
|
VersionAdded: '2.12'
|
||||||
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HaveHttpStatus
|
||||||
|
|
||||||
RSpec/Rails/HttpStatus:
|
RSpec/Rails/HttpStatus:
|
||||||
Description: Enforces use of symbolic or numeric value to describe HTTP status.
|
Description: Enforces use of symbolic or numeric value to describe HTTP status.
|
||||||
Enabled: true
|
Enabled: true
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module RSpec
|
||||||
|
module Capybara
|
||||||
|
# Checks for there is a more specific matcher offered by Capybara.
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
#
|
||||||
|
# # bad
|
||||||
|
# expect(page).to have_selector('button')
|
||||||
|
# expect(page).to have_no_selector('button.cls')
|
||||||
|
# expect(page).to have_css('button')
|
||||||
|
# expect(page).to have_no_css('a.cls', exact_text: 'foo')
|
||||||
|
# expect(page).to have_css('table.cls')
|
||||||
|
# expect(page).to have_css('select')
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# expect(page).to have_button
|
||||||
|
# expect(page).to have_no_button(class: 'cls')
|
||||||
|
# expect(page).to have_button
|
||||||
|
# expect(page).to have_no_link('foo', class: 'cls')
|
||||||
|
# expect(page).to have_table(class: 'cls')
|
||||||
|
# expect(page).to have_select
|
||||||
|
#
|
||||||
|
class SpecificMatcher < Base
|
||||||
|
MSG = 'Prefer `%<good_matcher>s` over `%<bad_matcher>s`.'
|
||||||
|
RESTRICT_ON_SEND = %i[have_selector have_no_selector have_css
|
||||||
|
have_no_css].freeze
|
||||||
|
SPECIFIC_MATCHER = {
|
||||||
|
'button' => 'button',
|
||||||
|
'a' => 'link',
|
||||||
|
'table' => 'table',
|
||||||
|
'select' => 'select'
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
# @!method first_argument(node)
|
||||||
|
def_node_matcher :first_argument, <<-PATTERN
|
||||||
|
(send nil? _ (str $_) ... )
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def on_send(node)
|
||||||
|
return unless (arg = first_argument(node))
|
||||||
|
return unless (matcher = specific_matcher(arg))
|
||||||
|
return if acceptable_pattern?(arg)
|
||||||
|
|
||||||
|
add_offense(node, message: message(node, matcher))
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def specific_matcher(arg)
|
||||||
|
splitted_arg = arg[/^\w+/, 0]
|
||||||
|
SPECIFIC_MATCHER[splitted_arg]
|
||||||
|
end
|
||||||
|
|
||||||
|
def acceptable_pattern?(arg)
|
||||||
|
arg.match?(/\[.+=\w+\]/) || arg.match?(/[ >,+]/)
|
||||||
|
end
|
||||||
|
|
||||||
|
def message(node, matcher)
|
||||||
|
format(MSG,
|
||||||
|
good_matcher: good_matcher(node, matcher),
|
||||||
|
bad_matcher: node.method_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def good_matcher(node, matcher)
|
||||||
|
node.method_name
|
||||||
|
.to_s
|
||||||
|
.gsub(/selector|css/, matcher.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -9,6 +9,8 @@ module RuboCop
|
|||||||
# # bad
|
# # bad
|
||||||
# expect { run }.to change(Foo, :bar).by(0)
|
# expect { run }.to change(Foo, :bar).by(0)
|
||||||
# expect { run }.to change { Foo.bar }.by(0)
|
# expect { run }.to change { Foo.bar }.by(0)
|
||||||
|
#
|
||||||
|
# # bad - compound expectations
|
||||||
# expect { run }
|
# expect { run }
|
||||||
# .to change(Foo, :bar).by(0)
|
# .to change(Foo, :bar).by(0)
|
||||||
# .and change(Foo, :baz).by(0)
|
# .and change(Foo, :baz).by(0)
|
||||||
@ -19,6 +21,9 @@ module RuboCop
|
|||||||
# # good
|
# # good
|
||||||
# expect { run }.not_to change(Foo, :bar)
|
# expect { run }.not_to change(Foo, :bar)
|
||||||
# expect { run }.not_to change { Foo.bar }
|
# expect { run }.not_to change { Foo.bar }
|
||||||
|
#
|
||||||
|
# # good - compound expectations
|
||||||
|
# define_negated_matcher :not_change, :change
|
||||||
# expect { run }
|
# expect { run }
|
||||||
# .to not_change(Foo, :bar)
|
# .to not_change(Foo, :bar)
|
||||||
# .and not_change(Foo, :baz)
|
# .and not_change(Foo, :baz)
|
||||||
@ -52,17 +57,17 @@ module RuboCop
|
|||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
expect_change_with_arguments(node.parent) do
|
expect_change_with_arguments(node.parent) do
|
||||||
check_offence(node.parent)
|
check_offense(node.parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
expect_change_with_block(node.parent.parent) do
|
expect_change_with_block(node.parent.parent) do
|
||||||
check_offence(node.parent.parent)
|
check_offense(node.parent.parent)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_offence(node)
|
def check_offense(node)
|
||||||
expression = node.loc.expression
|
expression = node.loc.expression
|
||||||
if compound_expectations?(node)
|
if compound_expectations?(node)
|
||||||
add_offense(expression, message: MSG_COMPOUND)
|
add_offense(expression, message: MSG_COMPOUND)
|
||||||
@ -11,7 +11,7 @@ module RuboCop
|
|||||||
# This cop can be configured using the `EnforcedStyle` and `SkipBlocks`
|
# This cop can be configured using the `EnforcedStyle` and `SkipBlocks`
|
||||||
# options.
|
# options.
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: described_class`
|
# @example `EnforcedStyle: described_class` (default)
|
||||||
# # bad
|
# # bad
|
||||||
# describe MyClass do
|
# describe MyClass do
|
||||||
# subject { MyClass.do_something }
|
# subject { MyClass.do_something }
|
||||||
@ -36,11 +36,9 @@ module RuboCop
|
|||||||
def on_block(node)
|
def on_block(node)
|
||||||
empty_hook?(node) do |hook|
|
empty_hook?(node) do |hook|
|
||||||
add_offense(hook) do |corrector|
|
add_offense(hook) do |corrector|
|
||||||
range = range_with_surrounding_space(
|
corrector.remove(
|
||||||
range: node.loc.expression,
|
range_with_surrounding_space(node.loc.expression, side: :left)
|
||||||
side: :left
|
|
||||||
)
|
)
|
||||||
corrector.remove(range)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -6,7 +6,7 @@ module RuboCop
|
|||||||
# Checks for long examples.
|
# Checks for long examples.
|
||||||
#
|
#
|
||||||
# A long example is usually more difficult to understand. Consider
|
# A long example is usually more difficult to understand. Consider
|
||||||
# extracting out some behaviour, e.g. with a `let` block, or a helper
|
# extracting out some behavior, e.g. with a `let` block, or a helper
|
||||||
# method.
|
# method.
|
||||||
#
|
#
|
||||||
# @example
|
# @example
|
||||||
@ -14,7 +14,7 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# This cop can be configured using the `EnforcedStyle` option
|
# This cop can be configured using the `EnforcedStyle` option
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: always_allow`
|
# @example `EnforcedStyle: always_allow` (default)
|
||||||
# # bad
|
# # bad
|
||||||
# it('') { is_expected.to be_good }
|
# it('') { is_expected.to be_good }
|
||||||
# it '' do
|
# it '' do
|
||||||
@ -5,6 +5,8 @@ module RuboCop
|
|||||||
module RSpec
|
module RSpec
|
||||||
# Checks for `expect(...)` calls containing literal values.
|
# Checks for `expect(...)` calls containing literal values.
|
||||||
#
|
#
|
||||||
|
# Autocorrection is performed when the expected is not a literal.
|
||||||
|
#
|
||||||
# @example
|
# @example
|
||||||
# # bad
|
# # bad
|
||||||
# expect(5).to eq(price)
|
# expect(5).to eq(price)
|
||||||
@ -10,14 +10,7 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# This cop can be configured using the `EnforcedStyle` option.
|
# This cop can be configured using the `EnforcedStyle` option.
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: block`
|
# @example `EnforcedStyle: method_call` (default)
|
||||||
# # bad
|
|
||||||
# expect { run }.to change(Foo, :bar)
|
|
||||||
#
|
|
||||||
# # good
|
|
||||||
# expect { run }.to change { Foo.bar }
|
|
||||||
#
|
|
||||||
# @example `EnforcedStyle: method_call`
|
|
||||||
# # bad
|
# # bad
|
||||||
# expect { run }.to change { Foo.bar }
|
# expect { run }.to change { Foo.bar }
|
||||||
# expect { run }.to change { foo.baz }
|
# expect { run }.to change { foo.baz }
|
||||||
@ -29,6 +22,13 @@ module RuboCop
|
|||||||
# expect { run }.to change { Foo.bar(:count) }
|
# expect { run }.to change { Foo.bar(:count) }
|
||||||
# expect { run }.to change { user.reload.name }
|
# expect { run }.to change { user.reload.name }
|
||||||
#
|
#
|
||||||
|
# @example `EnforcedStyle: block`
|
||||||
|
# # bad
|
||||||
|
# expect { run }.to change(Foo, :bar)
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# expect { run }.to change { Foo.bar }
|
||||||
|
#
|
||||||
class ExpectChange < Base
|
class ExpectChange < Base
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
@ -8,15 +8,21 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# This cop can be configured using the `EnforcedStyle` option
|
# This cop can be configured using the `EnforcedStyle` option
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: create_list`
|
# @example `EnforcedStyle: create_list` (default)
|
||||||
# # bad
|
# # bad
|
||||||
# 3.times { create :user }
|
# 3.times { create :user }
|
||||||
#
|
#
|
||||||
# # good
|
# # good
|
||||||
# create_list :user, 3
|
# create_list :user, 3
|
||||||
#
|
#
|
||||||
# # good
|
# # bad
|
||||||
# 3.times { |n| create :user, created_at: n.months.ago }
|
# 3.times { create :user, age: 18 }
|
||||||
|
#
|
||||||
|
# # good - index is used to alter the created models attributes
|
||||||
|
# 3.times { |n| create :user, age: n }
|
||||||
|
#
|
||||||
|
# # good - contains a method call, may return different values
|
||||||
|
# 3.times { create :user, age: rand }
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: n_times`
|
# @example `EnforcedStyle: n_times`
|
||||||
# # bad
|
# # bad
|
||||||
@ -33,15 +39,28 @@ module RuboCop
|
|||||||
MSG_N_TIMES = 'Prefer %<number>s.times.'
|
MSG_N_TIMES = 'Prefer %<number>s.times.'
|
||||||
RESTRICT_ON_SEND = %i[create_list].freeze
|
RESTRICT_ON_SEND = %i[create_list].freeze
|
||||||
|
|
||||||
# @!method n_times_block_without_arg?(node)
|
# @!method n_times_block?(node)
|
||||||
def_node_matcher :n_times_block_without_arg?, <<-PATTERN
|
def_node_matcher :n_times_block?, <<-PATTERN
|
||||||
(block
|
(block
|
||||||
(send (int _) :times)
|
(send (int _) :times)
|
||||||
(args)
|
|
||||||
...
|
...
|
||||||
)
|
)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
|
# @!method n_times_block_with_arg_and_used?(node)
|
||||||
|
def_node_matcher :n_times_block_with_arg_and_used?, <<-PATTERN
|
||||||
|
(block
|
||||||
|
(send (int _) :times)
|
||||||
|
(args (arg _value))
|
||||||
|
`_value
|
||||||
|
)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
# @!method arguments_include_method_call?(node)
|
||||||
|
def_node_matcher :arguments_include_method_call?, <<-PATTERN
|
||||||
|
(send ${nil? #factory_bot?} :create (sym $_) `$(send ...))
|
||||||
|
PATTERN
|
||||||
|
|
||||||
# @!method factory_call(node)
|
# @!method factory_call(node)
|
||||||
def_node_matcher :factory_call, <<-PATTERN
|
def_node_matcher :factory_call, <<-PATTERN
|
||||||
(send ${nil? #factory_bot?} :create (sym $_) $...)
|
(send ${nil? #factory_bot?} :create (sym $_) $...)
|
||||||
@ -54,7 +73,11 @@ module RuboCop
|
|||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless style == :create_list
|
return unless style == :create_list
|
||||||
return unless n_times_block_without_arg?(node)
|
|
||||||
|
return unless n_times_block?(node)
|
||||||
|
return if n_times_block_with_arg_and_used?(node)
|
||||||
|
return unless node.body
|
||||||
|
return if arguments_include_method_call?(node.body)
|
||||||
return unless contains_only_factory?(node.body)
|
return unless contains_only_factory?(node.body)
|
||||||
|
|
||||||
add_offense(node.send_node, message: MSG_CREATE_LIST) do |corrector|
|
add_offense(node.send_node, message: MSG_CREATE_LIST) do |corrector|
|
||||||
@ -193,7 +216,7 @@ module RuboCop
|
|||||||
if node.body.begin_type?
|
if node.body.begin_type?
|
||||||
format_multiline_block(node)
|
format_multiline_block(node)
|
||||||
else
|
else
|
||||||
format_singeline_block(node)
|
format_singleline_block(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -205,7 +228,7 @@ module RuboCop
|
|||||||
"#{indent_end}end"
|
"#{indent_end}end"
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_singeline_block(node)
|
def format_singleline_block(node)
|
||||||
" { #{node.arguments.source} #{node.body.source} }"
|
" { #{node.arguments.source} #{node.body.source} }"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -7,7 +7,7 @@ module RuboCop
|
|||||||
# Use shorthands from `FactoryBot::Syntax::Methods` in your specs.
|
# Use shorthands from `FactoryBot::Syntax::Methods` in your specs.
|
||||||
#
|
#
|
||||||
# @safety
|
# @safety
|
||||||
# The auto-correction is marked as unsafe because the cop
|
# The autocorrection is marked as unsafe because the cop
|
||||||
# cannot verify whether you already include
|
# cannot verify whether you already include
|
||||||
# `FactoryBot::Syntax::Methods` in your test suite.
|
# `FactoryBot::Syntax::Methods` in your test suite.
|
||||||
#
|
#
|
||||||
@ -117,8 +117,9 @@ module RuboCop
|
|||||||
|
|
||||||
def name_pattern(method_name)
|
def name_pattern(method_name)
|
||||||
return unless method_name&.str_type?
|
return unless method_name&.str_type?
|
||||||
|
return if ignore_methods?
|
||||||
|
|
||||||
".*#{method_name.str_content.gsub(/\W/, '')}" unless ignore_methods?
|
".*#{method_name.str_content.gsub(/\s/, '_').gsub(/\W/, '')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def expected_path(constant)
|
def expected_path(constant)
|
||||||
@ -69,10 +69,8 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def with_surrounding(focus)
|
def with_surrounding(focus)
|
||||||
range_with_space = range_with_surrounding_space(
|
range_with_space =
|
||||||
range: focus.loc.expression,
|
range_with_surrounding_space(focus.loc.expression, side: :left)
|
||||||
side: :left
|
|
||||||
)
|
|
||||||
|
|
||||||
range_with_surrounding_comma(range_with_space, :left)
|
range_with_surrounding_comma(range_with_space, :left)
|
||||||
end
|
end
|
||||||
@ -10,7 +10,7 @@ module RuboCop
|
|||||||
# styles: "implicit", "each", and "example." All styles have
|
# styles: "implicit", "each", and "example." All styles have
|
||||||
# the same behavior.
|
# the same behavior.
|
||||||
#
|
#
|
||||||
# @example when configuration is `EnforcedStyle: implicit`
|
# @example `EnforcedStyle: implicit` (default)
|
||||||
# # bad
|
# # bad
|
||||||
# before(:each) do
|
# before(:each) do
|
||||||
# # ...
|
# # ...
|
||||||
@ -26,7 +26,7 @@ module RuboCop
|
|||||||
# # ...
|
# # ...
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# @example when configuration is `EnforcedStyle: each`
|
# @example `EnforcedStyle: each`
|
||||||
# # bad
|
# # bad
|
||||||
# before(:example) do
|
# before(:example) do
|
||||||
# # ...
|
# # ...
|
||||||
@ -42,7 +42,7 @@ module RuboCop
|
|||||||
# # ...
|
# # ...
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# @example when configuration is `EnforcedStyle: example`
|
# @example `EnforcedStyle: example`
|
||||||
# # bad
|
# # bad
|
||||||
# before(:each) do
|
# before(:each) do
|
||||||
# # ...
|
# # ...
|
||||||
@ -8,7 +8,7 @@ module RuboCop
|
|||||||
# This cop can be configured using the `EnforcedStyle` option
|
# This cop can be configured using the `EnforcedStyle` option
|
||||||
# and supports the `--auto-gen-config` flag.
|
# and supports the `--auto-gen-config` flag.
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: is_expected`
|
# @example `EnforcedStyle: is_expected` (default)
|
||||||
#
|
#
|
||||||
# # bad
|
# # bad
|
||||||
# it { should be_truthy }
|
# it { should be_truthy }
|
||||||
@ -5,14 +5,14 @@ module RuboCop
|
|||||||
module RSpec
|
module RSpec
|
||||||
# Checks that only one `it_behaves_like` style is used.
|
# Checks that only one `it_behaves_like` style is used.
|
||||||
#
|
#
|
||||||
# @example when configuration is `EnforcedStyle: it_behaves_like`
|
# @example `EnforcedStyle: it_behaves_like` (default)
|
||||||
# # bad
|
# # bad
|
||||||
# it_should_behave_like 'a foo'
|
# it_should_behave_like 'a foo'
|
||||||
#
|
#
|
||||||
# # good
|
# # good
|
||||||
# it_behaves_like 'a foo'
|
# it_behaves_like 'a foo'
|
||||||
#
|
#
|
||||||
# @example when configuration is `EnforcedStyle: it_should_behave_like`
|
# @example `EnforcedStyle: it_should_behave_like`
|
||||||
# # bad
|
# # bad
|
||||||
# it_behaves_like 'a foo'
|
# it_behaves_like 'a foo'
|
||||||
#
|
#
|
||||||
@ -10,7 +10,7 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# If several examples may define a `DummyClass`, instead of being a
|
# If several examples may define a `DummyClass`, instead of being a
|
||||||
# blank slate class as it will be in the first example, subsequent
|
# blank slate class as it will be in the first example, subsequent
|
||||||
# examples will be reopening it and modifying its behaviour in
|
# examples will be reopening it and modifying its behavior in
|
||||||
# unpredictable ways.
|
# unpredictable ways.
|
||||||
# Even worse when a class that exists in the codebase is reopened.
|
# Even worse when a class that exists in the codebase is reopened.
|
||||||
#
|
#
|
||||||
@ -8,7 +8,7 @@ module RuboCop
|
|||||||
# This cop can be configured in your configuration using the
|
# This cop can be configured in your configuration using the
|
||||||
# `EnforcedStyle` option and supports `--auto-gen-config`.
|
# `EnforcedStyle` option and supports `--auto-gen-config`.
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: allow`
|
# @example `EnforcedStyle: allow` (default)
|
||||||
#
|
#
|
||||||
# # bad
|
# # bad
|
||||||
# expect(foo).to receive(:bar)
|
# expect(foo).to receive(:bar)
|
||||||
@ -8,21 +8,27 @@ module RuboCop
|
|||||||
# This cop can be configured in your configuration using the
|
# This cop can be configured in your configuration using the
|
||||||
# `EnforcedStyle` option and supports `--auto-gen-config`.
|
# `EnforcedStyle` option and supports `--auto-gen-config`.
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: have_received`
|
# @example `EnforcedStyle: have_received` (default)
|
||||||
#
|
#
|
||||||
# # bad
|
# # bad
|
||||||
# expect(foo).to receive(:bar)
|
# expect(foo).to receive(:bar)
|
||||||
|
# do_something
|
||||||
#
|
#
|
||||||
# # good
|
# # good
|
||||||
|
# allow(foo).to receive(:bar) # or use instance_spy
|
||||||
|
# do_something
|
||||||
# expect(foo).to have_received(:bar)
|
# expect(foo).to have_received(:bar)
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: receive`
|
# @example `EnforcedStyle: receive`
|
||||||
#
|
#
|
||||||
# # bad
|
# # bad
|
||||||
|
# allow(foo).to receive(:bar)
|
||||||
|
# do_something
|
||||||
# expect(foo).to have_received(:bar)
|
# expect(foo).to have_received(:bar)
|
||||||
#
|
#
|
||||||
# # good
|
# # good
|
||||||
# expect(foo).to receive(:bar)
|
# expect(foo).to receive(:bar)
|
||||||
|
# do_something
|
||||||
#
|
#
|
||||||
class MessageSpies < Base
|
class MessageSpies < Base
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
@ -4,7 +4,10 @@ module RuboCop
|
|||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
# Helps determine the offending location if there is not an empty line
|
# Helps determine the offending location if there is not an empty line
|
||||||
# following the node. Allows comments to follow directly after.
|
# following the node. Allows comments to follow directly after
|
||||||
|
# in the following cases.
|
||||||
|
# - `rubocop:enable` directive
|
||||||
|
# - followed by empty line(s)
|
||||||
module EmptyLineSeparation
|
module EmptyLineSeparation
|
||||||
include FinalEndLocation
|
include FinalEndLocation
|
||||||
include RangeHelp
|
include RangeHelp
|
||||||
@ -21,13 +24,19 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def missing_separating_line(node)
|
def missing_separating_line(node)
|
||||||
line = final_end_location(node).line
|
line = final_end_line = final_end_location(node).line
|
||||||
|
|
||||||
line += 1 while comment_line?(processed_source[line])
|
while comment_line?(processed_source[line])
|
||||||
|
line += 1
|
||||||
|
comment = processed_source.comment_at_line(line)
|
||||||
|
if DirectiveComment.new(comment).enabled?
|
||||||
|
enable_directive_line = line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return if processed_source[line].blank?
|
return if processed_source[line].blank?
|
||||||
|
|
||||||
yield offending_loc(line)
|
yield offending_loc(enable_directive_line || final_end_line)
|
||||||
end
|
end
|
||||||
|
|
||||||
def offending_loc(last_line)
|
def offending_loc(last_line)
|
||||||
@ -31,6 +31,26 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
# @example `aggregate_failures: true` (default)
|
||||||
|
#
|
||||||
|
# # good - the cop ignores when RSpec aggregates failures
|
||||||
|
# describe UserCreator do
|
||||||
|
# it 'builds a user', :aggregate_failures do
|
||||||
|
# expect(user.name).to eq("John")
|
||||||
|
# expect(user.age).to eq(22)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# @example `aggregate_failures: false`
|
||||||
|
#
|
||||||
|
# # Detected as an offense
|
||||||
|
# describe UserCreator do
|
||||||
|
# it 'builds a user', aggregate_failures: false do
|
||||||
|
# expect(user.name).to eq("John")
|
||||||
|
# expect(user.age).to eq(22)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
# @example configuration
|
# @example configuration
|
||||||
#
|
#
|
||||||
# # .rubocop.yml
|
# # .rubocop.yml
|
||||||
@ -5,7 +5,8 @@ module RuboCop
|
|||||||
module RSpec
|
module RSpec
|
||||||
# Checks for consistent method usage for negating expectations.
|
# Checks for consistent method usage for negating expectations.
|
||||||
#
|
#
|
||||||
# @example
|
# @example `EnforcedStyle: not_to` (default)
|
||||||
|
#
|
||||||
# # bad
|
# # bad
|
||||||
# it '...' do
|
# it '...' do
|
||||||
# expect(false).to_not be_true
|
# expect(false).to_not be_true
|
||||||
@ -15,6 +16,18 @@ module RuboCop
|
|||||||
# it '...' do
|
# it '...' do
|
||||||
# expect(false).not_to be_true
|
# expect(false).not_to be_true
|
||||||
# end
|
# end
|
||||||
|
#
|
||||||
|
# @example `EnforcedStyle: to_not`
|
||||||
|
#
|
||||||
|
# # bad
|
||||||
|
# it '...' do
|
||||||
|
# expect(false).not_to be_true
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# it '...' do
|
||||||
|
# expect(false).to_not be_true
|
||||||
|
# end
|
||||||
class NotToNot < Base
|
class NotToNot < Base
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module RSpec
|
||||||
|
module Rails
|
||||||
|
# Checks that tests use `have_http_status` instead of equality matchers.
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# # bad
|
||||||
|
# expect(response.status).to be(200)
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# expect(response).to have_http_status(200)
|
||||||
|
#
|
||||||
|
class HaveHttpStatus < Base
|
||||||
|
extend AutoCorrector
|
||||||
|
|
||||||
|
MSG =
|
||||||
|
'Prefer `expect(response).%<to>s have_http_status(%<status>i)` ' \
|
||||||
|
'over `expect(response.status).%<to>s %<match>s`.'
|
||||||
|
|
||||||
|
# @!method match_status(node)
|
||||||
|
def_node_matcher :match_status, <<-PATTERN
|
||||||
|
(send
|
||||||
|
(send nil? :expect
|
||||||
|
$(send (send nil? :response) :status)
|
||||||
|
)
|
||||||
|
$#Runners.all
|
||||||
|
$(send nil? {:be :eq :eql :equal} (int $_))
|
||||||
|
)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def on_send(node)
|
||||||
|
match_status(node) do |response_status, to, match, status|
|
||||||
|
message = format(MSG, to: to, match: match.source, status: status)
|
||||||
|
add_offense(node, message: message) do |corrector|
|
||||||
|
corrector.replace(response_status.source_range, 'response')
|
||||||
|
corrector.replace(match.loc.selector, 'have_http_status')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -11,6 +11,17 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# This cop can be configured using the `EnforcedStyle` option
|
# This cop can be configured using the `EnforcedStyle` option
|
||||||
#
|
#
|
||||||
|
# @example `EnforcedStyle: and_return` (default)
|
||||||
|
# # bad
|
||||||
|
# allow(Foo).to receive(:bar) { "baz" }
|
||||||
|
# expect(Foo).to receive(:bar) { "baz" }
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# allow(Foo).to receive(:bar).and_return("baz")
|
||||||
|
# expect(Foo).to receive(:bar).and_return("baz")
|
||||||
|
# # also good as the returned value is dynamic
|
||||||
|
# allow(Foo).to receive(:bar) { bar.baz }
|
||||||
|
#
|
||||||
# @example `EnforcedStyle: block`
|
# @example `EnforcedStyle: block`
|
||||||
# # bad
|
# # bad
|
||||||
# allow(Foo).to receive(:bar).and_return("baz")
|
# allow(Foo).to receive(:bar).and_return("baz")
|
||||||
@ -22,17 +33,6 @@ module RuboCop
|
|||||||
# # also good as the returned value is dynamic
|
# # also good as the returned value is dynamic
|
||||||
# allow(Foo).to receive(:bar).and_return(bar.baz)
|
# allow(Foo).to receive(:bar).and_return(bar.baz)
|
||||||
#
|
#
|
||||||
# @example `EnforcedStyle: and_return`
|
|
||||||
# # bad
|
|
||||||
# allow(Foo).to receive(:bar) { "baz" }
|
|
||||||
# expect(Foo).to receive(:bar) { "baz" }
|
|
||||||
#
|
|
||||||
# # good
|
|
||||||
# allow(Foo).to receive(:bar).and_return("baz")
|
|
||||||
# expect(Foo).to receive(:bar).and_return("baz")
|
|
||||||
# # also good as the returned value is dynamic
|
|
||||||
# allow(Foo).to receive(:bar) { bar.baz }
|
|
||||||
#
|
|
||||||
class ReturnFromStub < Base
|
class ReturnFromStub < Base
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
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