fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip]
Updated Layout/LineLength cop to Max 120 lenght and ignore everything inside specs/**/* Added rules for below cops in .rubocop.yml Lint/AmbiguousBlockAssociation Naming/HeredocDelimiterNaming Rails/SkipsModelValidations Style/FormatStringToken Fixed below mentioned cops: - Layout/CaseIndentation - Layout/DotPosition - Layout/ElseAlignment - Layout/IndentationWidth - Layout/LineLength - Layout/MultilineBlockLayout - Layout/MultilineOperationIndentation - Lint/AmbiguousBlockAssociation - Lint/MissingCopEnableDirective - Lint/NestedMethodDefinition - Lint/RedundantCopDisableDirective - Lint/RedundantRequireStatement - Lint/UnusedBlockArgument - Lint/UnusedMethodArgument - Metrics/ModuleLength - Naming/MemoizedInstanceVariableName - Naming/RescuedExceptionsVariableName - Rails/Output - Rails/Presence - Security/Eval - Security/Open - Style/ClassCheck - Style/CollectionMethods - Style/ConditionalAssignment - Style/EvalWithLocation - Style/FormatStringToken - Style/InverseMethods - Style/MutableConstant - Style/ParallelAssignment - Style/RedundantBegin - Style/RedundantCondition - Style/RedundantInterpolation - Style/RedundantSelf - Style/RedundantSort - Style/RescueStandardError - Style/SafeNavigation - Style/StringLiteralsInInterpolation - Style/SymbolProc
This commit is contained in:
parent
ee1008de7a
commit
3e88500318
28
.rubocop.yml
28
.rubocop.yml
|
@ -17,15 +17,13 @@ Layout/EmptyLineBetweenDefs:
|
|||
Layout/HeredocIndentation:
|
||||
Enabled: false
|
||||
Layout/LineLength:
|
||||
Exclude:
|
||||
- spec/**/*
|
||||
IgnoredPatterns:
|
||||
- "^[ ]*#.+$"
|
||||
- "^[ ]*describe.+$"
|
||||
- "^[ ]*context.+$"
|
||||
- "^[ ]*shared_context.+$"
|
||||
- "^[ ]*shared_examples_for.+$"
|
||||
- "^[ ]*it.+$"
|
||||
- "^[ ]*'.+?' => '.+?',?$"
|
||||
- "^[ ]*\".+?\" => \".+?\",?$"
|
||||
- '^[ ]*#.+$'
|
||||
- '^[ ]*''.+?'' => ''.+?'',?$'
|
||||
- '^[ ]*".+?" => ".+?",?$'
|
||||
Max: 120
|
||||
Layout/MultilineMethodCallIndentation:
|
||||
EnforcedStyle: indented
|
||||
Layout/ParameterAlignment:
|
||||
|
@ -34,6 +32,9 @@ Layout/SpaceInLambdaLiteral:
|
|||
EnforcedStyle: require_space
|
||||
Layout/SpaceInsideBlockBraces:
|
||||
Enabled: false
|
||||
Lint/AmbiguousBlockAssociation:
|
||||
Exclude:
|
||||
- spec/**/*
|
||||
Lint/AmbiguousOperator:
|
||||
Enabled: false
|
||||
Lint/AmbiguousRegexpLiteral:
|
||||
|
@ -70,6 +71,10 @@ Metrics/ClassLength:
|
|||
Enabled: false
|
||||
Metrics/MethodLength:
|
||||
Max: 30
|
||||
Metrics/ModuleLength:
|
||||
Enabled: true
|
||||
Exclude:
|
||||
- spec/**/*
|
||||
Metrics/ParameterLists:
|
||||
CountKeywordArgs: false
|
||||
Metrics/PerceivedComplexity:
|
||||
|
@ -82,6 +87,8 @@ Naming/BinaryOperatorParameterName:
|
|||
Enabled: false
|
||||
Naming/FileName:
|
||||
Enabled: false
|
||||
Naming/HeredocDelimiterNaming:
|
||||
Enabled: false
|
||||
Naming/MemoizedInstanceVariableName:
|
||||
EnforcedStyleForLeadingUnderscores: required
|
||||
Naming/PredicateName:
|
||||
|
@ -92,6 +99,9 @@ Rails/Delegate:
|
|||
Enabled: false
|
||||
Rails/HttpPositionalArguments:
|
||||
Enabled: false
|
||||
Rails/SkipsModelValidations:
|
||||
Exclude:
|
||||
- spec/**/*
|
||||
Rails/TimeZone:
|
||||
Enabled: false
|
||||
Style/Alias:
|
||||
|
@ -139,6 +149,8 @@ Style/EvenOdd:
|
|||
Enabled: false
|
||||
Style/FormatString:
|
||||
Enabled: false
|
||||
Style/FormatStringToken:
|
||||
EnforcedStyle: template
|
||||
Style/FrozenStringLiteralComment:
|
||||
Enabled: false
|
||||
Style/GlobalVars:
|
||||
|
|
|
@ -41,8 +41,8 @@ class CustomPlan < Zeus::Plan
|
|||
end
|
||||
|
||||
require_relative 'spec/support/unit/load_environment'
|
||||
rescue Gem::LoadError => error
|
||||
raise CouldNotBootZeusError.create(underlying_error: error)
|
||||
rescue Gem::LoadError => e
|
||||
raise CouldNotBootZeusError.create(underlying_error: e)
|
||||
end
|
||||
|
||||
def after_fork; end
|
||||
|
|
|
@ -10,11 +10,11 @@ end
|
|||
def diskfile
|
||||
@file.attributes[:markup] ||= markup_for_file('', @file.filename)
|
||||
|
||||
if @file.filename == 'README.md'
|
||||
contents = preprocess_index(@file.contents)
|
||||
else
|
||||
contents = @file.contents
|
||||
end
|
||||
contents = if @file.filename == 'README.md'
|
||||
preprocess_index(@file.contents)
|
||||
else
|
||||
@file.contents
|
||||
end
|
||||
|
||||
data = htmlify(contents, @file.attributes[:markup])
|
||||
"<div id='filecontents'>" + data + '</div>'
|
||||
|
@ -24,7 +24,8 @@ def preprocess_index(contents)
|
|||
regex = /\[ (\w+) \] \( lib \/ ([^()]+) \.rb (?:\#L\d+)? \)/x
|
||||
|
||||
contents.gsub(regex) do
|
||||
method_name, file_path = $1, $2
|
||||
method_name = $1
|
||||
file_path = $2
|
||||
|
||||
module_name = file_path.split('/')[0..2].
|
||||
map do |value|
|
||||
|
|
|
@ -31,7 +31,7 @@ module Shoulda
|
|||
@key = key
|
||||
end
|
||||
|
||||
def matches?(controller)
|
||||
def matches?(_controller)
|
||||
filters_key?
|
||||
end
|
||||
|
||||
|
|
|
@ -303,11 +303,11 @@ module Shoulda
|
|||
|
||||
def actual_permitted_parameter_names
|
||||
@_actual_permitted_parameter_names ||= begin
|
||||
if subparameter_name
|
||||
options = { for: subparameter_name }
|
||||
else
|
||||
options = {}
|
||||
end
|
||||
options = if subparameter_name
|
||||
{ for: subparameter_name }
|
||||
else
|
||||
{}
|
||||
end
|
||||
|
||||
parameters_double_registry.permitted_parameter_names(options)
|
||||
end
|
||||
|
@ -329,8 +329,8 @@ module Shoulda
|
|||
|
||||
def default_verb
|
||||
case action
|
||||
when :create then :post
|
||||
when :update then RailsShim.verb_for_update
|
||||
when :create then :post
|
||||
when :update then RailsShim.verb_for_update
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -75,14 +75,12 @@ module Shoulda
|
|||
private
|
||||
|
||||
def redirects_to_url?
|
||||
begin
|
||||
@context.__send__(:assert_redirected_to, url)
|
||||
@failure_message_when_negated = "Didn't expect to redirect to #{url}"
|
||||
true
|
||||
rescue Shoulda::Matchers.assertion_exception_class => error
|
||||
@failure_message = error.message
|
||||
false
|
||||
end
|
||||
@context.__send__(:assert_redirected_to, url)
|
||||
@failure_message_when_negated = "Didn't expect to redirect to #{url}"
|
||||
true
|
||||
rescue Shoulda::Matchers.assertion_exception_class => e
|
||||
@failure_message = e.message
|
||||
false
|
||||
end
|
||||
|
||||
def url
|
||||
|
|
|
@ -71,14 +71,12 @@ module Shoulda
|
|||
private
|
||||
|
||||
def renders_template?
|
||||
begin
|
||||
@context.__send__(:assert_template, @options, @message)
|
||||
@failure_message_when_negated = "Didn't expect to render #{@template}"
|
||||
true
|
||||
rescue Shoulda::Matchers.assertion_exception_class => error
|
||||
@failure_message = error.message
|
||||
false
|
||||
end
|
||||
@context.__send__(:assert_template, @options, @message)
|
||||
@failure_message_when_negated = "Didn't expect to render #{@template}"
|
||||
true
|
||||
rescue Shoulda::Matchers.assertion_exception_class => e
|
||||
@failure_message = e.message
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,11 +64,11 @@ module Shoulda
|
|||
# @private
|
||||
class RenderWithLayoutMatcher
|
||||
def initialize(expected_layout)
|
||||
if expected_layout
|
||||
@expected_layout = expected_layout.to_s
|
||||
else
|
||||
@expected_layout = nil
|
||||
end
|
||||
@expected_layout = if expected_layout
|
||||
expected_layout.to_s
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
@controller = nil
|
||||
end
|
||||
|
@ -95,11 +95,11 @@ module Shoulda
|
|||
|
||||
def description
|
||||
description = 'render with '
|
||||
if @expected_layout.nil?
|
||||
description << 'a layout'
|
||||
else
|
||||
description << "the #{@expected_layout.inspect} layout"
|
||||
end
|
||||
description << if @expected_layout.nil?
|
||||
'a layout'
|
||||
else
|
||||
"the #{@expected_layout.inspect} layout"
|
||||
end
|
||||
description
|
||||
end
|
||||
|
||||
|
|
|
@ -194,11 +194,11 @@ module Shoulda
|
|||
params,
|
||||
)
|
||||
true
|
||||
rescue ::ActionController::RoutingError => error
|
||||
@failure_message = error.message
|
||||
rescue ::ActionController::RoutingError => e
|
||||
@failure_message = e.message
|
||||
false
|
||||
rescue Shoulda::Matchers.assertion_exception_class => error
|
||||
@failure_message = error.message
|
||||
rescue Shoulda::Matchers.assertion_exception_class => e
|
||||
@failure_message = e.message
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module Shoulda
|
|||
module ActionController
|
||||
# @private
|
||||
class RouteParams
|
||||
PARAMS_TO_SYMBOLIZE = %i{format}
|
||||
PARAMS_TO_SYMBOLIZE = %i{format}.freeze
|
||||
|
||||
def initialize(args)
|
||||
@args = args
|
||||
|
|
|
@ -20,7 +20,8 @@ module Shoulda
|
|||
def to(expected_value = nil, &block)
|
||||
if block
|
||||
unless context_set?
|
||||
message = "When specifying a value as a block, a context must be specified beforehand, e.g., #{store.name}.in_context(context).to { ... }"
|
||||
message = "When specifying a value as a block, a context must be specified beforehand,
|
||||
e.g., #{store.name}.in_context(context).to { ... }"
|
||||
raise ArgumentError, message
|
||||
end
|
||||
|
||||
|
@ -81,18 +82,18 @@ module Shoulda
|
|||
def expectation_description
|
||||
string = 'set'
|
||||
|
||||
if key_set?
|
||||
string << " #{store.name}[#{key.inspect}]"
|
||||
else
|
||||
string << " any key in #{store.name}"
|
||||
end
|
||||
string << if key_set?
|
||||
" #{store.name}[#{key.inspect}]"
|
||||
else
|
||||
" any key in #{store.name}"
|
||||
end
|
||||
|
||||
if expected_value_set?
|
||||
if expected_value.is_a?(Regexp)
|
||||
string << " to a value matching #{expected_value.inspect}"
|
||||
else
|
||||
string << " to #{expected_value.inspect}"
|
||||
end
|
||||
string << if expected_value.is_a?(Regexp)
|
||||
" to a value matching #{expected_value.inspect}"
|
||||
else
|
||||
" to #{expected_value.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
string
|
||||
|
|
|
@ -99,11 +99,11 @@ module Shoulda
|
|||
end
|
||||
true
|
||||
else
|
||||
if whitelisting?
|
||||
@failure_message = "Expected #{@attribute} to be accessible"
|
||||
else
|
||||
@failure_message = "Did not expect #{@attribute} to be protected"
|
||||
end
|
||||
@failure_message = if whitelisting?
|
||||
"Expected #{@attribute} to be accessible"
|
||||
else
|
||||
"Did not expect #{@attribute} to be protected"
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
|
@ -129,15 +129,15 @@ module Shoulda
|
|||
end
|
||||
|
||||
def protected_attributes
|
||||
@protected_attributes ||= (@subject.class.protected_attributes || [])
|
||||
@_protected_attributes ||= (@subject.class.protected_attributes || [])
|
||||
end
|
||||
|
||||
def accessible_attributes
|
||||
@accessible_attributes ||= (@subject.class.accessible_attributes || [])
|
||||
@_accessible_attributes ||= (@subject.class.accessible_attributes || [])
|
||||
end
|
||||
|
||||
def whitelisting?
|
||||
authorizer.kind_of?(::ActiveModel::MassAssignmentSecurity::WhiteList)
|
||||
authorizer.is_a?(::ActiveModel::MassAssignmentSecurity::WhiteList)
|
||||
end
|
||||
|
||||
def attr_mass_assignable?
|
||||
|
|
|
@ -447,11 +447,11 @@ module Shoulda
|
|||
else
|
||||
message << ' produce'
|
||||
|
||||
if expected_message.is_a?(Regexp)
|
||||
message << ' a'
|
||||
else
|
||||
message << ' the'
|
||||
end
|
||||
message << if expected_message.is_a?(Regexp)
|
||||
' a'
|
||||
else
|
||||
' the'
|
||||
end
|
||||
|
||||
message << ' validation error'
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module Shoulda
|
|||
:<= => :less_than_or_equal_to,
|
||||
:== => :equal_to,
|
||||
:!= => :other_than,
|
||||
}
|
||||
}.freeze
|
||||
|
||||
def initialize(numericality_matcher, value, operator)
|
||||
super(nil)
|
||||
|
@ -77,7 +77,7 @@ module Shoulda
|
|||
|
||||
def failing_submatchers
|
||||
submatchers_and_results.
|
||||
select { |x| !x[:matched] }.
|
||||
reject { |x| x[:matched] }.
|
||||
map { |x| x[:matcher] }
|
||||
end
|
||||
|
||||
|
@ -145,12 +145,12 @@ module Shoulda
|
|||
|
||||
def comparison_expectation
|
||||
case @operator
|
||||
when :> then 'greater than'
|
||||
when :>= then 'greater than or equal to'
|
||||
when :== then 'equal to'
|
||||
when :< then 'less than'
|
||||
when :<= then 'less than or equal to'
|
||||
when :!= then 'other than'
|
||||
when :> then 'greater than'
|
||||
when :>= then 'greater than or equal to'
|
||||
when :== then 'equal to'
|
||||
when :< then 'less than'
|
||||
when :<= then 'less than or equal to'
|
||||
when :!= then 'other than'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Shoulda
|
|||
module IgnoringInterferenceByWriter
|
||||
attr_reader :ignore_interference_by_writer
|
||||
|
||||
def initialize(*args)
|
||||
def initialize(*_args)
|
||||
@ignore_interference_by_writer = IgnoreInterferenceByWriter.new
|
||||
end
|
||||
|
||||
|
|
|
@ -146,11 +146,11 @@ module Shoulda
|
|||
else
|
||||
description = "validate that :#{@attribute}"
|
||||
|
||||
if @array.many?
|
||||
description << " is neither #{inspected_array}"
|
||||
else
|
||||
description << " is not #{inspected_array}"
|
||||
end
|
||||
description << if @array.many?
|
||||
" is neither #{inspected_array}"
|
||||
else
|
||||
" is not #{inspected_array}"
|
||||
end
|
||||
|
||||
description
|
||||
end
|
||||
|
|
|
@ -268,20 +268,20 @@ module Shoulda
|
|||
|
||||
# @private
|
||||
class ValidateInclusionOfMatcher < ValidationMatcher
|
||||
BLANK_VALUES = ['', ' ', "\n", "\r", "\t", "\f"]
|
||||
ARBITRARY_OUTSIDE_STRING = 'shoulda-matchers test string'
|
||||
BLANK_VALUES = ['', ' ', "\n", "\r", "\t", "\f"].freeze
|
||||
ARBITRARY_OUTSIDE_STRING = 'shoulda-matchers test string'.freeze
|
||||
ARBITRARY_OUTSIDE_INTEGER = 123456789
|
||||
ARBITRARY_OUTSIDE_DECIMAL = BigDecimal('0.123456789')
|
||||
ARBITRARY_OUTSIDE_DATE = Date.jd(9999999)
|
||||
ARBITRARY_OUTSIDE_DATETIME = DateTime.jd(9999999)
|
||||
ARBITRARY_OUTSIDE_TIME = Time.at(9999999999)
|
||||
BOOLEAN_ALLOWS_BOOLEAN_MESSAGE = <<EOT
|
||||
BOOLEAN_ALLOWS_BOOLEAN_MESSAGE = <<EOT.freeze
|
||||
You are using `validate_inclusion_of` to assert that a boolean column allows
|
||||
boolean values and disallows non-boolean ones. Be aware that it is not possible
|
||||
to fully test this, as boolean columns will automatically convert non-boolean
|
||||
values to boolean ones. Hence, you should consider removing this test.
|
||||
EOT
|
||||
BOOLEAN_ALLOWS_NIL_MESSAGE = <<EOT
|
||||
BOOLEAN_ALLOWS_NIL_MESSAGE = <<EOT.freeze
|
||||
You are using `validate_inclusion_of` to assert that a boolean column allows nil.
|
||||
Be aware that it is not possible to fully test this, as anything other than
|
||||
true, false or nil will be converted to false. Hence, you should consider
|
||||
|
@ -354,11 +354,11 @@ EOT
|
|||
else
|
||||
description = "validate that :#{@attribute}"
|
||||
|
||||
if @array.many?
|
||||
description << " is either #{inspected_array}"
|
||||
else
|
||||
description << " is #{inspected_array}"
|
||||
end
|
||||
description << if @array.many?
|
||||
" is either #{inspected_array}"
|
||||
else
|
||||
" is #{inspected_array}"
|
||||
end
|
||||
|
||||
description
|
||||
end
|
||||
|
@ -581,21 +581,21 @@ EOT
|
|||
|
||||
def column_type_to_attribute_type(type)
|
||||
case type
|
||||
when :float then :integer
|
||||
when :timestamp then :datetime
|
||||
else type
|
||||
when :float then :integer
|
||||
when :timestamp then :datetime
|
||||
else type
|
||||
end
|
||||
end
|
||||
|
||||
def value_to_attribute_type(value)
|
||||
case value
|
||||
when true, false then :boolean
|
||||
when BigDecimal then :decimal
|
||||
when Integer then :integer
|
||||
when Date then :date
|
||||
when DateTime then :datetime
|
||||
when Time then :time
|
||||
else :unknown
|
||||
when true, false then :boolean
|
||||
when BigDecimal then :decimal
|
||||
when Integer then :integer
|
||||
when Date then :date
|
||||
when DateTime then :datetime
|
||||
when Time then :time
|
||||
else :unknown
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -331,8 +331,8 @@ module Shoulda
|
|||
|
||||
# @private
|
||||
class ValidateNumericalityOfMatcher
|
||||
NUMERIC_NAME = 'number'
|
||||
NON_NUMERIC_VALUE = 'abcd'
|
||||
NUMERIC_NAME = 'number'.freeze
|
||||
NON_NUMERIC_VALUE = 'abcd'.freeze
|
||||
DEFAULT_DIFF_TO_COMPARE = 1
|
||||
|
||||
include Qualifiers::IgnoringInterferenceByWriter
|
||||
|
@ -600,13 +600,13 @@ module Shoulda
|
|||
end
|
||||
|
||||
def first_submatcher_that_fails_to_match
|
||||
@_failing_submatchers ||= @submatchers.detect do |submatcher|
|
||||
@_first_submatcher_that_fails_to_match ||= @submatchers.detect do |submatcher|
|
||||
!submatcher.matches?(@subject)
|
||||
end
|
||||
end
|
||||
|
||||
def first_submatcher_that_fails_to_not_match
|
||||
@_failing_submatchers ||= @submatchers.detect do |submatcher|
|
||||
@_first_submatcher_that_fails_to_not_match ||= @submatchers.detect do |submatcher|
|
||||
!submatcher.does_not_match?(@subject)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -50,7 +50,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def validated_instance
|
||||
@validated_instance ||= validate_instance
|
||||
@_validated_instance ||= validate_instance
|
||||
end
|
||||
|
||||
def validate_instance
|
||||
|
|
|
@ -110,12 +110,12 @@ module Shoulda
|
|||
validation_error_messages: validation_error_messages,
|
||||
validation_exception_message: nil,
|
||||
}
|
||||
rescue ::ActiveModel::StrictValidationFailed => exception
|
||||
rescue ::ActiveModel::StrictValidationFailed => e
|
||||
@captured_validation_exception = true
|
||||
{
|
||||
all_validation_errors: nil,
|
||||
validation_error_messages: [],
|
||||
validation_exception_message: exception.message,
|
||||
validation_exception_message: e.message,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1163,7 +1163,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def option_verifier
|
||||
@option_verifier ||= AssociationMatchers::OptionVerifier.new(reflector)
|
||||
@_option_verifier ||= AssociationMatchers::OptionVerifier.new(reflector)
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -1171,7 +1171,7 @@ module Shoulda
|
|||
attr_reader :submatchers, :missing, :subject, :macro
|
||||
|
||||
def reflector
|
||||
@reflector ||= AssociationMatchers::ModelReflector.new(subject, name)
|
||||
@_reflector ||= AssociationMatchers::ModelReflector.new(subject, name)
|
||||
end
|
||||
|
||||
def add_submatcher(matcher_class, *args)
|
||||
|
@ -1215,9 +1215,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def failing_submatchers
|
||||
@failing_submatchers ||= submatchers.select do |matcher|
|
||||
!matcher.matches?(subject)
|
||||
end
|
||||
@_failing_submatchers ||= submatchers.reject { |matcher| matcher.matches?(subject) }
|
||||
end
|
||||
|
||||
def missing_options_for_failing_submatchers
|
||||
|
@ -1252,8 +1250,8 @@ module Shoulda
|
|||
def validate_inverse_of_through_association
|
||||
reflector.validate_inverse_of_through_association!
|
||||
true
|
||||
rescue ::ActiveRecord::ActiveRecordError => error
|
||||
@missing = error.message
|
||||
rescue ::ActiveRecord::ActiveRecordError => e
|
||||
@missing = e.message
|
||||
false
|
||||
end
|
||||
|
||||
|
@ -1303,8 +1301,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def join_table_matcher
|
||||
@join_table_matcher ||=
|
||||
AssociationMatchers::JoinTableMatcher.new(self, reflector)
|
||||
@_join_table_matcher ||= AssociationMatchers::JoinTableMatcher.new(self, reflector)
|
||||
end
|
||||
|
||||
def class_exists?
|
||||
|
@ -1339,7 +1336,7 @@ module Shoulda
|
|||
else
|
||||
@missing =
|
||||
"#{name} should have index_errors set to " +
|
||||
"#{options[:index_errors]}"
|
||||
options[:index_errors].to_s
|
||||
false
|
||||
end
|
||||
end
|
||||
|
@ -1410,7 +1407,8 @@ module Shoulda
|
|||
end
|
||||
|
||||
def foreign_key_reflection
|
||||
if [:has_one, :has_many].include?(macro) && reflection.options.include?(:inverse_of) && reflection.options[:inverse_of] != false
|
||||
if [:has_one, :has_many].include?(macro) && reflection.options.include?(:inverse_of) && \
|
||||
reflection.options[:inverse_of] != false
|
||||
associated_class.reflect_on_association(reflection.options[:inverse_of])
|
||||
else
|
||||
reflection
|
||||
|
|
|
@ -32,7 +32,7 @@ module Shoulda
|
|||
attr_accessor :subject, :counter_cache, :name
|
||||
|
||||
def option_verifier
|
||||
@option_verifier ||= OptionVerifier.new(subject)
|
||||
@_option_verifier ||= OptionVerifier.new(subject)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,7 +34,7 @@ module Shoulda
|
|||
private
|
||||
|
||||
def option_verifier
|
||||
@option_verifier ||= OptionVerifier.new(subject)
|
||||
@_option_verifier ||= OptionVerifier.new(subject)
|
||||
end
|
||||
|
||||
def option_matches?
|
||||
|
@ -43,8 +43,8 @@ module Shoulda
|
|||
|
||||
def option_type
|
||||
case dependent
|
||||
when true, false then :boolean
|
||||
else :string
|
||||
when true, false then :boolean
|
||||
else :string
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ module Shoulda
|
|||
attr_accessor :subject, :inverse_of, :name
|
||||
|
||||
def option_verifier
|
||||
@option_verifier ||= OptionVerifier.new(subject)
|
||||
@_option_verifier ||= OptionVerifier.new(subject)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ module Shoulda
|
|||
@reflector = reflector
|
||||
end
|
||||
|
||||
def matches?(subject)
|
||||
def matches?(_subject)
|
||||
join_table_option_correct? &&
|
||||
join_table_exists? &&
|
||||
join_table_has_correct_columns?
|
||||
|
@ -64,8 +64,8 @@ module Shoulda
|
|||
delegate :foreign_key, :association_foreign_key, to: :reflector
|
||||
|
||||
def missing_columns
|
||||
@missing_columns ||= expected_join_table_columns.select do |key|
|
||||
!actual_join_table_columns.include?(key.to_s)
|
||||
@_missing_columns ||= expected_join_table_columns.reject do |key|
|
||||
actual_join_table_columns.include?(key.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -25,13 +25,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def join_table_name
|
||||
join_table_name =
|
||||
if has_and_belongs_to_many_name_table_name
|
||||
has_and_belongs_to_many_name_table_name
|
||||
else
|
||||
reflection.join_table
|
||||
end
|
||||
|
||||
join_table_name = has_and_belongs_to_many_name_table_name || reflection.join_table
|
||||
join_table_name.to_s
|
||||
end
|
||||
|
||||
|
@ -82,9 +76,7 @@ module Shoulda
|
|||
private
|
||||
|
||||
def has_and_belongs_to_many_name_table_name
|
||||
if has_and_belongs_to_many_reflection
|
||||
has_and_belongs_to_many_reflection.table_name
|
||||
end
|
||||
has_and_belongs_to_many_reflection&.table_name
|
||||
end
|
||||
|
||||
def has_and_belongs_to_many_reflection
|
||||
|
|
|
@ -31,7 +31,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def reflection
|
||||
@reflection ||= reflect_on_association(name)
|
||||
@_reflection ||= reflect_on_association(name)
|
||||
end
|
||||
|
||||
def reflect_on_association(name)
|
||||
|
@ -48,9 +48,9 @@ module Shoulda
|
|||
|
||||
def build_relation_with_clause(name, value)
|
||||
case name
|
||||
when :conditions then associated_class.where(value)
|
||||
when :order then associated_class.order(value)
|
||||
else raise ArgumentError, "Unknown clause '#{name}'"
|
||||
when :conditions then associated_class.where(value)
|
||||
when :order then associated_class.order(value)
|
||||
else raise ArgumentError, "Unknown clause '#{name}'"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ module Shoulda
|
|||
class OptionVerifier
|
||||
delegate :reflection, to: :reflector
|
||||
|
||||
RELATION_OPTIONS = [:conditions, :order]
|
||||
RELATION_OPTIONS = [:conditions, :order].freeze
|
||||
|
||||
def initialize(reflector)
|
||||
@reflector = reflector
|
||||
|
|
|
@ -32,7 +32,7 @@ module Shoulda
|
|||
attr_accessor :subject, :order, :name
|
||||
|
||||
def option_verifier
|
||||
@option_verifier ||= OptionVerifier.new(subject)
|
||||
@_option_verifier ||= OptionVerifier.new(subject)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ module Shoulda
|
|||
attr_accessor :subject, :source, :name
|
||||
|
||||
def option_verifier
|
||||
@option_verifier ||= OptionVerifier.new(subject)
|
||||
@_option_verifier ||= OptionVerifier.new(subject)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def through_reflection
|
||||
@through_reflection ||= subject.reflect_on_association(through)
|
||||
@_through_reflection ||= subject.reflect_on_association(through)
|
||||
end
|
||||
|
||||
def through_association_correct?
|
||||
|
@ -54,7 +54,7 @@ module Shoulda
|
|||
attr_accessor :through, :name, :subject
|
||||
|
||||
def option_verifier
|
||||
@option_verifier ||= OptionVerifier.new(subject)
|
||||
@_option_verifier ||= OptionVerifier.new(subject)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -134,10 +134,8 @@ Did not expect #{expectation}, but it does.
|
|||
|
||||
def attachments_association_name
|
||||
case macro
|
||||
when :one then
|
||||
"#{name}_attachment"
|
||||
when :many then
|
||||
"#{name}_attachments"
|
||||
when :one then "#{name}_attachment"
|
||||
when :many then "#{name}_attachments"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -163,10 +161,8 @@ Did not expect #{expectation}, but it does.
|
|||
|
||||
def blobs_association_name
|
||||
case macro
|
||||
when :one then
|
||||
"#{name}_blob"
|
||||
when :many then
|
||||
"#{name}_blobs"
|
||||
when :one then "#{name}_blob"
|
||||
when :many then "#{name}_blobs"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -229,11 +229,11 @@ module Shoulda
|
|||
true
|
||||
else
|
||||
@missing = "#{model_class} has a db column named #{@column} "
|
||||
if @options[:primary]
|
||||
@missing << 'that is not primary, but should be'
|
||||
else
|
||||
@missing << 'that is primary, but should not be'
|
||||
end
|
||||
@missing << if @options[:primary]
|
||||
'that is not primary, but should be'
|
||||
else
|
||||
'that is primary, but should not be'
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,15 +39,15 @@ module Shoulda
|
|||
check_column_exists!
|
||||
check_implicit_order_column_matches!
|
||||
true
|
||||
rescue SecondaryCheckFailedError => error
|
||||
rescue SecondaryCheckFailedError => e
|
||||
@failure_message = Shoulda::Matchers.word_wrap(
|
||||
"Expected #{model.name} to #{expectation}, " +
|
||||
"but that could not be proved: #{error.message}.",
|
||||
"but that could not be proved: #{e.message}.",
|
||||
)
|
||||
false
|
||||
rescue PrimaryCheckFailedError => error
|
||||
rescue PrimaryCheckFailedError => e
|
||||
@failure_message = Shoulda::Matchers.word_wrap(
|
||||
"Expected #{model.name} to #{expectation}, but #{error.message}.",
|
||||
"Expected #{model.name} to #{expectation}, but #{e.message}.",
|
||||
)
|
||||
false
|
||||
end
|
||||
|
|
|
@ -38,14 +38,14 @@ module Shoulda
|
|||
@failure_message_when_negated = "Did not expect #{@attribute} to be read-only"
|
||||
true
|
||||
else
|
||||
if readonly_attributes.empty?
|
||||
@failure_message = "#{class_name} attribute #{@attribute} " <<
|
||||
'is not read-only'
|
||||
else
|
||||
@failure_message = "#{class_name} is making " <<
|
||||
"#{readonly_attributes.to_a.to_sentence} " <<
|
||||
"read-only, but not #{@attribute}."
|
||||
end
|
||||
@failure_message = if readonly_attributes.empty?
|
||||
"#{class_name} attribute #{@attribute} " <<
|
||||
'is not read-only'
|
||||
else
|
||||
"#{class_name} is making " <<
|
||||
"#{readonly_attributes.to_a.to_sentence} " <<
|
||||
"read-only, but not #{@attribute}."
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
|
@ -57,7 +57,7 @@ module Shoulda
|
|||
private
|
||||
|
||||
def readonly_attributes
|
||||
@readonly_attributes ||= (@subject.class.readonly_attributes || [])
|
||||
@_readonly_attributes ||= (@subject.class.readonly_attributes || [])
|
||||
end
|
||||
|
||||
def class_name
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require 'thread'
|
||||
|
||||
module Shoulda
|
||||
module Matchers
|
||||
module ActiveRecord
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require 'thread'
|
||||
|
||||
module Shoulda
|
||||
module Matchers
|
||||
module ActiveRecord
|
||||
|
|
|
@ -413,11 +413,11 @@ module Shoulda
|
|||
else
|
||||
@failure_reason = 'Expected the validation '
|
||||
|
||||
if expected_scopes.empty?
|
||||
@failure_reason << 'not to be scoped to anything, '
|
||||
else
|
||||
@failure_reason << "to be scoped to #{inspected_expected_scopes}, "
|
||||
end
|
||||
@failure_reason << if expected_scopes.empty?
|
||||
'not to be scoped to anything, '
|
||||
else
|
||||
"to be scoped to #{inspected_expected_scopes}, "
|
||||
end
|
||||
|
||||
if actual_sets_of_scopes.any?
|
||||
@failure_reason << 'but it was scoped to '
|
||||
|
@ -534,20 +534,15 @@ module Shoulda
|
|||
|
||||
def find_existing_record
|
||||
record = model.first
|
||||
|
||||
if record.present?
|
||||
record
|
||||
else
|
||||
nil
|
||||
end
|
||||
record.presence
|
||||
end
|
||||
|
||||
def create_existing_record
|
||||
@given_record.tap do |existing_record|
|
||||
existing_record.save(validate: false)
|
||||
end
|
||||
rescue ::ActiveRecord::StatementInvalid => error
|
||||
raise ExistingRecordInvalid.create(underlying_exception: error)
|
||||
rescue ::ActiveRecord::StatementInvalid => e
|
||||
raise ExistingRecordInvalid.create(underlying_exception: e)
|
||||
end
|
||||
|
||||
def update_existing_record!(value)
|
||||
|
@ -625,11 +620,11 @@ module Shoulda
|
|||
|
||||
reason << inspected_scopes.to_sentence
|
||||
|
||||
if inspected_scopes.many?
|
||||
reason << ' do not seem to be attributes'
|
||||
else
|
||||
reason << ' does not seem to be an attribute'
|
||||
end
|
||||
reason << if inspected_scopes.many?
|
||||
' do not seem to be attributes'
|
||||
else
|
||||
' does not seem to be an attribute'
|
||||
end
|
||||
|
||||
reason << " on #{model.name}."
|
||||
|
||||
|
@ -649,11 +644,11 @@ module Shoulda
|
|||
|
||||
reason << inspected_scopes.to_sentence
|
||||
|
||||
if inspected_scopes.many?
|
||||
reason << ' seem to be attributes'
|
||||
else
|
||||
reason << ' seems to be an attribute'
|
||||
end
|
||||
reason << if inspected_scopes.many?
|
||||
' seem to be attributes'
|
||||
else
|
||||
' seems to be an attribute'
|
||||
end
|
||||
|
||||
reason << " on #{model.name}."
|
||||
|
||||
|
@ -664,14 +659,14 @@ module Shoulda
|
|||
end
|
||||
|
||||
def scopes_present_on_model
|
||||
@_present_scopes ||= expected_scopes.select do |scope|
|
||||
@_scopes_present_on_model ||= expected_scopes.select do |scope|
|
||||
model.method_defined?("#{scope}=")
|
||||
end
|
||||
end
|
||||
|
||||
def scopes_missing_on_model
|
||||
@_missing_scopes ||= expected_scopes.select do |scope|
|
||||
!model.method_defined?("#{scope}=")
|
||||
@_scopes_missing_on_model ||= expected_scopes.reject do |scope|
|
||||
model.method_defined?("#{scope}=")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'forwardable'
|
||||
require 'logger'
|
||||
|
||||
module Shoulda
|
||||
module Matchers
|
||||
|
@ -20,7 +21,7 @@ module Shoulda
|
|||
|
||||
def debug(&block)
|
||||
if debugging_enabled?
|
||||
puts block.call
|
||||
Logger.new(STDOUT).debug block.call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,19 +18,19 @@ module Shoulda
|
|||
end
|
||||
|
||||
def activate
|
||||
doubles_by_method_name.each do |method_name, double|
|
||||
doubles_by_method_name.each do |_method_name, double|
|
||||
double.activate
|
||||
end
|
||||
end
|
||||
|
||||
def deactivate
|
||||
doubles_by_method_name.each do |method_name, double|
|
||||
doubles_by_method_name.each do |_method_name, double|
|
||||
double.deactivate
|
||||
end
|
||||
end
|
||||
|
||||
def calls_by_method_name
|
||||
doubles_by_method_name.reduce({}) do |hash, (method_name, double)|
|
||||
doubles_by_method_name.inject({}) do |hash, (method_name, double)|
|
||||
hash.merge method_name => double.calls.map(&:args)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,9 @@ module Shoulda
|
|||
# @private
|
||||
module DoubleImplementationRegistry
|
||||
class << self
|
||||
# rubocop:disable Style/MutableConstant
|
||||
REGISTRY = {}
|
||||
# rubocop:enable Style/MutableConstant
|
||||
|
||||
def find(type)
|
||||
find_class!(type).create
|
||||
|
|
|
@ -14,11 +14,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def returns(value = nil, &block)
|
||||
if block
|
||||
@implementation = block
|
||||
else
|
||||
@implementation = proc { value }
|
||||
end
|
||||
@implementation = block || proc { value }
|
||||
end
|
||||
|
||||
def call(call)
|
||||
|
|
|
@ -39,13 +39,13 @@ module Shoulda
|
|||
private
|
||||
|
||||
def activate
|
||||
double_collections_by_class.each do |klass, double_collection|
|
||||
double_collections_by_class.each do |_klass, double_collection|
|
||||
double_collection.activate
|
||||
end
|
||||
end
|
||||
|
||||
def deactivate
|
||||
double_collections_by_class.each do |klass, double_collection|
|
||||
double_collections_by_class.each do |_klass, double_collection|
|
||||
double_collection.deactivate
|
||||
end
|
||||
end
|
||||
|
|
|
@ -256,8 +256,8 @@ module Shoulda
|
|||
|
||||
def build_delegating_method_prefix(prefix)
|
||||
case prefix
|
||||
when true, nil then delegate_object_reader_method
|
||||
else prefix
|
||||
when true, nil then delegate_object_reader_method
|
||||
else prefix
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -398,11 +398,11 @@ module Shoulda
|
|||
true
|
||||
rescue Module::DelegationError
|
||||
false
|
||||
rescue NoMethodError => error
|
||||
if error.message =~ /undefined method `#{delegate_method}' for nil:NilClass/
|
||||
rescue NoMethodError => e
|
||||
if e.message =~ /undefined method `#{delegate_method}' for nil:NilClass/
|
||||
false
|
||||
else
|
||||
raise error
|
||||
raise e
|
||||
end
|
||||
end
|
||||
else
|
||||
|
@ -445,7 +445,7 @@ module Shoulda
|
|||
string << "\n\n"
|
||||
calls_on_delegate_object.each_with_index do |call, i|
|
||||
name = call.method_name
|
||||
args = call.args.map { |arg| arg.inspect }.join(', ')
|
||||
args = call.args.map(&:inspect).join(', ')
|
||||
string << "#{i + 1}) #{name}(#{args})\n"
|
||||
end
|
||||
else
|
||||
|
|
|
@ -60,7 +60,7 @@ EOT
|
|||
end
|
||||
|
||||
def no_test_frameworks_added?
|
||||
@test_frameworks.empty? || !@test_frameworks.any?(&:present?)
|
||||
@test_frameworks.empty? || @test_frameworks.none?(&:present?)
|
||||
end
|
||||
|
||||
def no_libraries_added?
|
||||
|
|
|
@ -13,9 +13,8 @@ module Shoulda
|
|||
test_framework.include(matchers_module, type: :controller)
|
||||
|
||||
include_into(::ActionController::TestCase, matchers_module) do
|
||||
def subject
|
||||
@controller
|
||||
end
|
||||
subject = -> { @controller }
|
||||
subject.call
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ module Shoulda
|
|||
:active_record,
|
||||
:action_controller,
|
||||
:routing,
|
||||
]
|
||||
].freeze
|
||||
|
||||
def integrate_with(test_framework)
|
||||
Shoulda::Matchers.assertion_exception_class =
|
||||
|
|
|
@ -8,7 +8,7 @@ module Shoulda
|
|||
|
||||
def validate!; end
|
||||
|
||||
def include(*modules, **options)
|
||||
def include(*modules, **_options)
|
||||
test_case_class.include(*modules)
|
||||
end
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ module Shoulda
|
|||
|
||||
def validate!; end
|
||||
|
||||
def include(*modules, **options)
|
||||
def include(*modules, **_options)
|
||||
test_case_class.class_eval do
|
||||
include(*modules)
|
||||
extend(*modules)
|
||||
|
|
|
@ -9,7 +9,7 @@ module Shoulda
|
|||
|
||||
def validate!; end
|
||||
|
||||
def include(*modules, **options)
|
||||
def include(*modules, **_options)
|
||||
test_case_class.class_eval do
|
||||
include(*modules)
|
||||
extend(*modules)
|
||||
|
|
|
@ -8,7 +8,7 @@ module Shoulda
|
|||
|
||||
def validate!; end
|
||||
|
||||
def include(*modules, **options)
|
||||
def include(*modules, **_options)
|
||||
test_case_class.class_eval do
|
||||
include(*modules)
|
||||
extend(*modules)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Shoulda
|
||||
module Matchers
|
||||
# @private
|
||||
module RailsShim
|
||||
module RailsShim # rubocop:disable Metrics/ModuleLength
|
||||
class << self
|
||||
def action_pack_gte_5?
|
||||
Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version)
|
||||
|
|
|
@ -41,7 +41,7 @@ module Shoulda
|
|||
|
||||
# @private
|
||||
class Text < ::String
|
||||
LIST_ITEM_REGEXP = /\A((?:[a-z0-9]+(?:\)|\.)|\*) )/
|
||||
LIST_ITEM_REGEXP = /\A((?:[a-z0-9]+(?:\)|\.)|\*) )/.freeze
|
||||
|
||||
def indented?
|
||||
self =~ /\A[ ]+/
|
||||
|
@ -88,7 +88,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def combine_list_item_lines(lines)
|
||||
lines.reduce([]) do |combined_lines, line|
|
||||
lines.inject([]) do |combined_lines, line|
|
||||
if line.list_item?
|
||||
combined_lines << line
|
||||
else
|
||||
|
@ -114,7 +114,7 @@ module Shoulda
|
|||
|
||||
# @private
|
||||
class Line
|
||||
OFFSETS = { left: -1, right: +1 }
|
||||
OFFSETS = { left: -1, right: +1 }.freeze
|
||||
|
||||
def initialize(line, indent: 0)
|
||||
@indent = indent
|
||||
|
@ -169,7 +169,7 @@ module Shoulda
|
|||
end
|
||||
end
|
||||
|
||||
def wrap_line(line, direction: :left)
|
||||
def wrap_line(line, _direction: :left)
|
||||
index = nil
|
||||
|
||||
if line.length > Shoulda::Matchers::WordWrap::TERMINAL_WIDTH
|
||||
|
|
|
@ -18,7 +18,9 @@ Gem::Specification.new do |s|
|
|||
s.homepage = 'https://matchers.shoulda.io/'
|
||||
s.summary = 'Simple one-liner tests for common Rails functionality'
|
||||
s.license = 'MIT'
|
||||
s.description = 'Shoulda Matchers provides RSpec- and Minitest-compatible one-liners to test common Rails functionality that, if written by hand, would be much longer, more complex, and error-prone.'
|
||||
s.description = 'Shoulda Matchers provides RSpec- and Minitest-compatible one-liners to test
|
||||
common Rails functionality that, if written by hand, would be much longer, more complex,
|
||||
and error-prone.'
|
||||
s.metadata = {
|
||||
'bug_tracker_uri' => 'https://github.com/thoughtbot/shoulda-matchers/issues',
|
||||
'changelog_uri' => 'https://github.com/thoughtbot/shoulda-matchers/blob/master/CHANGELOG.md',
|
||||
|
|
|
@ -99,11 +99,11 @@ module AcceptanceTests
|
|||
end
|
||||
|
||||
if integrates_with_rspec?(test_framework)
|
||||
if bundle.includes?('rspec-rails')
|
||||
files << 'spec/rails_helper.rb'
|
||||
else
|
||||
files << 'spec/spec_helper.rb'
|
||||
end
|
||||
files << if bundle.includes?('rspec-rails')
|
||||
'spec/rails_helper.rb'
|
||||
else
|
||||
'spec/spec_helper.rb'
|
||||
end
|
||||
end
|
||||
|
||||
files
|
||||
|
@ -118,7 +118,7 @@ module AcceptanceTests
|
|||
test_framework == :rspec
|
||||
end
|
||||
|
||||
def integrates_with_rspec_rails_3_x?(test_framework, libraries)
|
||||
def integrates_with_rspec_rails_3_x?(_test_framework, libraries)
|
||||
integrates_with_rails?(libraries) && rspec_rails_version >= 3
|
||||
end
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ module AcceptanceTests
|
|||
|
||||
def n_unit_test_case_superclass
|
||||
case default_test_framework
|
||||
when :test_unit then 'Test::Unit::TestCase'
|
||||
when :minitest_4 then 'MiniTest::Unit::TestCase'
|
||||
else 'Minitest::Test'
|
||||
when :test_unit then 'Test::Unit::TestCase'
|
||||
when :minitest_4 then 'MiniTest::Unit::TestCase'
|
||||
else 'Minitest::Test'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -58,11 +58,11 @@ module AcceptanceTests
|
|||
|
||||
def create_rails_application
|
||||
fs.clean
|
||||
if rails_version =~ '~> 6.0'
|
||||
command = "bundle exec rails new #{fs.project_directory} --skip-bundle --skip-javascript --no-rc"
|
||||
else
|
||||
command = "bundle exec rails new #{fs.project_directory} --skip-bundle --no-rc"
|
||||
end
|
||||
command = if rails_version =~ '~> 6.0'
|
||||
"bundle exec rails new #{fs.project_directory} --skip-bundle --skip-javascript --no-rc"
|
||||
else
|
||||
"bundle exec rails new #{fs.project_directory} --skip-bundle --no-rc"
|
||||
end
|
||||
|
||||
run_command!(command) do |runner|
|
||||
runner.directory = nil
|
||||
|
|
|
@ -24,11 +24,11 @@ module AcceptanceTests
|
|||
message = "Expected output to indicate that #{some_tests_were_run}.\n" +
|
||||
"Expected output: #{expected_output}\n"
|
||||
|
||||
if actual_output.empty?
|
||||
message << 'Actual output: (empty)'
|
||||
else
|
||||
message << "Actual output:\n#{actual_output}"
|
||||
end
|
||||
message << if actual_output.empty?
|
||||
'Actual output: (empty)'
|
||||
else
|
||||
"Actual output:\n#{actual_output}"
|
||||
end
|
||||
|
||||
message
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module Tests
|
|||
@fs = Filesystem.new
|
||||
end
|
||||
|
||||
def updating(&block)
|
||||
def updating(&_block)
|
||||
if already_updating?
|
||||
yield self
|
||||
return
|
||||
|
|
|
@ -57,9 +57,7 @@ module Tests
|
|||
end
|
||||
|
||||
def formatted_command
|
||||
[formatted_env, Shellwords.join(command)].
|
||||
select { |value| !value.empty? }.
|
||||
join(' ')
|
||||
[formatted_env, Shellwords.join(command)].reject(&:empty?).join(' ')
|
||||
end
|
||||
|
||||
def call
|
||||
|
@ -202,18 +200,16 @@ Output:
|
|||
end
|
||||
|
||||
def possibly_retrying
|
||||
begin
|
||||
@num_times_run += 1
|
||||
yield
|
||||
rescue => error
|
||||
debug { "#{error.class}: #{error.message}" }
|
||||
@num_times_run += 1
|
||||
yield
|
||||
rescue StandardError => e
|
||||
debug { "#{e.class}: #{e.message}" }
|
||||
|
||||
if @num_times_run < @retries
|
||||
sleep @num_times_run
|
||||
retry
|
||||
else
|
||||
raise error
|
||||
end
|
||||
if @num_times_run < @retries
|
||||
sleep @num_times_run
|
||||
retry
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ EOT
|
|||
end
|
||||
|
||||
def latest_appraisal
|
||||
available_appraisals.sort.last
|
||||
available_appraisals.max
|
||||
end
|
||||
|
||||
def available_appraisals
|
||||
|
|
|
@ -2,7 +2,7 @@ require_relative 'database_configuration'
|
|||
|
||||
module Tests
|
||||
class Database
|
||||
NAME = 'shoulda-matchers-test'
|
||||
NAME = 'shoulda-matchers-test'.freeze
|
||||
ADAPTER_NAME = ENV.fetch('DATABASE_ADAPTER', 'sqlite3').to_sym
|
||||
|
||||
include Singleton
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'delegate'
|
|||
|
||||
module Tests
|
||||
class DatabaseConfiguration < SimpleDelegator
|
||||
ENVIRONMENTS = %w(development test production)
|
||||
ENVIRONMENTS = %w(development test production).freeze
|
||||
|
||||
attr_reader :adapter_class
|
||||
|
||||
|
|
|
@ -63,9 +63,9 @@ module Tests
|
|||
wrap(path).dirname.mkpath
|
||||
end
|
||||
|
||||
def append_to_file(path, content, options = {})
|
||||
def append_to_file(path, content, _options = {})
|
||||
create_parents_of(path)
|
||||
open(path, 'a') { |f| f.puts(content + "\n") }
|
||||
File.open(path, 'a') { |f| f.puts(content + "\n") }
|
||||
end
|
||||
|
||||
def remove_from_file(path, pattern)
|
||||
|
|
|
@ -38,8 +38,8 @@ module Tests
|
|||
|
||||
private
|
||||
|
||||
def compare?(op, other_version)
|
||||
Gem::Requirement.new("#{op} #{other_version}").satisfied_by?(version)
|
||||
def compare?(operator, other_version)
|
||||
Gem::Requirement.new("#{operator} #{other_version}").satisfied_by?(version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ module UnitTests
|
|||
DEFAULT_COLUMN_OPTIONS = {
|
||||
null: false,
|
||||
array: false,
|
||||
}
|
||||
}.freeze
|
||||
|
||||
def initialize(args)
|
||||
@args = args
|
||||
|
|
|
@ -9,14 +9,14 @@ module Kernel
|
|||
def capture(stream)
|
||||
stream = stream.to_s
|
||||
captured_stream = Tempfile.new(stream)
|
||||
stream_io = eval("$#{stream}")
|
||||
stream_io = eval("$#{stream}", binding, __FILE__, __LINE__) # rubocop:disable Security/Eval
|
||||
origin_stream = stream_io.dup
|
||||
stream_io.reopen(captured_stream)
|
||||
|
||||
yield
|
||||
|
||||
stream_io.rewind
|
||||
return captured_stream.read
|
||||
captured_stream.read
|
||||
ensure
|
||||
captured_stream.unlink
|
||||
stream_io.reopen(origin_stream)
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'forwardable'
|
|||
module UnitTests
|
||||
module CreateModelArguments
|
||||
class Basic
|
||||
DEFAULT_MODEL_NAME = 'Example'
|
||||
DEFAULT_MODEL_NAME = 'Example'.freeze
|
||||
DEFAULT_ATTRIBUTE_NAME = :attr
|
||||
DEFAULT_COLUMN_TYPE = :string
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ module UnitTests
|
|||
end
|
||||
|
||||
def columns
|
||||
attributes.reduce({}) do |options, attribute|
|
||||
attributes.inject({}) do |options, attribute|
|
||||
options.merge(
|
||||
attribute.name => {
|
||||
type: attribute.column_type,
|
||||
|
@ -31,7 +31,7 @@ module UnitTests
|
|||
end
|
||||
|
||||
def attribute_default_values_by_name
|
||||
attributes.reduce({}) do |values, attribute|
|
||||
attributes.inject({}) do |values, attribute|
|
||||
values.merge(attribute.name => attribute.default_value)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ module UnitTests
|
|||
|
||||
remove_defined_module(module_name)
|
||||
|
||||
eval <<-RUBY
|
||||
eval <<-RUBY, binding, __FILE__, __LINE__ + 1 # rubocop:disable Security/Eval
|
||||
module #{namespace}::#{name_without_namespace}
|
||||
end
|
||||
RUBY
|
||||
|
@ -49,7 +49,7 @@ module UnitTests
|
|||
|
||||
remove_defined_module(class_name)
|
||||
|
||||
eval <<-RUBY
|
||||
eval <<-RUBY, binding, __FILE__, __LINE__ + 1 # rubocop:disable Security/Eval
|
||||
class #{namespace}::#{name_without_namespace} < ::#{parent_class}
|
||||
end
|
||||
RUBY
|
||||
|
|
|
@ -4,7 +4,7 @@ module UnitTests
|
|||
example_group.include(self)
|
||||
end
|
||||
|
||||
def define_mailer(name, paths, &block)
|
||||
def define_mailer(name, _paths, &block)
|
||||
class_name = name.to_s.pluralize.classify
|
||||
define_class(class_name, ActionMailer::Base, &block)
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ module UnitTests
|
|||
connection.create_table(table_name, options, &block)
|
||||
created_tables << table_name
|
||||
connection
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
||||
raise e
|
||||
end
|
||||
|
|
|
@ -12,11 +12,11 @@ module UnitTests
|
|||
|
||||
begin
|
||||
block.call
|
||||
rescue RSpec::Expectations::ExpectationNotMetError => ex
|
||||
@actual = ex.message
|
||||
rescue RSpec::Expectations::ExpectationNotMetError => e
|
||||
@actual = e.message
|
||||
end
|
||||
|
||||
@actual && @actual.include?(expected)
|
||||
@actual&.include?(expected)
|
||||
end
|
||||
|
||||
def failure_message
|
||||
|
|
|
@ -19,8 +19,8 @@ module UnitTests
|
|||
|
||||
begin
|
||||
block.call
|
||||
rescue RSpec::Expectations::ExpectationNotMetError => ex
|
||||
@actual = ex.message
|
||||
rescue RSpec::Expectations::ExpectationNotMetError => e
|
||||
@actual = e.message
|
||||
end
|
||||
|
||||
@actual && @actual == expected.sub(/\n\z/, '')
|
||||
|
|
|
@ -104,7 +104,7 @@ module UnitTests
|
|||
end
|
||||
|
||||
def inspect
|
||||
middle = '%s:0x%014x%s' % [
|
||||
middle = '%s:0x%014x%s' % [ # rubocop:disable Style/FormatStringToken
|
||||
self.class,
|
||||
object_id * 2,
|
||||
' ' + inspected_attributes.join(' '),
|
||||
|
|
|
@ -19,7 +19,7 @@ module UnitTests
|
|||
private
|
||||
|
||||
def model
|
||||
@_model ||= super.tap do |model|
|
||||
@_model ||= super.tap do |_model|
|
||||
stub_validation_messages
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,7 +64,7 @@ module UnitTests
|
|||
|
||||
define_method(_context[:validation_method_name]) do
|
||||
if self[_context[:attribute_to_validate]] != _context[:valid_value]
|
||||
self.errors.add(_context[:attribute_that_receives_error], _context[:message])
|
||||
errors.add(_context[:attribute_that_receives_error], _context[:message])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -88,11 +88,11 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
|||
|
||||
context 'when operating on the entire params hash' do
|
||||
include_context 'basic tests' do
|
||||
def permit_with_conditional_slice_of_params(permit, options = {})
|
||||
def permit_with_conditional_slice_of_params(permit, _options = {})
|
||||
permit
|
||||
end
|
||||
|
||||
def params_with_conditional_require(params, *filters)
|
||||
def params_with_conditional_require(params, *_filters)
|
||||
params
|
||||
end
|
||||
end
|
||||
|
@ -105,7 +105,7 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
|||
all_params: [:user],
|
||||
selected_param: :user
|
||||
)
|
||||
params = all_params.reduce({}) do |hash, param|
|
||||
params = all_params.inject({}) do |hash, param|
|
||||
hash.merge(param => { any: 'value' })
|
||||
end
|
||||
|
||||
|
@ -246,7 +246,7 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
|||
actual_user_params = params.require(:user)
|
||||
begin
|
||||
actual_user_params.permit(:name)
|
||||
rescue
|
||||
rescue StandardError
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher, type: :model do
|
|||
it 'truncates the description when long' do
|
||||
matcher = allow_value('A' * 10000).for(:baz)
|
||||
|
||||
expect(matcher.description).to eq "allow :baz to be ‹\"#{"A" * 499}...›"
|
||||
expect(matcher.description).to eq "allow :baz to be ‹\"#{'A' * 499}...›"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -304,8 +304,8 @@ errors instead:
|
|||
}
|
||||
|
||||
record = record_with_custom_validation(options) do
|
||||
if self.attr == 'xyz'
|
||||
self.errors.add :attr, :greater_than, count: 2
|
||||
if attr == 'xyz'
|
||||
errors.add :attr, :greater_than, count: 2
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -324,8 +324,8 @@ errors instead:
|
|||
}
|
||||
|
||||
record = record_with_custom_validation(options) do
|
||||
if self.attr == 'xyz'
|
||||
self.errors.add :attr, 'some other error'
|
||||
if attr == 'xyz'
|
||||
errors.add :attr, 'some other error'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -694,7 +694,7 @@ something else entirely.
|
|||
model = define_active_model_class 'Example', accessors: [:name] do
|
||||
validates_format_of :name, with: /another name/
|
||||
|
||||
def name=(value)
|
||||
def name=(_value)
|
||||
super('constant name')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,12 +68,8 @@ describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher, type: :model do
|
|||
def record_with_custom_validation
|
||||
define_model :example, attr: :string, attr2: :string do
|
||||
validate :custom_validation
|
||||
|
||||
def custom_validation
|
||||
if self[:attr] != 'good value'
|
||||
self.errors[:attr2] << 'some message'
|
||||
end
|
||||
end
|
||||
custom_validation = -> { errors[:attr2] << 'some message' if self[:attr] != 'good value' }
|
||||
custom_validation.call
|
||||
end.new
|
||||
end
|
||||
end
|
||||
|
|
|
@ -475,9 +475,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
|||
|
||||
if reserved_outside_value
|
||||
it 'raises an error when valid and given value is our test outside value' do
|
||||
# rubocop:disable Metrics/LineLength
|
||||
error_class = Shoulda::Matchers::ActiveModel::CouldNotDetermineValueOutsideOfArray
|
||||
# rubocop:enable Metrics/LineLength
|
||||
builder = build_object_allowing([reserved_outside_value])
|
||||
|
||||
expect { expect_to_match_on_values(builder, [reserved_outside_value]) }.
|
||||
|
@ -857,10 +855,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
|||
it 'raises a specific error' do
|
||||
valid_values = [nil]
|
||||
builder = build_object_allowing(valid_values)
|
||||
# rubocop:disable Metrics/LineLength
|
||||
error_class = Shoulda::Matchers::ActiveModel::NonNullableBooleanError
|
||||
# rubocop:enable Metrics/LineLength
|
||||
|
||||
expect {
|
||||
expect_to_match_in_array(builder, valid_values)
|
||||
}.to raise_error(error_class)
|
||||
|
|
|
@ -972,7 +972,7 @@ validation exception on failure, but this could not be proved.
|
|||
model = define_active_model_class :example, accessors: [:foo] do
|
||||
validates_presence_of :foo
|
||||
|
||||
def foo=(value)
|
||||
def foo=(_value)
|
||||
super([])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2132,7 +2132,7 @@ Expected Person to have a has_and_belongs_to_many association called relatives (
|
|||
end
|
||||
end
|
||||
|
||||
def having_and_belonging_to_many_relatives(options = {})
|
||||
def having_and_belonging_to_many_relatives(_options = {})
|
||||
define_model :relative
|
||||
define_model :people_relative, id: false, person_id: :integer,
|
||||
relative_id: :integer
|
||||
|
@ -2148,7 +2148,7 @@ Expected Person to have a has_and_belongs_to_many association called relatives (
|
|||
end
|
||||
end
|
||||
|
||||
def define_association_with_conditions(model, macro, name, conditions, other_options = {})
|
||||
def define_association_with_conditions(model, macro, name, conditions, _other_options = {})
|
||||
args = []
|
||||
options = {}
|
||||
if active_record_supports_relations?
|
||||
|
@ -2160,7 +2160,7 @@ Expected Person to have a has_and_belongs_to_many association called relatives (
|
|||
model.__send__(macro, name, *args)
|
||||
end
|
||||
|
||||
def define_association_with_order(model, macro, name, order, other_options={})
|
||||
def define_association_with_order(model, macro, name, order, _other_options = {})
|
||||
args = []
|
||||
options = {}
|
||||
if active_record_supports_relations?
|
||||
|
|
|
@ -7,8 +7,6 @@ describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher, type: :model do
|
|||
end
|
||||
|
||||
describe 'the matcher' do
|
||||
# rubocop:disable Layout/MultilineBlockLayout
|
||||
# rubocop:disable Layout/SpaceAroundBlockParameters
|
||||
shared_examples 'for when the matcher is qualified' do |
|
||||
index:,
|
||||
other_index:,
|
||||
|
@ -16,8 +14,6 @@ describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher, type: :model do
|
|||
qualifier_args:,
|
||||
columns: { index => :string }
|
||||
|
|
||||
# rubocop:enable Layout/MultilineBlockLayout
|
||||
# rubocop:enable Layout/SpaceAroundBlockParameters
|
||||
if unique
|
||||
index_type = 'unique'
|
||||
inverse_description = 'not unique'
|
||||
|
@ -359,15 +355,7 @@ does not.
|
|||
end
|
||||
|
||||
describe '#description' do
|
||||
# rubocop:disable Layout/MultilineBlockLayout
|
||||
# rubocop:disable Layout/SpaceAroundBlockParameters
|
||||
shared_examples 'for when the matcher is qualified' do |
|
||||
index:,
|
||||
index_type:,
|
||||
qualifier_args:
|
||||
|
|
||||
# rubocop:enable Layout/MultilineBlockLayout
|
||||
# rubocop:enable Layout/SpaceAroundBlockParameters
|
||||
shared_examples 'for when the matcher is qualified' do |index:, index_type:, qualifier_args:|
|
||||
it 'returns the correct description' do
|
||||
matcher = have_db_index(index).unique(*qualifier_args)
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ describe Shoulda::Matchers::ActiveRecord::HaveImplicitOrderColumnMatcher, type:
|
|||
columns: [:created_at],
|
||||
)
|
||||
|
||||
expect { have_implicit_order_column(:created_at) }
|
||||
.to match_against(record)
|
||||
.or_fail_with(<<~MESSAGE, wrap: true)
|
||||
expect { have_implicit_order_column(:created_at) }.
|
||||
to match_against(record).
|
||||
or_fail_with(<<~MESSAGE, wrap: true)
|
||||
Expected Employee not to have an implicit_order_column of
|
||||
:created_at, but it did.
|
||||
MESSAGE
|
||||
|
@ -30,9 +30,9 @@ describe Shoulda::Matchers::ActiveRecord::HaveImplicitOrderColumnMatcher, type:
|
|||
columns: [:created_at],
|
||||
)
|
||||
|
||||
expect { have_implicit_order_column('created_at') }
|
||||
.to match_against(record)
|
||||
.or_fail_with(<<~MESSAGE, wrap: true)
|
||||
expect { have_implicit_order_column('created_at') }.
|
||||
to match_against(record).
|
||||
or_fail_with(<<~MESSAGE, wrap: true)
|
||||
Expected Employee not to have an implicit_order_column of
|
||||
:created_at, but it did.
|
||||
MESSAGE
|
||||
|
@ -49,9 +49,9 @@ describe Shoulda::Matchers::ActiveRecord::HaveImplicitOrderColumnMatcher, type:
|
|||
columns: [:created_at, :email],
|
||||
)
|
||||
|
||||
expect { have_implicit_order_column(:email) }
|
||||
.not_to match_against(record)
|
||||
.and_fail_with(<<-MESSAGE, wrap: true)
|
||||
expect { have_implicit_order_column(:email) }.
|
||||
not_to match_against(record).
|
||||
and_fail_with(<<-MESSAGE, wrap: true)
|
||||
Expected Employee to have an implicit_order_column of :email,
|
||||
but it is :created_at.
|
||||
MESSAGE
|
||||
|
@ -66,9 +66,9 @@ describe Shoulda::Matchers::ActiveRecord::HaveImplicitOrderColumnMatcher, type:
|
|||
columns: [:created_at, :email],
|
||||
)
|
||||
|
||||
expect { have_implicit_order_column('email') }
|
||||
.not_to match_against(record)
|
||||
.and_fail_with(<<-MESSAGE, wrap: true)
|
||||
expect { have_implicit_order_column('email') }.
|
||||
not_to match_against(record).
|
||||
and_fail_with(<<-MESSAGE, wrap: true)
|
||||
Expected Employee to have an implicit_order_column of :email,
|
||||
but it is :created_at.
|
||||
MESSAGE
|
||||
|
@ -85,9 +85,9 @@ describe Shoulda::Matchers::ActiveRecord::HaveImplicitOrderColumnMatcher, type:
|
|||
columns: [:created_at],
|
||||
)
|
||||
|
||||
expect { have_implicit_order_column(:created_at) }
|
||||
.not_to match_against(record)
|
||||
.and_fail_with(<<-MESSAGE, wrap: true)
|
||||
expect { have_implicit_order_column(:created_at) }.
|
||||
not_to match_against(record).
|
||||
and_fail_with(<<-MESSAGE, wrap: true)
|
||||
Expected Employee to have an implicit_order_column of
|
||||
:created_at, but implicit_order_column is not set.
|
||||
MESSAGE
|
||||
|
@ -101,9 +101,9 @@ describe Shoulda::Matchers::ActiveRecord::HaveImplicitOrderColumnMatcher, type:
|
|||
columns: [:created_at],
|
||||
)
|
||||
|
||||
expect { have_implicit_order_column('created_at') }
|
||||
.not_to match_against(record)
|
||||
.and_fail_with(<<-MESSAGE, wrap: true)
|
||||
expect { have_implicit_order_column('created_at') }.
|
||||
not_to match_against(record).
|
||||
and_fail_with(<<-MESSAGE, wrap: true)
|
||||
Expected Employee to have an implicit_order_column of
|
||||
:created_at, but implicit_order_column is not set.
|
||||
MESSAGE
|
||||
|
@ -117,9 +117,9 @@ describe Shoulda::Matchers::ActiveRecord::HaveImplicitOrderColumnMatcher, type:
|
|||
it 'does not match, producing an appropriate message' do
|
||||
record = record_without_any_columns(class_name: 'Employee')
|
||||
|
||||
expect { have_implicit_order_column(:whatever) }
|
||||
.not_to match_against(record)
|
||||
.and_fail_with(<<-MESSAGE, wrap: true)
|
||||
expect { have_implicit_order_column(:whatever) }.
|
||||
not_to match_against(record).
|
||||
and_fail_with(<<-MESSAGE, wrap: true)
|
||||
Expected Employee to have an implicit_order_column of :whatever,
|
||||
but that could not be proved: The :employees table does not have a
|
||||
:whatever column.
|
||||
|
@ -131,9 +131,9 @@ describe Shoulda::Matchers::ActiveRecord::HaveImplicitOrderColumnMatcher, type:
|
|||
it 'does not match, producing an appropriate message' do
|
||||
record = record_without_any_columns(class_name: 'Employee')
|
||||
|
||||
expect { have_implicit_order_column('whatever') }
|
||||
.not_to match_against(record)
|
||||
.and_fail_with(<<-MESSAGE, wrap: true)
|
||||
expect { have_implicit_order_column('whatever') }.
|
||||
not_to match_against(record).
|
||||
and_fail_with(<<-MESSAGE, wrap: true)
|
||||
Expected Employee to have an implicit_order_column of :whatever,
|
||||
but that could not be proved: The :employees table does not have a
|
||||
:whatever column.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require 'unit_spec_helper'
|
||||
|
||||
# rubocop:disable Metrics/BlockLength
|
||||
describe Shoulda::Matchers::ActiveRecord::HaveSecureTokenMatcher,
|
||||
type: :model do
|
||||
if active_record_supports_has_secure_token?
|
||||
|
|
|
@ -35,7 +35,7 @@ describe Shoulda::Matchers::ActiveRecord::SerializeMatcher, type: :model do
|
|||
end
|
||||
|
||||
def unserialized_model
|
||||
@model ||= define_model(:example, attr: :string).new
|
||||
@_unserialized_model ||= define_model(:example, attr: :string).new
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -79,8 +79,8 @@ describe Shoulda::Matchers::ActiveRecord::SerializeMatcher, type: :model do
|
|||
|
||||
def define_serializer(name)
|
||||
define_class(name) do
|
||||
def load(*); end
|
||||
def dump(*); end
|
||||
def load(*); end # rubocop:disable Lint/NestedMethodDefinition
|
||||
def dump(*); end # rubocop:disable Lint/NestedMethodDefinition
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1159,13 +1159,9 @@ long as it is not nil, but this could not be proved.
|
|||
it 'accepts' do
|
||||
model = define_model_validating_uniqueness(
|
||||
validation_options: { allow_blank: true },
|
||||
additional_attributes: [{ name: :password_digest, type: :string }],
|
||||
) do |m|
|
||||
m.has_secure_password
|
||||
end
|
||||
|
||||
additional_attributes: [{ name: :password_digest, type: :string }], &:has_secure_password
|
||||
)
|
||||
record = build_record_from(model, attribute_name => nil)
|
||||
|
||||
expect(record).to validate_uniqueness.allow_blank
|
||||
end
|
||||
end
|
||||
|
@ -1175,13 +1171,9 @@ long as it is not nil, but this could not be proved.
|
|||
model = define_model_validating_uniqueness(
|
||||
attribute_type: :string,
|
||||
validation_options: { allow_blank: true },
|
||||
additional_attributes: [{ name: :password_digest, type: :string }],
|
||||
) do |m|
|
||||
m.has_secure_password
|
||||
end
|
||||
|
||||
additional_attributes: [{ name: :password_digest, type: :string }], &:has_secure_password
|
||||
)
|
||||
record = build_record_from(model, attribute_name => '')
|
||||
|
||||
expect(record).to validate_uniqueness.allow_blank
|
||||
end
|
||||
end
|
||||
|
@ -1566,9 +1558,7 @@ this could not be proved.
|
|||
end
|
||||
|
||||
def create_record_from(model, extra_attributes = {})
|
||||
build_record_from(model, extra_attributes).tap do |record|
|
||||
record.save!
|
||||
end
|
||||
build_record_from(model, extra_attributes).tap(&:save!)
|
||||
end
|
||||
|
||||
def define_model_validating_uniqueness(options = {}, &block)
|
||||
|
@ -1605,7 +1595,7 @@ this could not be proved.
|
|||
end
|
||||
end
|
||||
|
||||
block.call(m) if block
|
||||
block&.call(m)
|
||||
end
|
||||
|
||||
model_attributes[model] = attributes
|
||||
|
@ -1621,9 +1611,7 @@ this could not be proved.
|
|||
:build_record_validating_uniqueness
|
||||
|
||||
def create_record_validating_uniqueness(options = {}, &block)
|
||||
build_record_validating_uniqueness(options, &block).tap do |record|
|
||||
record.save!
|
||||
end
|
||||
build_record_validating_uniqueness(options, &block).tap(&:save!)
|
||||
end
|
||||
alias_method :existing_record_validating_uniqueness,
|
||||
:create_record_validating_uniqueness
|
||||
|
|
|
@ -178,7 +178,7 @@ module Shoulda::Matchers::Doublespeak
|
|||
def create_class(methods = {})
|
||||
Class.new.tap do |klass|
|
||||
methods.each do |name, value|
|
||||
klass.__send__(:define_method, name) { |*args| value }
|
||||
klass.__send__(:define_method, name) { |*_args| value }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -250,7 +250,7 @@ module Shoulda::Matchers::Doublespeak
|
|||
def create_class(methods = {})
|
||||
Class.new.tap do |klass|
|
||||
methods.each do |name, value|
|
||||
klass.__send__(:define_method, name) { |*args| value }
|
||||
klass.__send__(:define_method, name) { |*_args| value }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,7 +41,9 @@ module Shoulda::Matchers::Doublespeak
|
|||
context 'if the implementation was set as a block' do
|
||||
it 'calls the block with the MethodCall object the implementation was called with' do
|
||||
double = build_double
|
||||
expected_object, expected_args, expected_block = :object, :args, :block
|
||||
expected_object = :object
|
||||
expected_args = :args
|
||||
expected_block = :block
|
||||
call = build_call(
|
||||
double: double,
|
||||
object: expected_object,
|
||||
|
|
|
@ -264,7 +264,7 @@ describe Shoulda::Matchers::Independent::DelegateMethodMatcher do
|
|||
define_class('Mailman')
|
||||
|
||||
define_class('PostOffice') do
|
||||
def deliver_mail(*args)
|
||||
def deliver_mail(*_args)
|
||||
mailman.deliver_mail('221B Baker St.', hastily: true)
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
desc 'Generate docs for a particular version'
|
||||
task :generate, [:version, :latest_version] => :setup do |t, args|
|
||||
task :generate, [:version, :latest_version] => :setup do |_t, args|
|
||||
unless args.version
|
||||
raise ArgumentError, 'Missing version'
|
||||
end
|
||||
|
@ -62,7 +62,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
desc 'Generate docs for a particular version and push them to GitHub'
|
||||
task :publish, [:version, :latest_version] => :setup do |t, args|
|
||||
task :publish, [:version, :latest_version] => :setup do |_t, args|
|
||||
unless args.version
|
||||
raise ArgumentError, 'Missing version'
|
||||
end
|
||||
|
@ -85,10 +85,10 @@ module Shoulda
|
|||
|
||||
class DocumentationPublisher
|
||||
CURRENT_VERSION = Shoulda::Matchers::VERSION
|
||||
GITHUB_USERNAME = 'thoughtbot'
|
||||
GITHUB_USERNAME = 'thoughtbot'.freeze
|
||||
# GITHUB_USERNAME = 'mcmire'
|
||||
GH_PAGES_DIR = ".#{GITHUB_USERNAME}-gh-pages"
|
||||
DOCS_DIR = "#{GH_PAGES_DIR}/docs"
|
||||
GH_PAGES_DIR = ".#{GITHUB_USERNAME}-gh-pages".freeze
|
||||
DOCS_DIR = "#{GH_PAGES_DIR}/docs".freeze
|
||||
|
||||
def self.current_version
|
||||
CURRENT_VERSION
|
||||
|
@ -130,7 +130,7 @@ module Shoulda
|
|||
end
|
||||
end
|
||||
|
||||
def publish_docs_for(version, options = {})
|
||||
def publish_docs_for(version, _options = {})
|
||||
message = build_commit_message(version)
|
||||
|
||||
within_gh_pages_dir do
|
||||
|
|
Loading…
Reference in New Issue