From ee1008de7ae02cfb4a2bcacf2f6baaa91b64492d Mon Sep 17 00:00:00 2001 From: Kapil Sachdev Date: Sat, 5 Sep 2020 17:44:10 +0530 Subject: [PATCH] fix(rubocop): Fix Layout related offenses [ci skip] - Layout/EmptyLines - Layout/EmptyLineAfterGuardClause - Layout/TrailingEmptyLines - Layout/EmptyLinesAroundBlockBody - Layout/EmptyLinesAroundModuleBody - Layout/EmptyLineAfterMagicComment - Layout/SpaceInsidePercentLiteralDelimiters - Layout/SpaceAroundEqualsInParameterDefault - Layout/SpaceInsideArrayLiteralBrackets - Layout/LeadingCommentSpace - Layout/SpaceBeforeComment - Layout/SpaceAroundOperators - Layout/SpaceInsideRangeLiteral - Layout/SpaceInsideReferenceBrackets - Layout/SpaceInLambdaLiteral - Layout/SpaceAfterComma - Layout/SpaceInsideHashLiteralBraces - Layout/TrailingWhitespace - Layout/ArgumentAlignment - Layout/HashAlignment - Layout/DotPosition - Layout/IndentationWidth - Layout/EndAlignment - Layout/MultilineOperationIndentation - Layout/IndentationConsistency - Layout/ClosingHeredocIndentation - Layout/MultilineMethodCallBrace- Layout - Layout/ClosingParenthesisIndentation --- .../templates/default/fulldoc/html/setup.rb | 1 + .../action_controller/route_matcher.rb | 1 - .../action_controller/route_params.rb | 2 +- .../allow_mass_assignment_of_matcher.rb | 4 +- .../active_model/disallow_value_matcher.rb | 2 +- .../comparison_matcher.rb | 3 +- .../validate_absence_of_matcher.rb | 2 +- .../validate_inclusion_of_matcher.rb | 8 ++-- .../validate_numericality_of_matcher.rb | 6 +-- .../active_model/validation_message_finder.rb | 4 +- .../active_record/define_enum_for_matcher.rb | 8 ++-- .../have_readonly_attribute_matcher.rb | 6 +-- .../have_secure_token_matcher.rb | 2 + .../validate_uniqueness_of_matcher.rb | 4 +- .../independent/delegate_method_matcher.rb | 4 +- .../test_frameworks/missing_test_framework.rb | 2 +- lib/shoulda/matchers/util.rb | 5 ++- lib/shoulda/matchers/util/word_wrap.rb | 2 +- spec/acceptance_spec_helper.rb | 2 +- .../adds_shoulda_matchers_to_project.rb | 2 +- ...ndicate_number_of_tests_was_run_matcher.rb | 2 +- .../indicate_that_tests_were_run_matcher.rb | 2 +- spec/support/tests/command_runner.rb | 2 +- .../helpers/confirmation_matcher_helpers.rb | 3 +- .../unit/helpers/controller_builder.rb | 2 +- .../render_template_matcher_spec.rb | 2 +- .../render_with_layout_matcher_spec.rb | 1 - .../respond_with_matcher_spec.rb | 2 +- .../action_controller/route_params_spec.rb | 2 +- .../allow_mass_assignment_of_matcher_spec.rb | 4 +- .../active_model/allow_value_matcher_spec.rb | 6 +-- .../disallow_value_matcher_spec.rb | 3 +- .../matchers/active_model/helpers_spec.rb | 5 ++- .../validate_absence_of_matcher_spec.rb | 2 +- .../validate_exclusion_of_matcher_spec.rb | 4 +- .../validate_length_of_matcher_spec.rb | 9 ++-- .../validate_presence_of_matcher_spec.rb | 3 +- .../active_record/association_matcher_spec.rb | 44 ++++++++----------- .../have_rich_text_matcher_spec.rb | 4 +- .../have_secure_token_matcher_spec.rb | 1 - .../validate_uniqueness_of_matcher_spec.rb | 20 ++++----- .../matchers/doublespeak/double_spec.rb | 3 +- .../delegate_method_matcher_spec.rb | 1 + spec/unit_spec_helper.rb | 2 +- 44 files changed, 98 insertions(+), 101 deletions(-) diff --git a/doc_config/yard/templates/default/fulldoc/html/setup.rb b/doc_config/yard/templates/default/fulldoc/html/setup.rb index 51f0708e..c2f0ca67 100644 --- a/doc_config/yard/templates/default/fulldoc/html/setup.rb +++ b/doc_config/yard/templates/default/fulldoc/html/setup.rb @@ -15,6 +15,7 @@ def class_list(root = Registry.root, tree = TreeContext.new) end children.compact.sort_by(&:path).each do |child| next unless child.is_a?(CodeObjects::NamespaceObject) + name = child.namespace.is_a?(CodeObjects::Proxy) ? child.path : child.name has_children = run_verifier(child.children).any? {|o| o.is_a?(CodeObjects::NamespaceObject) } out << "
  • " diff --git a/lib/shoulda/matchers/action_controller/route_matcher.rb b/lib/shoulda/matchers/action_controller/route_matcher.rb index 22e9c3b2..d18a08f4 100644 --- a/lib/shoulda/matchers/action_controller/route_matcher.rb +++ b/lib/shoulda/matchers/action_controller/route_matcher.rb @@ -183,7 +183,6 @@ module Shoulda end end - def guess_controller_if_necessary(controller) params[:controller] ||= controller.controller_path end diff --git a/lib/shoulda/matchers/action_controller/route_params.rb b/lib/shoulda/matchers/action_controller/route_params.rb index 2e4413a0..0837db5f 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} def initialize(args) @args = args 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 4e9bea61..5757388a 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 @@ -94,8 +94,8 @@ module Shoulda @failure_message_when_negated = 'no attributes were protected' else @failure_message_when_negated = "#{class_name} is protecting " << - "#{protected_attributes.to_a.to_sentence}, " << - "but not #{@attribute}." + "#{protected_attributes.to_a.to_sentence}, " << + "but not #{@attribute}." end true else diff --git a/lib/shoulda/matchers/active_model/disallow_value_matcher.rb b/lib/shoulda/matchers/active_model/disallow_value_matcher.rb index e6a50647..3eb35f51 100644 --- a/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +++ b/lib/shoulda/matchers/active_model/disallow_value_matcher.rb @@ -46,7 +46,7 @@ module Shoulda self end - def with_message(message, options={}) + def with_message(message, options = {}) allow_matcher.with_message(message, options) self 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 dd227733..5cc57f98 100644 --- a/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +++ b/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb @@ -18,6 +18,7 @@ module Shoulda unless numericality_matcher.respond_to? :diff_to_compare raise ArgumentError, 'numericality_matcher is invalid' end + @numericality_matcher = numericality_matcher @value = value @operator = operator @@ -127,7 +128,7 @@ module Shoulda when :<= [true, true, false] when :!= - [true, false, true] + [true, false, true] end end diff --git a/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb index c78ddf6a..bd834c33 100644 --- a/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb @@ -103,7 +103,7 @@ module Shoulda if reflection obj = reflection.klass.new if collection? - [ obj ] + [obj] else obj 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 d9faecac..aa91b50f 100644 --- a/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb @@ -545,10 +545,10 @@ EOT values = [] values << case @array - when [true] then false - when [false] then true - else raise CouldNotDetermineValueOutsideOfArray - end + when [true] then false + when [false] then true + else raise CouldNotDetermineValueOutsideOfArray + end if attribute_allows_nil? values << nil diff --git a/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb index 9acbc1f9..1689c9e5 100644 --- a/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb @@ -372,9 +372,9 @@ module Shoulda def allow_nil @expects_to_allow_nil = true prepare_submatcher( - AllowValueMatcher.new(nil) - .for(@attribute) - .with_message(:not_a_number), + AllowValueMatcher.new(nil). + for(@attribute). + with_message(:not_a_number), ) self end diff --git a/lib/shoulda/matchers/active_model/validation_message_finder.rb b/lib/shoulda/matchers/active_model/validation_message_finder.rb index 33d1305e..6387ddaf 100644 --- a/lib/shoulda/matchers/active_model/validation_message_finder.rb +++ b/lib/shoulda/matchers/active_model/validation_message_finder.rb @@ -5,7 +5,7 @@ module Shoulda class ValidationMessageFinder include Helpers - def initialize(instance, attribute, context=nil) + def initialize(instance, attribute, context = nil) @instance = instance @attribute = attribute @context = context @@ -58,8 +58,6 @@ module Shoulda @instance end end - end end end - diff --git a/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb b/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb index 6fd570e0..d661bf89 100644 --- a/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +++ b/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb @@ -421,9 +421,9 @@ module Shoulda def expected_prefix if options.include?(:prefix) if options[:prefix] == true - attribute_name#.to_sym + attribute_name # .to_sym else - options[:prefix]#.to_sym + options[:prefix] # .to_sym end end end @@ -431,9 +431,9 @@ module Shoulda def expected_suffix if options.include?(:suffix) if options[:suffix] == true - attribute_name#.to_sym + attribute_name # .to_sym else - options[:suffix]#.to_sym + options[:suffix] # .to_sym end end 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 aec93184..7e13177d 100644 --- a/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +++ b/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb @@ -40,11 +40,11 @@ module Shoulda else if readonly_attributes.empty? @failure_message = "#{class_name} attribute #{@attribute} " << - 'is not read-only' + 'is not read-only' else @failure_message = "#{class_name} is making " << - "#{readonly_attributes.to_a.to_sentence} " << - "read-only, but not #{@attribute}." + "#{readonly_attributes.to_a.to_sentence} " << + "read-only, but not #{@attribute}." end false end diff --git a/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb b/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb index 541c886e..ba76d31e 100644 --- a/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +++ b/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb @@ -63,12 +63,14 @@ module Shoulda def failure_message return if !@errors + "Expected #{@subject.class} to #{description} but the following " \ "errors were found: #{@errors.join(', ')}" end def failure_message_when_negated return if !@errors + "Did not expect #{@subject.class} to have secure token " \ ":#{token_attribute}" end 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 33f91da8..2b33ec7e 100644 --- a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +++ b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb @@ -795,7 +795,7 @@ module Shoulda column = column_for(scope) if column.respond_to?(:array) && column.array - [ dummy_scalar_value_for(column) ] + [dummy_scalar_value_for(column)] else dummy_scalar_value_for(column) end @@ -807,7 +807,7 @@ module Shoulda def next_value_for(scope, previous_value) if previous_value.is_a?(Array) - [ next_scalar_value_for(scope, previous_value[0]) ] + [next_scalar_value_for(scope, previous_value[0])] else next_scalar_value_for(scope, previous_value) end diff --git a/lib/shoulda/matchers/independent/delegate_method_matcher.rb b/lib/shoulda/matchers/independent/delegate_method_matcher.rb index 76cff52d..2983451e 100644 --- a/lib/shoulda/matchers/independent/delegate_method_matcher.rb +++ b/lib/shoulda/matchers/independent/delegate_method_matcher.rb @@ -245,7 +245,7 @@ module Shoulda def with_prefix(prefix = nil) @delegating_method = :"#{build_delegating_method_prefix(prefix)}_#{delegate_method}" - delegate_method + delegate_method self end @@ -446,7 +446,7 @@ module Shoulda calls_on_delegate_object.each_with_index do |call, i| name = call.method_name args = call.args.map { |arg| arg.inspect }.join(', ') - string << "#{i+1}) #{name}(#{args})\n" + string << "#{i + 1}) #{name}(#{args})\n" end else string << ' (none)' diff --git a/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb b/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb index c92c6477..7056b1fb 100644 --- a/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +++ b/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb @@ -20,7 +20,7 @@ Shoulda::Matchers.configure do |config| with.test_framework :test_unit end end -EOT + EOT end def include(*modules, **options); end diff --git a/lib/shoulda/matchers/util.rb b/lib/shoulda/matchers/util.rb index 3f84fbbd..971adcf3 100644 --- a/lib/shoulda/matchers/util.rb +++ b/lib/shoulda/matchers/util.rb @@ -8,7 +8,7 @@ module Shoulda def self.deconstantize(path) if defined?(ActiveSupport::Inflector) && - ActiveSupport::Inflector.respond_to?(:deconstantize) + ActiveSupport::Inflector.respond_to?(:deconstantize) ActiveSupport::Inflector.deconstantize(path) else path.to_s[0...(path.to_s.rindex('::') || 0)] @@ -17,7 +17,7 @@ module Shoulda def self.safe_constantize(camel_cased_word) if defined?(ActiveSupport::Inflector) && - ActiveSupport::Inflector.respond_to?(:safe_constantize) + ActiveSupport::Inflector.respond_to?(:safe_constantize) ActiveSupport::Inflector.safe_constantize(camel_cased_word) else begin @@ -30,6 +30,7 @@ module Shoulda def self.indent(string, width) return if !string + indentation = ' ' * width string.split(/[\n\r]/).map { |line| indentation + line }.join("\n") end diff --git a/lib/shoulda/matchers/util/word_wrap.rb b/lib/shoulda/matchers/util/word_wrap.rb index 5962e016..2b5d730f 100644 --- a/lib/shoulda/matchers/util/word_wrap.rb +++ b/lib/shoulda/matchers/util/word_wrap.rb @@ -185,7 +185,7 @@ module Shoulda leftover = '' else fitted_line = line[0..index].rstrip - leftover = line[index + 1 .. -1] + leftover = line[index + 1..-1] end { fitted_line: fitted_line, leftover: leftover } diff --git a/spec/acceptance_spec_helper.rb b/spec/acceptance_spec_helper.rb index 5e390467..b3b38f21 100644 --- a/spec/acceptance_spec_helper.rb +++ b/spec/acceptance_spec_helper.rb @@ -8,7 +8,7 @@ require 'rspec/core' require 'spec_helper' -Dir[ File.join(File.expand_path('support/acceptance/**/*.rb', __dir__)) ].sort.each do |file| +Dir[File.join(File.expand_path('support/acceptance/**/*.rb', __dir__))].sort.each do |file| require file end diff --git a/spec/support/acceptance/adds_shoulda_matchers_to_project.rb b/spec/support/acceptance/adds_shoulda_matchers_to_project.rb index 7f605e63..4ed3bb49 100644 --- a/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +++ b/spec/support/acceptance/adds_shoulda_matchers_to_project.rb @@ -94,7 +94,7 @@ module AcceptanceTests files = [] if integrates_with_nunit_and_rails?(test_framework, libraries) || - integrates_with_nunit_only?(test_framework) + integrates_with_nunit_only?(test_framework) files << 'test/test_helper.rb' end 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 7ca88c8f..5f6e9097 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 @@ -22,7 +22,7 @@ module AcceptanceTests def failure_message message = "Expected output to indicate that #{some_tests_were_run}.\n" + - "Expected output: #{expected_output}\n" + "Expected output: #{expected_output}\n" if actual_output.empty? message << 'Actual output: (empty)' diff --git a/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb b/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb index 0b0d32e8..30789615 100644 --- a/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +++ b/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb @@ -61,7 +61,7 @@ module AcceptanceTests def expected_output_for_turn full_report = series.map do |number| "pass: #{number}, fail: 0, error: 0" - end.join('.+') + end.join('.+') Regexp.new(full_report, Regexp::MULTILINE) end diff --git a/spec/support/tests/command_runner.rb b/spec/support/tests/command_runner.rb index 7d65be3a..4ac3b63d 100644 --- a/spec/support/tests/command_runner.rb +++ b/spec/support/tests/command_runner.rb @@ -34,7 +34,7 @@ module Tests ) @env = extract_env_from(@options) - @wrapper = ->(block) { block.call } + @wrapper = -> (block) { block.call } @command_prefix = '' self.directory = Dir.pwd @run_quickly = false diff --git a/spec/support/unit/helpers/confirmation_matcher_helpers.rb b/spec/support/unit/helpers/confirmation_matcher_helpers.rb index dd6c8a14..bba35a69 100644 --- a/spec/support/unit/helpers/confirmation_matcher_helpers.rb +++ b/spec/support/unit/helpers/confirmation_matcher_helpers.rb @@ -10,8 +10,7 @@ module UnitTests def builder_for_record_validating_confirmation_with_18n_message(options = {}) builder = builder_for_record_validating_confirmation(options) RecordBuilderWithI18nValidationMessage.new(builder, - validation_message_key: :confirmation, - ) + validation_message_key: :confirmation,) end end end diff --git a/spec/support/unit/helpers/controller_builder.rb b/spec/support/unit/helpers/controller_builder.rb index e5e651a8..544b38ae 100644 --- a/spec/support/unit/helpers/controller_builder.rb +++ b/spec/support/unit/helpers/controller_builder.rb @@ -27,7 +27,7 @@ module UnitTests layout false define_method(action, &block) end - controller_class.view_paths = [ $test_app.temp_views_directory.to_s ] + controller_class.view_paths = [$test_app.temp_views_directory.to_s] define_routes do get 'examples', to: "examples##{action}" diff --git a/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb index 1ad1cde7..0ce8d1af 100644 --- a/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb @@ -60,7 +60,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher, type: :cont context 'a controller that renders a partial several times' do it 'accepts rendering that partial twice' do controller = build_fake_response(partial: '_customer') do - render partial: 'customer', collection: [1,2] + render partial: 'customer', collection: [1, 2] end expect(controller).to render_template(partial: '_customer', count: 2) diff --git a/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb index 571d633e..cdd63208 100644 --- a/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb @@ -23,7 +23,6 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher, type: :co end context 'a controller that renders without a layout' do - it 'rejects rendering with a layout' do controller_without_layout = build_fake_response { render layout: false } diff --git a/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb index 055973a1..5f202257 100644 --- a/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb @@ -2,7 +2,7 @@ require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::RespondWithMatcher, type: :controller do statuses = { success: 200, redirect: 301, missing: 404, error: 500, - not_implemented: 501, } + not_implemented: 501, } statuses.each do |human_name, numeric_code| context "a controller responding with #{human_name}" do diff --git a/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb b/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb index cbe97fbf..5d213bf5 100644 --- a/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb @@ -19,7 +19,7 @@ describe Shoulda::Matchers::ActionController::RouteParams, type: :controller do context 'when the route params is a string' do it 'produces a hash of route params' do expect(build_route_params('examples#index').normalize). - to eq({ controller: 'examples', action: 'index'}) + to eq({ controller: 'examples', action: 'index' }) end end end diff --git a/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb index 5e09af88..23847a26 100644 --- a/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb @@ -33,7 +33,7 @@ describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher, type: :mo context 'an attribute that is not whitelisted for mass-assignment' do it 'rejects being mass-assignable' do model = define_model(:example, not_whitelisted: :string, - whitelisted: :string,) do + whitelisted: :string,) do attr_accessible :whitelisted end.new @@ -52,7 +52,7 @@ describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher, type: :mo context 'an attribute not included in the mass-assignment blacklist' do it 'accepts being mass-assignable' do model = define_model(:example, not_blacklisted: :string, - blacklisted: :string,) do + blacklisted: :string,) do attr_protected :blacklisted end.new 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 70ce4310..13cf8565 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 @@ -464,7 +464,7 @@ indeed invalid, but it produced these validation errors instead: validates_presence_of :attr validates_length_of :attr, within: 1..5 validates_numericality_of :attr, greater_than_or_equal_to: 1, - less_than_or_equal_to: 50000 + less_than_or_equal_to: 50000 end.new end @@ -784,7 +784,7 @@ that attribute does not exist. message = <<-MESSAGE.rstrip The matcher attempted to set :nonexistent on the Example to "some value", but that attribute does not exist. - MESSAGE + MESSAGE expect(&assertion).to raise_error( described_class::AttributeDoesNotExistError, @@ -810,7 +810,7 @@ value", but that attribute does not exist. message = <<-MESSAGE.rstrip The matcher attempted to set :nonexistent on the Example to "some value", but that attribute does not exist. - MESSAGE + MESSAGE expect(&assertion).to raise_error( described_class::AttributeDoesNotExistError, 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 3d80dbe2..8a364776 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 @@ -37,8 +37,7 @@ describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher, type: :model do it "delegates its failure message to its allow matcher's negative failure message" do allow_matcher = double('allow_matcher', - failure_message_when_negated: 'allow matcher failure', - ).as_null_object + failure_message_when_negated: 'allow matcher failure',).as_null_object allow(Shoulda::Matchers::ActiveModel::AllowValueMatcher). to receive(:new). and_return(allow_matcher) diff --git a/spec/unit/shoulda/matchers/active_model/helpers_spec.rb b/spec/unit/shoulda/matchers/active_model/helpers_spec.rb index 86d16ba9..8471037e 100644 --- a/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/helpers_spec.rb @@ -1,4 +1,5 @@ # encoding: UTF-8 + require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::Helpers do @@ -81,7 +82,7 @@ describe Shoulda::Matchers::ActiveModel::Helpers do context 'if ActiveModel::Errors#generate_message behavior has changed' do it 'provides the right error message for validate_presence_of' do stub_active_model_message_generation(type: :blank, - message: 'Behavior has diverged.',) + message: 'Behavior has diverged.',) assert_presence_validation_has_correct_message end end @@ -101,7 +102,7 @@ describe Shoulda::Matchers::ActiveModel::Helpers do expect(record).to validate_length_of(:attr).is_equal_to(40) end - def store_translations(options = {without: []}) + def store_translations(options = { without: [] }) options[:without] = Array.wrap(options[:without] || []) translations = { diff --git a/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb index 40923041..a8a99cda 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb @@ -203,7 +203,7 @@ could not be proved. it 'does not raise an exception' do stub_translation('activerecord.errors.messages.present', - '%{attribute} must be blank in a %{model}',) + '%{attribute} must be blank in a %{model}',) expect { expect(validating_absence_of(:attr)).to validate_absence_of(:attr) diff --git a/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb index cf9393ba..de42eb84 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb @@ -105,7 +105,7 @@ to ‹5›, but this could not be proved. it 'accepts ensuring the correct range with an interpolated variable in the message' do matcher = validating_exclusion(in: 2..4, message: '%{value} is not good') expect(matcher). - to validate_exclusion_of(:attr). + to validate_exclusion_of(:attr). in_range(2..4). with_message(/^[234] is not good$/) end @@ -203,7 +203,7 @@ but this could not be proved. this test is failing. If you've overridden the writer method for this attribute, then you may need to change it to make this test pass, or do something else entirely. - MESSAGE + MESSAGE }, }, model_creator: :active_model, diff --git a/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb index 1ad01889..0b7f6264 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb @@ -241,7 +241,8 @@ could not be proved. before do stub_translation( 'activerecord.errors.messages.too_long', - 'The %{attribute} of your %{model} is too long (maximum is %{count} characters)',) + 'The %{attribute} of your %{model} is too long (maximum is %{count} characters)', + ) end it 'does not raise an exception' do @@ -256,7 +257,8 @@ could not be proved. before do stub_translation( 'activerecord.errors.messages.too_short', - 'The %{attribute} of your %{model} is too short (minimum is %{count} characters)',) + 'The %{attribute} of your %{model} is too short (minimum is %{count} characters)', + ) end it 'does not raise an exception' do @@ -270,7 +272,8 @@ could not be proved. before do stub_translation( 'activerecord.errors.messages.wrong_length', - 'The %{attribute} of your %{model} is the wrong length (should be %{count} characters)',) + 'The %{attribute} of your %{model} is the wrong length (should be %{count} characters)', + ) end it 'does not raise an exception' do 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 6ab46702..3b8c21d0 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 @@ -886,7 +886,8 @@ could not be proved. before do stub_translation( 'activerecord.errors.messages.blank', - 'Please enter a %{attribute} for your %{model}',) + 'Please enter a %{attribute} for your %{model}', + ) end after { I18n.backend.reload! } 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 ca8bfd57..f9a900ef 100644 --- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb @@ -858,10 +858,9 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher, type: :model do it 'accepts a valid association with a :through option' do define_model :child - define_model :conception, child_id: :integer, - parent_id: :integer do + define_model :conception, child_id: :integer, parent_id: :integer do belongs_to :child - end + end define_model :parent do has_many :conceptions has_many :children, through: :conceptions @@ -877,11 +876,9 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher, type: :model do has_many :children, through: :conceptions end - expect { have_many(:children) } - .not_to match_against(parent_class.new) - .and_fail_with(<<-MESSAGE) + expect { have_many(:children) }.not_to match_against(parent_class.new).and_fail_with(<<-MESSAGE) Expected Parent to have a has_many association called children through conceptions (Could not find the source association(s) "child" or :children in model Conception. Try 'has_many :children, :through => :conceptions, :source => '. Is it one of ?) - MESSAGE + MESSAGE end it 'accepts a valid association with an :as option' do @@ -920,7 +917,7 @@ Expected Parent to have a has_many association called children through conceptio it 'rejects an association with a bad :as option' do define_model :child, caretaker_type: :string, - caretaker_id: :integer + caretaker_id: :integer define_model :parent do has_many :children, as: :guardian end @@ -940,7 +937,7 @@ Expected Parent to have a has_many association called children through conceptio define_model :child define_model :conception, child_id: :integer, - parent_id: :integer do + parent_id: :integer do belongs_to :child end @@ -1251,7 +1248,7 @@ Expected Parent to have a has_many association called children through conceptio it 'accepts a valid association with an :as option' do define_model :detail, detailable_id: :integer, - detailable_type: :string + detailable_type: :string define_model :person do has_one :detail, as: :detailable end @@ -1294,7 +1291,7 @@ Expected Parent to have a has_many association called children through conceptio it 'rejects an association with a bad :as option' do define_model :detail, detailable_id: :integer, - detailable_type: :string + detailable_type: :string define_model :person do has_one :detail, as: :describable end @@ -1442,7 +1439,6 @@ Expected Parent to have a has_many association called children through conceptio }.to fail_with_message(message) end - it 'accepts an association with a through' do define_model :detail @@ -1539,7 +1535,7 @@ Expected Parent to have a has_many association called children through conceptio define_model :relative define_model :person define_model :people_relative, id: false, person_id: :integer, - relative_id: :integer + relative_id: :integer expect(Person.new).not_to have_and_belong_to_many(:relatives) end @@ -1967,19 +1963,17 @@ Expected Person to have a has_and_belongs_to_many association called relatives ( define_model :relative define_model :person do has_and_belongs_to_many :relatives, - foreign_key: :some_foreign_key_id, - association_foreign_key: :custom_association_foreign_key_id + foreign_key: :some_foreign_key_id, + association_foreign_key: :custom_association_foreign_key_id end define_model :people_relative, - id: false, - custom_association_foreign_key_id: :integer, - some_foreign_key_id: :integer + id: false, + custom_association_foreign_key_id: :integer, + some_foreign_key_id: :integer expect(Person.new).to have_and_belong_to_many(:relatives) - end - end it 'rejects an association of the wrong type' do @@ -1997,7 +1991,7 @@ Expected Person to have a has_and_belongs_to_many association called relatives ( define_association_with_conditions(model, :has_and_belongs_to_many, :relatives, adopted: true) end define_model :people_relative, id: false, person_id: :integer, - relative_id: :integer + relative_id: :integer expect(Person.new).to have_and_belong_to_many(:relatives).conditions(adopted: true) end @@ -2008,7 +2002,7 @@ Expected Person to have a has_and_belongs_to_many association called relatives ( has_and_belongs_to_many :relatives end define_model :people_relative, id: false, person_id: :integer, - relative_id: :integer + relative_id: :integer expect(Person.new).not_to have_and_belong_to_many(:relatives).conditions(adopted: true) end @@ -2025,7 +2019,7 @@ Expected Person to have a has_and_belongs_to_many association called relatives ( end define_model :people_person_relative, person_id: :integer, - person_relative_id: :integer + person_relative_id: :integer expect(Person.new).to have_and_belong_to_many(:relatives).class_name('PersonRelative') end @@ -2141,7 +2135,7 @@ Expected Person to have a has_and_belongs_to_many association called relatives ( def having_and_belonging_to_many_relatives(options = {}) define_model :relative define_model :people_relative, id: false, person_id: :integer, - relative_id: :integer + relative_id: :integer define_model :person do has_and_belongs_to_many :relatives end.new @@ -2154,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? diff --git a/spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb index c5f5470b..c5342071 100644 --- a/spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_rich_text_matcher_spec.rb @@ -71,11 +71,11 @@ describe Shoulda::Matchers::ActiveRecord::HaveRichTextMatcher, type: :model do def new_post(has_invalid_content: false, is_rich_text_association: false) columns = {} - + if has_invalid_content columns[:invalid_content] = :string end - + define_model 'Post', columns do if is_rich_text_association has_rich_text :content 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 cc2b203a..9ae5c578 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 @@ -3,7 +3,6 @@ require 'unit_spec_helper' # rubocop:disable Metrics/BlockLength describe Shoulda::Matchers::ActiveRecord::HaveSecureTokenMatcher, type: :model do - if active_record_supports_has_secure_token? describe '#description' do it 'returns the message including the name of the default column' do 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 43cbb319..2f3112f3 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 @@ -20,7 +20,7 @@ describe Shoulda::Matchers::ActiveRecord::ValidateUniquenessOfMatcher, type: :mo it 'still accepts if the scope is unset beforehand' do record = build_record_validating_uniqueness( - scopes: [ build_attribute(name: :scope, value: nil) ], + scopes: [build_attribute(name: :scope, value: nil)], ) expect(record).to validate_uniqueness.scoped_to(:scope) @@ -41,7 +41,7 @@ describe Shoulda::Matchers::ActiveRecord::ValidateUniquenessOfMatcher, type: :mo it 'still accepts if the scope is unset beforehand' do record = create_record_validating_uniqueness( - scopes: [ build_attribute(name: :scope, value: nil) ], + scopes: [build_attribute(name: :scope, value: nil)], ) expect(record).to validate_uniqueness.scoped_to(:scope) @@ -55,7 +55,7 @@ describe Shoulda::Matchers::ActiveRecord::ValidateUniquenessOfMatcher, type: :mo value2 = next_version_of(value1, value_type) value3 = next_version_of(value2, value_type) model = define_model_validating_uniqueness( - scopes: [ build_attribute(name: :scope) ], + scopes: [build_attribute(name: :scope)], ) create_record_from(model, scope: value2) create_record_from(model, scope: value3) @@ -122,7 +122,7 @@ within the scope of :scope1, but this could not be proved. context 'when a different scope is specified' do it 'rejects with an appropriate failure message' do record = build_record_validating_uniqueness( - scopes: [ build_attribute(name: :other) ], + scopes: [build_attribute(name: :other)], additional_attributes: [:scope], ) assertion = lambda do @@ -145,7 +145,7 @@ within the scope of :scope, but this could not be proved. context 'when no scope is specified' do it 'rejects with an appropriate failure message' do record = build_record_validating_uniqueness( - scopes: [ build_attribute(name: :scope) ], + scopes: [build_attribute(name: :scope)], ) assertion = lambda do @@ -165,7 +165,7 @@ this could not be proved. context 'if the scope attribute is unset in the record given to the matcher' do it 'rejects with an appropriate failure message' do record = build_record_validating_uniqueness( - scopes: [ build_attribute(name: :scope, value: nil) ], + scopes: [build_attribute(name: :scope, value: nil)], ) assertion = lambda do @@ -188,7 +188,7 @@ this could not be proved. context 'when there is more than one scope' do it 'rejects with an appropriate failure message (and does not raise an error)' do record = build_record_validating_uniqueness( - scopes: [ build_attribute(name: :scope) ], + scopes: [build_attribute(name: :scope)], ) assertion = lambda do @@ -208,7 +208,7 @@ within the scope of :non_existent, but this could not be proved. context 'when there is more than one scope' do it 'rejects with an appropriate failure message (and does not raise an error)' do record = build_record_validating_uniqueness( - scopes: [ build_attribute(name: :scope) ], + scopes: [build_attribute(name: :scope)], ) assertion = lambda do @@ -1548,7 +1548,7 @@ this could not be proved. def next_version_of(value, value_type) if value.is_a?(Array) - [ next_version_of(value[0], value_type) ] + [next_version_of(value[0], value_type)] elsif value_type == :uuid SecureRandom.uuid elsif value.is_a?(Time) @@ -1632,7 +1632,7 @@ this could not be proved. options = options.dup enum_scope_attribute = normalize_attribute(options.delete(:enum_scope)). - merge(value_type: :integer, column_type: :integer) + merge(value_type: :integer, column_type: :integer) additional_scopes = options.delete(:additional_scopes) { [] } options[:scopes] = [enum_scope_attribute] + additional_scopes dummy_enum_values = [:foo, :bar] diff --git a/spec/unit/shoulda/matchers/doublespeak/double_spec.rb b/spec/unit/shoulda/matchers/doublespeak/double_spec.rb index 087845b2..0f5b23d9 100644 --- a/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/double_spec.rb @@ -186,8 +186,7 @@ module Shoulda::Matchers::Doublespeak object: instance, method_name: method_name, args: expected_args, - block: expected_block, - ) + block: expected_block,) double = described_class.new( world, klass, 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 b9036ac1..cc0f3241 100644 --- a/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb @@ -610,6 +610,7 @@ to account for when #country *was* nil. def hello return unless country + country.hello end end diff --git a/spec/unit_spec_helper.rb b/spec/unit_spec_helper.rb index e343de1b..18a01c23 100644 --- a/spec/unit_spec_helper.rb +++ b/spec/unit_spec_helper.rb @@ -8,7 +8,7 @@ require 'spec_helper' $VERBOSE = true -Dir[ File.join(File.expand_path('support/unit/**/*.rb', __dir__)) ].sort.each do |file| +Dir[File.join(File.expand_path('support/unit/**/*.rb', __dir__))].sort.each do |file| require file end