diff --git a/.rubocop.yml b/.rubocop.yml index 60e9753c1..eaca4ca2d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -15,15 +15,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: @@ -32,6 +30,9 @@ Layout/SpaceInLambdaLiteral: EnforcedStyle: require_space Layout/SpaceInsideBlockBraces: Enabled: false +Lint/AmbiguousBlockAssociation: + Exclude: + - spec/**/* Lint/AmbiguousOperator: Enabled: false Lint/AmbiguousRegexpLiteral: @@ -68,6 +69,10 @@ Metrics/ClassLength: Enabled: false Metrics/MethodLength: Max: 30 +Metrics/ModuleLength: + Enabled: true + Exclude: + - spec/**/* Metrics/ParameterLists: CountKeywordArgs: false Metrics/PerceivedComplexity: @@ -80,6 +85,8 @@ Naming/BinaryOperatorParameterName: Enabled: false Naming/FileName: Enabled: false +Naming/HeredocDelimiterNaming: + Enabled: false Naming/MemoizedInstanceVariableName: EnforcedStyleForLeadingUnderscores: required Naming/PredicateName: @@ -90,6 +97,9 @@ Rails/Delegate: Enabled: false Rails/HttpPositionalArguments: Enabled: false +Rails/SkipsModelValidations: + Exclude: + - spec/**/* Rails/TimeZone: Enabled: false Style/Alias: @@ -137,6 +147,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 15587ccef..a18e036d7 100644 --- a/custom_plan.rb +++ b/custom_plan.rb @@ -41,8 +41,8 @@ def best_available 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 11abe65be..774dd3af2 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 @@ def javascripts 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 c8e06b1cb..5e8165158 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 @@ def initialize(key) @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 383f1602f..61ffdec67 100644 --- a/lib/shoulda/matchers/action_controller/permit_matcher.rb +++ b/lib/shoulda/matchers/action_controller/permit_matcher.rb @@ -303,11 +303,11 @@ def format_parameter_names(parameter_names) 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 @@ def ensure_action_and_verb_present! 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 c68ae67dd..6f3d66db2 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 @@ def description 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 c373e905f..0a8446b17 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 @@ def in_context(context) 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 358d210a6..28aecd20b 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 @@ def render_with_layout(expected_layout = nil) # @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 @@ def failure_message_when_negated 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 d18a08f41..43d50480f 100644 --- a/lib/shoulda/matchers/action_controller/route_matcher.rb +++ b/lib/shoulda/matchers/action_controller/route_matcher.rb @@ -194,11 +194,11 @@ def route_recognized? 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 0837db5f6..9761e1604 100644 --- a/lib/shoulda/matchers/action_controller/route_params.rb +++ b/lib/shoulda/matchers/action_controller/route_params.rb @@ -3,7 +3,7 @@ module Matchers 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 f004ebe22..795d82f93 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 @@ def [](key) 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 @@ def expected_value_matches? 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 5757388ad..ce2091787 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 @@ def matches?(subject) 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 @@ def role 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 20741dbf9..f5d863682 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 @@ def failure_message_when_negated 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/have_secure_password_matcher.rb b/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb index 6da9307c4..d2331064f 100644 --- a/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +++ b/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb @@ -34,8 +34,8 @@ def have_secure_password class HaveSecurePasswordMatcher attr_reader :failure_message - CORRECT_PASSWORD = 'aBcDe12345' - INCORRECT_PASSWORD = 'password' + CORRECT_PASSWORD = 'aBcDe12345'.freeze + INCORRECT_PASSWORD = 'password'.freeze EXPECTED_METHODS = [ :authenticate, @@ -43,13 +43,13 @@ class HaveSecurePasswordMatcher :password_confirmation=, :password_digest, :password_digest=, - ] + ].freeze MESSAGES = { authenticated_incorrect_password: 'expected %{subject} to not authenticate an incorrect password', did_not_authenticate_correct_password: 'expected %{subject} to authenticate the correct password', method_not_found: 'expected %{subject} to respond to %{methods}', - } + }.freeze def description 'have a secure password' @@ -71,7 +71,7 @@ def matches?(subject) attr_reader :subject def validate - missing_methods = EXPECTED_METHODS.select {|m| !subject.respond_to?(m) } + missing_methods = EXPECTED_METHODS.reject {|m| subject.respond_to?(m) } if missing_methods.present? [:method_not_found, { methods: missing_methods.to_sentence }] 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 5cc57f98d..0f9042767 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 @@ class ComparisonMatcher < ValidationMatcher :<= => :less_than_or_equal_to, :== => :equal_to, :!= => :other_than, - } + }.freeze def initialize(numericality_matcher, value, operator) super(nil) @@ -77,7 +77,7 @@ def all_bounds_correct? def failing_submatchers submatchers_and_results. - select { |x| !x[:matched] }. + reject { |x| x[:matched] }. map { |x| x[:matcher] } end @@ -145,12 +145,12 @@ def diffs_to_compare 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 31302f02b..517912a77 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 Qualifiers 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 037760f7a..22d1bd680 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 @@ def simple_description 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 aa91b50fd..c14bc30ad 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 @@ def validate_inclusion_of(attr) # @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 185e4d338..fde79945d 100644 --- a/lib/shoulda/matchers/active_record/association_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matcher.rb @@ -1163,7 +1163,7 @@ def join_table_name end def option_verifier - @option_verifier ||= AssociationMatchers::OptionVerifier.new(reflector) + @_option_verifier ||= AssociationMatchers::OptionVerifier.new(reflector) end protected @@ -1171,7 +1171,7 @@ def option_verifier 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 @@ def missing_options 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 @@ def macro_correct? 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 @@ def join_table_correct? 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 @@ def index_errors_correct? else @missing = "#{name} should have index_errors set to " + - "#{options[:index_errors]}" + options[:index_errors].to_s false end end @@ -1410,7 +1407,8 @@ def foreign_key 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 6866e3b9b..da8523f40 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 @@ def matches?(subject) 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 cf41110f1..f5ef0380a 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 @@ def matches?(subject) private def option_verifier - @option_verifier ||= OptionVerifier.new(subject) + @_option_verifier ||= OptionVerifier.new(subject) end def option_matches? @@ -43,8 +43,8 @@ def option_matches? 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 ae9a56563..e27d247fe 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 @@ def matches?(subject) 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 83fa16485..5a43baf4b 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 @@ def initialize(association_matcher, reflector) @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 @@ def join_table_has_correct_columns? 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 4247f146a..0526b8ea5 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 @@ def through? 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 @@ def has_and_belongs_to_many_name 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 f17766396..7affc2e98 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 @@ def association_relation end def reflection - @reflection ||= reflect_on_association(name) + @_reflection ||= reflect_on_association(name) end def reflect_on_association(name) @@ -48,9 +48,9 @@ def model_class 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 0f3c832db..f6f5dab65 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 AssociationMatchers 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 087759556..3c18c0923 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 @@ def matches?(subject) 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 7985b003d..b109889e5 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 @@ def matches?(subject) 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 0569394a4..d54534643 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 @@ def through_association_exists? 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 @@ def through_association_correct? 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 32a74fa0b..e0bb02de5 100644 --- a/lib/shoulda/matchers/active_record/have_attached_matcher.rb +++ b/lib/shoulda/matchers/active_record/have_attached_matcher.rb @@ -92,10 +92,8 @@ def attachments_association_matcher 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 @@ -121,10 +119,8 @@ def blobs_association_matcher 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 76f955fa2..a38b9df52 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 @@ def correct_primary? 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 341470879..984f575c5 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 @@ def matches?(subject) 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 7e13177dd..d95f92d56 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 @@ def matches?(subject) @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 @@ def description 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 20bd9755c..1c2fae9ee 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 2283af96f..227559c77 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 786202d9e..94c799efb 100644 --- a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +++ b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb @@ -407,11 +407,11 @@ def matches_scopes_configuration? 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 ' @@ -528,20 +528,15 @@ def find_or_create_existing_record 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) @@ -619,11 +614,11 @@ def matches_presence_of_scopes? 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}." @@ -643,11 +638,11 @@ def does_not_match_presence_of_scopes? 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}." @@ -658,14 +653,14 @@ def does_not_match_presence_of_scopes? 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 e09b0082a..9ce1534ca 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 @@ def debugging_enabled? 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 43d4f003c..fb520f4ce 100644 --- a/lib/shoulda/matchers/doublespeak/double_collection.rb +++ b/lib/shoulda/matchers/doublespeak/double_collection.rb @@ -18,19 +18,19 @@ def register_proxy(method_name) 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 71e43e1de..83de70e8d 100644 --- a/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +++ b/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb @@ -4,7 +4,9 @@ module Doublespeak # @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 acb125d13..e39f48c21 100644 --- a/lib/shoulda/matchers/doublespeak/stub_implementation.rb +++ b/lib/shoulda/matchers/doublespeak/stub_implementation.rb @@ -14,11 +14,7 @@ def initialize 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 3c046a3ca..686d0e242 100644 --- a/lib/shoulda/matchers/doublespeak/world.rb +++ b/lib/shoulda/matchers/doublespeak/world.rb @@ -39,13 +39,13 @@ def doubles_activated? 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 2983451e3..9ef6648ed 100644 --- a/lib/shoulda/matchers/independent/delegate_method_matcher.rb +++ b/lib/shoulda/matchers/independent/delegate_method_matcher.rb @@ -256,8 +256,8 @@ def allow_nil 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 @@ def subject_handles_nil_delegate_object? 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 @@ def formatted_calls_on_delegate_object 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 78f7953e8..eea3583dc 100644 --- a/lib/shoulda/matchers/integrations/configuration.rb +++ b/lib/shoulda/matchers/integrations/configuration.rb @@ -60,7 +60,7 @@ def clear_default_test_framework 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 5d3a1fe4e..afc94f7f5 100644 --- a/lib/shoulda/matchers/integrations/libraries/action_controller.rb +++ b/lib/shoulda/matchers/integrations/libraries/action_controller.rb @@ -13,9 +13,8 @@ def integrate_with(test_framework) 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 62eb98174..380c59d19 100644 --- a/lib/shoulda/matchers/integrations/libraries/rails.rb +++ b/lib/shoulda/matchers/integrations/libraries/rails.rb @@ -13,7 +13,7 @@ class Rails :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 3d1c5e327..d4edea0c9 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 @@ class ActiveSupportTestCase 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 a6b16ed88..1a86eb2a1 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 @@ class Minitest4 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 5375cc319..c2d525b38 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 @@ class Minitest5 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 4dc04fc57..9ddd34fdc 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 @@ class TestUnit 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 ae36345c4..8b3914b9f 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 2b5d730f8..51f2322c0 100644 --- a/lib/shoulda/matchers/util/word_wrap.rb +++ b/lib/shoulda/matchers/util/word_wrap.rb @@ -41,7 +41,7 @@ def wrapped_paragraphs # @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 @@ def lines 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 @@ def combine_paragraph_into_one_line # @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 @@ def read_indentation 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 5dbec5147..353e7cd83 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 4ed3bb494..8bcc4e761 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 @@ def test_helper_files_for(test_framework, libraries) 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 @@ def integrates_with_rspec?(test_framework) 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 92d86f7bd..5d1128df6 100644 --- a/spec/support/acceptance/helpers/n_unit_helpers.rb +++ b/spec/support/acceptance/helpers/n_unit_helpers.rb @@ -6,9 +6,9 @@ module NUnitHelpers 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 46fc85528..a5ba2409f 100644 --- a/spec/support/acceptance/helpers/step_helpers.rb +++ b/spec/support/acceptance/helpers/step_helpers.rb @@ -58,11 +58,11 @@ def run_n_unit_test_suite 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 5f6e90976..770e3a40d 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 @@ def failure_message 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 5042c9100..4031b2674 100644 --- a/spec/support/tests/bundle.rb +++ b/spec/support/tests/bundle.rb @@ -9,7 +9,7 @@ def initialize @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 4ac3b63db..7fffa53bd 100644 --- a/spec/support/tests/command_runner.rb +++ b/spec/support/tests/command_runner.rb @@ -57,9 +57,7 @@ def directory=(directory) 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 @@ def possibly_running_quickly(&block) end def possibly_retrying - begin - @num_times_run += 1 - yield - rescue => error - debug { "#{error.class}: #{error.message}" } - - if @num_times_run < @retries - sleep @num_times_run - retry - else - raise error - end + @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 e end end diff --git a/spec/support/tests/current_bundle.rb b/spec/support/tests/current_bundle.rb index f4d095d44..427ef6072 100644 --- a/spec/support/tests/current_bundle.rb +++ b/spec/support/tests/current_bundle.rb @@ -29,7 +29,7 @@ def current_or_latest_appraisal 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 34061c3f9..bd8bb71ee 100644 --- a/spec/support/tests/database.rb +++ b/spec/support/tests/database.rb @@ -2,7 +2,7 @@ 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 fed227530..df7aa13a2 100644 --- a/spec/support/tests/database_configuration.rb +++ b/spec/support/tests/database_configuration.rb @@ -3,7 +3,7 @@ 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 b269a5a18..8fe33d208 100644 --- a/spec/support/tests/filesystem.rb +++ b/spec/support/tests/filesystem.rb @@ -63,9 +63,9 @@ def create_parents_of(path) 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 4a2a66e4e..3859bac5e 100644 --- a/spec/support/tests/version.rb +++ b/spec/support/tests/version.rb @@ -38,8 +38,8 @@ def to_s 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 386e88433..f3e8ad49f 100644 --- a/spec/support/unit/attribute.rb +++ b/spec/support/unit/attribute.rb @@ -4,7 +4,7 @@ class Attribute 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 a5879954f..1702042c9 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 dd4181fc4..4e9714ddb 100644 --- a/spec/support/unit/create_model_arguments/basic.rb +++ b/spec/support/unit/create_model_arguments/basic.rb @@ -3,7 +3,7 @@ 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 4bb6d9c05..c3fe9b5c7 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 @@ def self.normalize_attributes(attributes) 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 @@ def validation_options 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 3d1477b50..c7e294b86 100644 --- a/spec/support/unit/helpers/class_builder.rb +++ b/spec/support/unit/helpers/class_builder.rb @@ -28,7 +28,7 @@ def define_module(module_name, &block) 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 @@ def define_class(class_name, parent_class = Object, &block) 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 9e284f036..709afe138 100644 --- a/spec/support/unit/helpers/mailer_builder.rb +++ b/spec/support/unit/helpers/mailer_builder.rb @@ -4,7 +4,7 @@ def self.configure_example_group(example_group) 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 39393161f..4a7fae830 100644 --- a/spec/support/unit/helpers/model_builder.rb +++ b/spec/support/unit/helpers/model_builder.rb @@ -47,7 +47,7 @@ def create_table(table_name, options = {}, &block) 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 8c1e40068..8079b2624 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 @@ def supports_block_expectations? 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 c86783d56..ba7e58dff 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 @@ def supports_block_expectations? 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 45b5f7550..38c79151e 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 @@ def initialize(attributes = {}) 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 8858a781f..392612809 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 @@ def validation_message_key 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 e43e1e60d..c712e18d4 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 @@ def create_model 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 a1aff3488..e9aa88454 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 @@ 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 @@ def permit_with_conditional_slice_of_params( 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 @@ def params_with_conditional_require(params, *filters) 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 13cf85659..e24319321 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 @@ 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 @@ } 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 @@ } 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 @@ def name=(_value) 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 8a364776a..53510ea30 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 @@ 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 bc18c2d50..b47869d42 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 @@ def configure_validation_matcher(matcher) 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 @@ def build_object(**options, &block) 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 3b8c21d0f..dccca62ac 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 @@ def record_belonging_to( 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 f9a900ef3..c2c3ab725 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 @@ def having_one_non_existent(model_name, assoc_name, options = {}) 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 @@ def having_and_belonging_to_many_non_existent_class(model_name, assoc_name, opti 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 @@ def define_association_with_conditions(model, macro, name, conditions, other_opt 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 2c1025c50..7a0ffdea9 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 @@ def self.can_test_expression_indexes? 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 @@ def self.can_test_expression_indexes? 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 @@ def self.can_test_expression_indexes? 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 bc3e9d74f..51c88c00d 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 9ae5c578f..c8c1e6fb2 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 07cc1d360..6caee54a9 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 @@ 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 @@ def with_serialized_attr(type = nil) 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 2f3112f38..69439b473 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 @@ def configure_validation_matcher(matcher) 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 @@ def configure_validation_matcher(matcher) 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 @@ def build_record_from(model, extra_attributes = {}) 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 @@ def define_model_validating_uniqueness(options = {}, &block) end end - block.call(m) if block + block&.call(m) end model_attributes[model] = attributes @@ -1621,9 +1611,7 @@ def build_record_validating_uniqueness(options = {}, &block) :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 dd03c1853..1eef2a092 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 0f5b23d9f..295a84a05 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 c181918e0..e973f7fc7 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 cc0f32410..fbe9e896b 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 @@ def mailman 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 c87d05024..fdca5f1b1 100644 --- a/tasks/documentation.rb +++ b/tasks/documentation.rb @@ -21,7 +21,7 @@ def self.create 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 @@ def self.create 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 @@ def self.create 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 @@ def generate_docs_for(version, options = {}) end end - def publish_docs_for(version, options = {}) + def publish_docs_for(version, _options = {}) message = build_commit_message(version) within_gh_pages_dir do