diff --git a/.rubocop.yml b/.rubocop.yml index b4d27918..ba591da4 100644 --- a/.rubocop.yml +++ b/.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: diff --git a/custom_plan.rb b/custom_plan.rb index 15587cce..a18e036d 100644 --- a/custom_plan.rb +++ b/custom_plan.rb @@ -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 diff --git a/doc_config/yard/templates/default/layout/html/setup.rb b/doc_config/yard/templates/default/layout/html/setup.rb index 11abe65b..774dd3af 100644 --- a/doc_config/yard/templates/default/layout/html/setup.rb +++ b/doc_config/yard/templates/default/layout/html/setup.rb @@ -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]) "
" + data + '
' @@ -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| diff --git a/lib/shoulda/matchers/action_controller/filter_param_matcher.rb b/lib/shoulda/matchers/action_controller/filter_param_matcher.rb index c8e06b1c..5e816515 100644 --- a/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +++ b/lib/shoulda/matchers/action_controller/filter_param_matcher.rb @@ -31,7 +31,7 @@ module Shoulda @key = key end - def matches?(controller) + def matches?(_controller) filters_key? end diff --git a/lib/shoulda/matchers/action_controller/permit_matcher.rb b/lib/shoulda/matchers/action_controller/permit_matcher.rb index 383f1602..61ffdec6 100644 --- a/lib/shoulda/matchers/action_controller/permit_matcher.rb +++ b/lib/shoulda/matchers/action_controller/permit_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb b/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb index c68ae67d..6f3d66db 100644 --- a/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +++ b/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/action_controller/render_template_matcher.rb b/lib/shoulda/matchers/action_controller/render_template_matcher.rb index c373e905..0a8446b1 100644 --- a/lib/shoulda/matchers/action_controller/render_template_matcher.rb +++ b/lib/shoulda/matchers/action_controller/render_template_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb b/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb index 358d210a..28aecd20 100644 --- a/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +++ b/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/action_controller/route_matcher.rb b/lib/shoulda/matchers/action_controller/route_matcher.rb index d18a08f4..43d50480 100644 --- a/lib/shoulda/matchers/action_controller/route_matcher.rb +++ b/lib/shoulda/matchers/action_controller/route_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/action_controller/route_params.rb b/lib/shoulda/matchers/action_controller/route_params.rb index 0837db5f..9761e160 100644 --- a/lib/shoulda/matchers/action_controller/route_params.rb +++ b/lib/shoulda/matchers/action_controller/route_params.rb @@ -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 diff --git a/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb b/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb index f004ebe2..795d82f9 100644 --- a/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +++ b/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb b/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb index 5757388a..ce209178 100644 --- a/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb @@ -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? diff --git a/lib/shoulda/matchers/active_model/allow_value_matcher.rb b/lib/shoulda/matchers/active_model/allow_value_matcher.rb index 20741dbf..f5d86368 100644 --- a/lib/shoulda/matchers/active_model/allow_value_matcher.rb +++ b/lib/shoulda/matchers/active_model/allow_value_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb b/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb index 5cc57f98..0f904276 100644 --- a/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +++ b/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb b/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb index 31302f02..517912a7 100644 --- a/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +++ b/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb @@ -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 diff --git a/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb index 037760f7..22d1bd68 100644 --- a/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb index aa91b50f..c14bc30a 100644 --- a/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb @@ -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 = < 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 diff --git a/lib/shoulda/matchers/active_record/association_matcher.rb b/lib/shoulda/matchers/active_record/association_matcher.rb index 185e4d33..fde79945 100644 --- a/lib/shoulda/matchers/active_record/association_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb index 6866e3b9..da8523f4 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb index cf41110f..f5ef0380 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb index ae9a5656..e27d247f 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb index 83fa1648..5a43baf4 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb b/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb index 4247f146..0526b8ea 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb b/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb index f1776639..7affc2e9 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb b/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb index 0f3c832d..f6f5dab6 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb index 08775955..3c18c092 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb index 7985b003..b109889e 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb index 0569394a..d5453464 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/have_attached_matcher.rb b/lib/shoulda/matchers/active_record/have_attached_matcher.rb index e3626357..9b6314da 100644 --- a/lib/shoulda/matchers/active_record/have_attached_matcher.rb +++ b/lib/shoulda/matchers/active_record/have_attached_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/have_db_column_matcher.rb b/lib/shoulda/matchers/active_record/have_db_column_matcher.rb index 76f955fa..a38b9df5 100644 --- a/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +++ b/lib/shoulda/matchers/active_record/have_db_column_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/have_implicit_order_column.rb b/lib/shoulda/matchers/active_record/have_implicit_order_column.rb index 34147087..984f575c 100644 --- a/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +++ b/lib/shoulda/matchers/active_record/have_implicit_order_column.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb b/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb index 7e13177d..d95f92d5 100644 --- a/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +++ b/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb b/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb index 20bd9755..1c2fae9e 100644 --- a/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +++ b/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb @@ -1,5 +1,3 @@ -require 'thread' - module Shoulda module Matchers module ActiveRecord diff --git a/lib/shoulda/matchers/active_record/uniqueness/test_models.rb b/lib/shoulda/matchers/active_record/uniqueness/test_models.rb index 2283af96..227559c7 100644 --- a/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +++ b/lib/shoulda/matchers/active_record/uniqueness/test_models.rb @@ -1,5 +1,3 @@ -require 'thread' - module Shoulda module Matchers module ActiveRecord diff --git a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb index 2b33ec7e..200bb0fb 100644 --- a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +++ b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/doublespeak.rb b/lib/shoulda/matchers/doublespeak.rb index e09b0082..9ce1534c 100644 --- a/lib/shoulda/matchers/doublespeak.rb +++ b/lib/shoulda/matchers/doublespeak.rb @@ -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 diff --git a/lib/shoulda/matchers/doublespeak/double_collection.rb b/lib/shoulda/matchers/doublespeak/double_collection.rb index 43d4f003..fb520f4c 100644 --- a/lib/shoulda/matchers/doublespeak/double_collection.rb +++ b/lib/shoulda/matchers/doublespeak/double_collection.rb @@ -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 diff --git a/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb b/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb index 71e43e1d..83de70e8 100644 --- a/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +++ b/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb @@ -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 diff --git a/lib/shoulda/matchers/doublespeak/stub_implementation.rb b/lib/shoulda/matchers/doublespeak/stub_implementation.rb index acb125d1..e39f48c2 100644 --- a/lib/shoulda/matchers/doublespeak/stub_implementation.rb +++ b/lib/shoulda/matchers/doublespeak/stub_implementation.rb @@ -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) diff --git a/lib/shoulda/matchers/doublespeak/world.rb b/lib/shoulda/matchers/doublespeak/world.rb index 3c046a3c..686d0e24 100644 --- a/lib/shoulda/matchers/doublespeak/world.rb +++ b/lib/shoulda/matchers/doublespeak/world.rb @@ -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 diff --git a/lib/shoulda/matchers/independent/delegate_method_matcher.rb b/lib/shoulda/matchers/independent/delegate_method_matcher.rb index 2983451e..9ef6648e 100644 --- a/lib/shoulda/matchers/independent/delegate_method_matcher.rb +++ b/lib/shoulda/matchers/independent/delegate_method_matcher.rb @@ -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 diff --git a/lib/shoulda/matchers/integrations/configuration.rb b/lib/shoulda/matchers/integrations/configuration.rb index 78f7953e..eea3583d 100644 --- a/lib/shoulda/matchers/integrations/configuration.rb +++ b/lib/shoulda/matchers/integrations/configuration.rb @@ -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? diff --git a/lib/shoulda/matchers/integrations/libraries/action_controller.rb b/lib/shoulda/matchers/integrations/libraries/action_controller.rb index 5d3a1fe4..afc94f7f 100644 --- a/lib/shoulda/matchers/integrations/libraries/action_controller.rb +++ b/lib/shoulda/matchers/integrations/libraries/action_controller.rb @@ -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 diff --git a/lib/shoulda/matchers/integrations/libraries/rails.rb b/lib/shoulda/matchers/integrations/libraries/rails.rb index 62eb9817..380c59d1 100644 --- a/lib/shoulda/matchers/integrations/libraries/rails.rb +++ b/lib/shoulda/matchers/integrations/libraries/rails.rb @@ -13,7 +13,7 @@ module Shoulda :active_record, :action_controller, :routing, - ] + ].freeze def integrate_with(test_framework) Shoulda::Matchers.assertion_exception_class = diff --git a/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb b/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb index 3d1c5e32..d4edea0c 100644 --- a/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +++ b/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb @@ -8,7 +8,7 @@ module Shoulda def validate!; end - def include(*modules, **options) + def include(*modules, **_options) test_case_class.include(*modules) end diff --git a/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb b/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb index a6b16ed8..1a86eb2a 100644 --- a/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +++ b/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb @@ -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) diff --git a/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb b/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb index 5375cc31..c2d525b3 100644 --- a/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +++ b/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb @@ -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) diff --git a/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb b/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb index 4dc04fc5..9ddd34fd 100644 --- a/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +++ b/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb @@ -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) diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb index ae36345c..8b3914b9 100644 --- a/lib/shoulda/matchers/rails_shim.rb +++ b/lib/shoulda/matchers/rails_shim.rb @@ -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) diff --git a/lib/shoulda/matchers/util/word_wrap.rb b/lib/shoulda/matchers/util/word_wrap.rb index 2b5d730f..51f2322c 100644 --- a/lib/shoulda/matchers/util/word_wrap.rb +++ b/lib/shoulda/matchers/util/word_wrap.rb @@ -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 diff --git a/shoulda-matchers.gemspec b/shoulda-matchers.gemspec index f61d7641..b5258d7d 100644 --- a/shoulda-matchers.gemspec +++ b/shoulda-matchers.gemspec @@ -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', diff --git a/spec/support/acceptance/adds_shoulda_matchers_to_project.rb b/spec/support/acceptance/adds_shoulda_matchers_to_project.rb index 4ed3bb49..8bcc4e76 100644 --- a/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +++ b/spec/support/acceptance/adds_shoulda_matchers_to_project.rb @@ -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 diff --git a/spec/support/acceptance/helpers/n_unit_helpers.rb b/spec/support/acceptance/helpers/n_unit_helpers.rb index 92d86f7b..5d1128df 100644 --- a/spec/support/acceptance/helpers/n_unit_helpers.rb +++ b/spec/support/acceptance/helpers/n_unit_helpers.rb @@ -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 diff --git a/spec/support/acceptance/helpers/step_helpers.rb b/spec/support/acceptance/helpers/step_helpers.rb index 35898eb4..0aa0dc7e 100644 --- a/spec/support/acceptance/helpers/step_helpers.rb +++ b/spec/support/acceptance/helpers/step_helpers.rb @@ -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 diff --git a/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb b/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb index 5f6e9097..770e3a40 100644 --- a/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +++ b/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb @@ -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 diff --git a/spec/support/tests/bundle.rb b/spec/support/tests/bundle.rb index 5042c910..4031b267 100644 --- a/spec/support/tests/bundle.rb +++ b/spec/support/tests/bundle.rb @@ -9,7 +9,7 @@ module Tests @fs = Filesystem.new end - def updating(&block) + def updating(&_block) if already_updating? yield self return diff --git a/spec/support/tests/command_runner.rb b/spec/support/tests/command_runner.rb index 4ac3b63d..7fffa53b 100644 --- a/spec/support/tests/command_runner.rb +++ b/spec/support/tests/command_runner.rb @@ -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 diff --git a/spec/support/tests/current_bundle.rb b/spec/support/tests/current_bundle.rb index f4d095d4..427ef607 100644 --- a/spec/support/tests/current_bundle.rb +++ b/spec/support/tests/current_bundle.rb @@ -29,7 +29,7 @@ EOT end def latest_appraisal - available_appraisals.sort.last + available_appraisals.max end def available_appraisals diff --git a/spec/support/tests/database.rb b/spec/support/tests/database.rb index 34061c3f..bd8bb71e 100644 --- a/spec/support/tests/database.rb +++ b/spec/support/tests/database.rb @@ -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 diff --git a/spec/support/tests/database_configuration.rb b/spec/support/tests/database_configuration.rb index fed22753..df7aa13a 100644 --- a/spec/support/tests/database_configuration.rb +++ b/spec/support/tests/database_configuration.rb @@ -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 diff --git a/spec/support/tests/filesystem.rb b/spec/support/tests/filesystem.rb index b269a5a1..8fe33d20 100644 --- a/spec/support/tests/filesystem.rb +++ b/spec/support/tests/filesystem.rb @@ -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) diff --git a/spec/support/tests/version.rb b/spec/support/tests/version.rb index 4a2a66e4..3859bac5 100644 --- a/spec/support/tests/version.rb +++ b/spec/support/tests/version.rb @@ -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 diff --git a/spec/support/unit/attribute.rb b/spec/support/unit/attribute.rb index 386e8843..f3e8ad49 100644 --- a/spec/support/unit/attribute.rb +++ b/spec/support/unit/attribute.rb @@ -4,7 +4,7 @@ module UnitTests DEFAULT_COLUMN_OPTIONS = { null: false, array: false, - } + }.freeze def initialize(args) @args = args diff --git a/spec/support/unit/capture.rb b/spec/support/unit/capture.rb index a5879954..1702042c 100644 --- a/spec/support/unit/capture.rb +++ b/spec/support/unit/capture.rb @@ -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) diff --git a/spec/support/unit/create_model_arguments/basic.rb b/spec/support/unit/create_model_arguments/basic.rb index dd4181fc..4e9714dd 100644 --- a/spec/support/unit/create_model_arguments/basic.rb +++ b/spec/support/unit/create_model_arguments/basic.rb @@ -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 diff --git a/spec/support/unit/create_model_arguments/uniqueness_matcher.rb b/spec/support/unit/create_model_arguments/uniqueness_matcher.rb index 4bb6d9c0..c3fe9b5c 100644 --- a/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +++ b/spec/support/unit/create_model_arguments/uniqueness_matcher.rb @@ -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 diff --git a/spec/support/unit/helpers/class_builder.rb b/spec/support/unit/helpers/class_builder.rb index 3d1477b5..c7e294b8 100644 --- a/spec/support/unit/helpers/class_builder.rb +++ b/spec/support/unit/helpers/class_builder.rb @@ -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 diff --git a/spec/support/unit/helpers/mailer_builder.rb b/spec/support/unit/helpers/mailer_builder.rb index 9e284f03..709afe13 100644 --- a/spec/support/unit/helpers/mailer_builder.rb +++ b/spec/support/unit/helpers/mailer_builder.rb @@ -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 diff --git a/spec/support/unit/helpers/model_builder.rb b/spec/support/unit/helpers/model_builder.rb index 39393161..4a7fae83 100644 --- a/spec/support/unit/helpers/model_builder.rb +++ b/spec/support/unit/helpers/model_builder.rb @@ -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 diff --git a/spec/support/unit/matchers/fail_with_message_including_matcher.rb b/spec/support/unit/matchers/fail_with_message_including_matcher.rb index 8c1e4006..8079b262 100644 --- a/spec/support/unit/matchers/fail_with_message_including_matcher.rb +++ b/spec/support/unit/matchers/fail_with_message_including_matcher.rb @@ -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 diff --git a/spec/support/unit/matchers/fail_with_message_matcher.rb b/spec/support/unit/matchers/fail_with_message_matcher.rb index c86783d5..ba7e58df 100644 --- a/spec/support/unit/matchers/fail_with_message_matcher.rb +++ b/spec/support/unit/matchers/fail_with_message_matcher.rb @@ -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/, '') diff --git a/spec/support/unit/model_creation_strategies/active_model.rb b/spec/support/unit/model_creation_strategies/active_model.rb index 45b5f755..38c79151 100644 --- a/spec/support/unit/model_creation_strategies/active_model.rb +++ b/spec/support/unit/model_creation_strategies/active_model.rb @@ -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(' '), diff --git a/spec/support/unit/record_builder_with_i18n_validation_message.rb b/spec/support/unit/record_builder_with_i18n_validation_message.rb index 8858a781..39261280 100644 --- a/spec/support/unit/record_builder_with_i18n_validation_message.rb +++ b/spec/support/unit/record_builder_with_i18n_validation_message.rb @@ -19,7 +19,7 @@ module UnitTests private def model - @_model ||= super.tap do |model| + @_model ||= super.tap do |_model| stub_validation_messages end end diff --git a/spec/support/unit/record_with_different_error_attribute_builder.rb b/spec/support/unit/record_with_different_error_attribute_builder.rb index e43e1e60..c712e18d 100644 --- a/spec/support/unit/record_with_different_error_attribute_builder.rb +++ b/spec/support/unit/record_with_different_error_attribute_builder.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb index a1aff348..e9aa8845 100644 --- a/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb index 13cf8565..e2431932 100644 --- a/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb index 8a364776..53510ea3 100644 --- a/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb index bc18c2d5..b47869d4 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb @@ -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) diff --git a/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb index 3b8c21d0..dccca62a 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb index f9a900ef..c2c3ab72 100644 --- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb @@ -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? diff --git a/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb index 2c1025c5..7a0ffdea 100644 --- a/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb @@ -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) diff --git a/spec/unit/shoulda/matchers/active_record/have_implicit_order_column_spec.rb b/spec/unit/shoulda/matchers/active_record/have_implicit_order_column_spec.rb index bc3e9d74..51c88c00 100644 --- a/spec/unit/shoulda/matchers/active_record/have_implicit_order_column_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_implicit_order_column_spec.rb @@ -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. diff --git a/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb index 9ae5c578..c8c1e6fb 100644 --- a/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb @@ -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? diff --git a/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb index 07cc1d36..6caee54a 100644 --- a/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb index 2f3112f3..69439b47 100644 --- a/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb b/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb index dd03c185..1eef2a09 100644 --- a/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/doublespeak/double_spec.rb b/spec/unit/shoulda/matchers/doublespeak/double_spec.rb index 0f5b23d9..295a84a0 100644 --- a/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/double_spec.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb b/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb index c181918e..e973f7fc 100644 --- a/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb @@ -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, diff --git a/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb b/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb index cc0f3241..fbe9e896 100644 --- a/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb @@ -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 diff --git a/tasks/documentation.rb b/tasks/documentation.rb index 8c6e8ec7..ff51b33b 100644 --- a/tasks/documentation.rb +++ b/tasks/documentation.rb @@ -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