diff --git a/.rubocop.yml b/.rubocop.yml
index e7b3ddd94..659b0e8f8 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -4,6 +4,11 @@ require:
AllCops:
NewCops: disable
TargetRubyVersion: 2.4
+ Exclude:
+ - 'gemfiles/*'
+Bundler/OrderedGems:
+ Include:
+ - '**/Gemfile'
Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation
Layout/CommentIndentation:
@@ -17,23 +22,26 @@ Layout/EmptyLineBetweenDefs:
Layout/HeredocIndentation:
Enabled: false
Layout/LineLength:
+ Exclude:
+ - spec/**/*
IgnoredPatterns:
- - "^[ ]*#.+$"
- - "^[ ]*describe.+$"
- - "^[ ]*context.+$"
- - "^[ ]*shared_context.+$"
- - "^[ ]*shared_examples_for.+$"
- - "^[ ]*it.+$"
- - "^[ ]*'.+?' => '.+?',?$"
- - "^[ ]*\".+?\" => \".+?\",?$"
+ - !ruby/regexp /\A +(it|describe|context|shared_examples|include_examples|it_behaves_like) ["']/
+ - !ruby/regexp /\A(require|require_relative) ["']/
+ - '^[ ]*#.+$'
+ - '^[ ]*''.+?'' => ''.+?'',?$'
+ - '^[ ]*".+?" => ".+?",?$'
+ Max: 80
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation
-Layout/SpaceInsideBlockBraces:
- Enabled: false
Layout/SpaceInLambdaLiteral:
EnforcedStyle: require_space
+Layout/SpaceInsideBlockBraces:
+ Enabled: false
+Lint/AmbiguousBlockAssociation:
+ Exclude:
+ - spec/**/*
Lint/AmbiguousOperator:
Enabled: false
Lint/AmbiguousRegexpLiteral:
@@ -50,6 +58,8 @@ Lint/LiteralInInterpolation:
Enabled: false
Lint/Loop:
Enabled: false
+Lint/MissingSuper:
+ Enabled: false
Lint/ParenthesesAsGroupedExpression:
Enabled: false
Lint/RequireParentheses:
@@ -63,43 +73,50 @@ Lint/UnderscorePrefixedVariableName:
Lint/Void:
Enabled: false
Metrics/AbcSize:
- Max: 25
+ Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
+Metrics/CyclomaticComplexity:
+ Enabled: false
Metrics/MethodLength:
Max: 30
+Metrics/ModuleLength:
+ Enabled: true
+ Exclude:
+ - spec/**/*
Metrics/ParameterLists:
CountKeywordArgs: false
Metrics/PerceivedComplexity:
- Max: 10
+ Enabled: false
Naming/AccessorMethodName:
Enabled: false
Naming/AsciiIdentifiers:
Enabled: false
Naming/BinaryOperatorParameterName:
Enabled: false
+Naming/FileName:
+ Enabled: false
+Naming/HeredocDelimiterNaming:
+ Enabled: false
Naming/MemoizedInstanceVariableName:
EnforcedStyleForLeadingUnderscores: required
Naming/PredicateName:
Enabled: false
-Style/BlockDelimiters:
- Enabled: false
-Style/ClassVars:
- Enabled: false
-Style/ColonMethodCall:
- Enabled: false
-Naming/FileName:
+Naming/RescuedExceptionsVariableName:
Enabled: false
Rails/Date:
Enabled: false
Rails/Delegate:
Enabled: false
-Rails/TimeZone:
- Enabled: false
Rails/HttpPositionalArguments:
Enabled: false
+Rails/SkipsModelValidations:
+ Exclude:
+ - spec/**/*
+Rails/TimeZone:
+ Enabled: false
Style/Alias:
Enabled: false
Style/ArrayJoin:
@@ -108,19 +125,25 @@ Style/AsciiComments:
Enabled: false
Style/Attr:
Enabled: false
+Style/BlockDelimiters:
+ Enabled: false
Style/CaseEquality:
Enabled: false
Style/CharacterLiteral:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
+Style/ClassVars:
+ Enabled: false
Style/CollectionMethods:
Enabled: true
PreferredMethods:
- find: detect
- reduce: inject
collect: map
+ find: detect
find_all: select
+ reduce: inject
+Style/ColonMethodCall:
+ Enabled: false
Style/CommentAnnotation:
Enabled: false
Style/Documentation:
@@ -133,12 +156,16 @@ Style/EmptyElse:
Enabled: false
Style/EmptyLiteral:
Enabled: false
+Style/EmptyMethod:
+ EnforcedStyle: expanded
Style/Encoding:
Enabled: false
Style/EvenOdd:
Enabled: false
Style/FormatString:
Enabled: false
+Style/FormatStringToken:
+ EnforcedStyle: template
Style/FrozenStringLiteralComment:
Enabled: false
Style/GlobalVars:
@@ -151,6 +178,8 @@ Style/IfWithSemicolon:
Enabled: false
Style/InlineComment:
Enabled: false
+Style/InverseMethods:
+ Enabled: false
Style/Lambda:
Enabled: false
Style/LambdaCall:
@@ -177,6 +206,8 @@ Style/NumericPredicate:
Enabled: false
Style/OneLineConditional:
Enabled: false
+Style/OptionalBooleanParameter:
+ Enabled: false
Style/ParenthesesAroundCondition:
Enabled: false
Style/PercentLiteralDelimiters:
@@ -213,11 +244,11 @@ Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma
Style/TrivialAccessors:
Enabled: false
+Style/VariableInterpolation:
+ Enabled: false
Style/WhenThen:
Enabled: false
Style/WhileUntilModifier:
Enabled: false
Style/WordArray:
Enabled: false
-Style/VariableInterpolation:
- Enabled: false
diff --git a/Appraisals b/Appraisals
index 7e507e750..de9fea76a 100644
--- a/Appraisals
+++ b/Appraisals
@@ -107,7 +107,8 @@ appraise 'rails_5_2' do
gem 'sqlite3', '~> 1.3.6'
end
-if Gem::Requirement.new('>= 2.5.0').satisfied_by?(Gem::Version.new(RUBY_VERSION))
+if Gem::Requirement.new('>= 2.5.0').
+ satisfied_by?(Gem::Version.new(RUBY_VERSION))
appraise 'rails_6_0' do
instance_eval(&shared_dependencies)
instance_eval(&controller_test_dependency)
diff --git a/Gemfile b/Gemfile
index 36d0457c1..879359bad 100644
--- a/Gemfile
+++ b/Gemfile
@@ -14,6 +14,6 @@ gem 'zeus', require: false
# YARD
gem 'fssm'
-gem 'rouge'
gem 'redcarpet'
+gem 'rouge'
gem 'yard'
diff --git a/Gemfile.lock b/Gemfile.lock
index ef73728a5..5364786e0 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,6 +1,12 @@
GEM
remote: https://rubygems.org/
specs:
+ activesupport (6.0.3.4)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (>= 0.7, < 2)
+ minitest (~> 5.1)
+ tzinfo (~> 1.1)
+ zeitwerk (~> 2.2, >= 2.2.2)
appraisal (2.2.0)
bundler
rake
@@ -8,11 +14,15 @@ GEM
ast (2.4.1)
byebug (11.1.3)
coderay (1.1.3)
+ concurrent-ruby (1.1.7)
diff-lcs (1.3)
fssm (0.2.10)
+ i18n (1.8.5)
+ concurrent-ruby (~> 1.0)
method_source (1.0.0)
+ minitest (5.14.2)
parallel (1.19.2)
- parser (2.7.1.4)
+ parser (2.7.2.0)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
@@ -20,11 +30,11 @@ GEM
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
- rack (2.2.2)
+ rack (2.2.3)
rainbow (3.0.0)
rake (13.0.1)
redcarpet (3.5.0)
- regexp_parser (1.7.1)
+ regexp_parser (1.8.2)
rexml (3.2.4)
rouge (3.22.0)
rspec (3.9.0)
@@ -40,27 +50,32 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
- rubocop (0.89.1)
+ rubocop (1.0.0)
parallel (~> 1.10)
- parser (>= 2.7.1.1)
+ parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
- regexp_parser (>= 1.7)
+ regexp_parser (>= 1.8)
rexml
- rubocop-ast (>= 0.3.0, < 1.0)
+ rubocop-ast (>= 0.6.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
- rubocop-ast (0.3.0)
- parser (>= 2.7.1.4)
- rubocop-packaging (0.4.0)
- rubocop (~> 0.89)
- rubocop-rails (2.0.1)
+ rubocop-ast (1.1.0)
+ parser (>= 2.7.1.5)
+ rubocop-packaging (0.5.1)
+ rubocop (>= 0.89, < 2.0)
+ rubocop-rails (2.8.1)
+ activesupport (>= 4.2.0)
rack (>= 1.1)
- rubocop (>= 0.70.0)
+ rubocop (>= 0.87.0)
ruby-progressbar (1.10.1)
thor (0.20.0)
+ thread_safe (0.3.6)
+ tzinfo (1.2.7)
+ thread_safe (~> 0.1)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)
yard (0.9.25)
+ zeitwerk (2.4.0)
zeus (0.15.14)
method_source (>= 0.6.7)
diff --git a/Rakefile b/Rakefile
index 411c8e1b0..6d0368506 100644
--- a/Rakefile
+++ b/Rakefile
@@ -8,14 +8,14 @@ require_relative 'spec/support/tests/current_bundle'
RSpec::Core::RakeTask.new('spec:unit') do |t|
t.ruby_opts = '-w -r ./spec/report_warnings'
- t.pattern = "spec/unit/**/*_spec.rb"
+ t.pattern = 'spec/unit/**/*_spec.rb'
t.rspec_opts = '--color --format progress'
t.verbose = false
end
RSpec::Core::RakeTask.new('spec:acceptance') do |t|
t.ruby_opts = '-w -r ./spec/report_warnings'
- t.pattern = "spec/acceptance/**/*_spec.rb"
+ t.pattern = 'spec/acceptance/**/*_spec.rb'
t.rspec_opts = '--color --format progress'
t.verbose = false
end
@@ -24,18 +24,16 @@ task :default do
if Tests::CurrentBundle.instance.appraisal_in_use?
sh 'rake spec:unit --trace'
sh 'rake spec:acceptance --trace'
+ elsif ENV['CI']
+ exec 'appraisal install && appraisal rake --trace'
else
- if ENV['CI']
- exec "appraisal install && appraisal rake --trace"
- else
- appraisal = Tests::CurrentBundle.instance.latest_appraisal
- exec "appraisal install && appraisal #{appraisal} rake --trace"
- end
+ appraisal = Tests::CurrentBundle.instance.latest_appraisal
+ exec "appraisal install && appraisal #{appraisal} rake --trace"
end
end
namespace :appraisal do
- task :list do
+ task list: :environment do
appraisals = Tests::CurrentBundle.instance.available_appraisals
puts "Valid appraisals: #{appraisals.join(', ')}"
end
diff --git a/custom_plan.rb b/custom_plan.rb
index 944b6b0f7..f042aa4aa 100644
--- a/custom_plan.rb
+++ b/custom_plan.rb
@@ -25,13 +25,13 @@ class CustomPlan < Zeus::Plan
def boot
ENV['BUNDLE_GEMFILE'] = File.expand_path(
"../gemfiles/#{latest_appraisal}.gemfile",
- __FILE__
+ __FILE__,
)
require 'bundler/setup'
- $LOAD_PATH << File.expand_path('../lib', __FILE__)
- $LOAD_PATH << File.expand_path('../spec', __FILE__)
+ $LOAD_PATH << File.expand_path('lib', __dir__)
+ $LOAD_PATH << File.expand_path('spec', __dir__)
# Fix Zeus for Pry 0.13.0+
Pry::Pager.class_eval do
@@ -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
@@ -97,7 +97,7 @@ def expand_rspec_argument(rspec_argument)
file_path, location = match.captures
expanded_file_path = File.expand_path(
"../spec/unit/shoulda/matchers/#{file_path}",
- __FILE__
+ __FILE__,
)
[expanded_file_path, location]
diff --git a/doc_config/yard/setup.rb b/doc_config/yard/setup.rb
index 6483b4c22..5957c5d64 100644
--- a/doc_config/yard/setup.rb
+++ b/doc_config/yard/setup.rb
@@ -1,4 +1,6 @@
-YARD::Templates::Engine.register_template_path(File.dirname(__FILE__) + '/templates')
+YARD::Templates::Engine.register_template_path(
+ "#{File.dirname(__FILE__)}/templates",
+)
require 'rouge'
diff --git a/doc_config/yard/templates/default/fulldoc/html/setup.rb b/doc_config/yard/templates/default/fulldoc/html/setup.rb
index 1696df6d5..4081ab744 100644
--- a/doc_config/yard/templates/default/fulldoc/html/setup.rb
+++ b/doc_config/yard/templates/default/fulldoc/html/setup.rb
@@ -8,28 +8,32 @@ def javascripts
end
def class_list(root = Registry.root, tree = TreeContext.new)
- out = String.new("")
+ out = String.new('')
children = run_verifier(root.children)
if root == Registry.root
children += @items.select {|o| o.namespace.is_a?(CodeObjects::Proxy) }
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) }
+ has_children = run_verifier(child.children).
+ any? {|o| o.is_a?(CodeObjects::NamespaceObject) }
out << "
"
out << ""
out << "
" if has_children
out << linkify(child, name)
- out << " < #{child.superclass.name}" if child.is_a?(CodeObjects::ClassObject) && child.superclass
+ if child.is_a?(CodeObjects::ClassObject) && child.superclass
+ out << " < #{child.superclass.name}"
+ end
out << "
"
out << child.namespace.title
- out << ""
- out << "
"
+ out << ''
+ out << ''
tree.nest do
out << "#{class_list(child, tree)}
" if has_children
end
- out << ""
+ out << ''
end
out
end
diff --git a/doc_config/yard/templates/default/layout/html/setup.rb b/doc_config/yard/templates/default/layout/html/setup.rb
index ec952ba95..a12121f52 100644
--- a/doc_config/yard/templates/default/layout/html/setup.rb
+++ b/doc_config/yard/templates/default/layout/html/setup.rb
@@ -10,21 +10,23 @@ 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 + "
"
+ "#{data}
"
end
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/gemfiles/rails_4_2.gemfile b/gemfiles/rails_4_2.gemfile
index b58c8b2fe..a89c23df4 100644
--- a/gemfiles/rails_4_2.gemfile
+++ b/gemfiles/rails_4_2.gemfile
@@ -9,12 +9,13 @@ gem "pry-byebug"
gem "rake", "13.0.1"
gem "rspec", "~> 3.9"
gem "rubocop", require: false
+gem "rubocop-packaging", require: false
gem "rubocop-rails", require: false
gem "warnings_logger"
gem "zeus", require: false
gem "fssm"
-gem "rouge"
gem "redcarpet"
+gem "rouge"
gem "yard"
gem "spring"
gem "spring-commands-rspec"
diff --git a/gemfiles/rails_4_2.gemfile.lock b/gemfiles/rails_4_2.gemfile.lock
index cbbc45ff8..42af8d843 100644
--- a/gemfiles/rails_4_2.gemfile.lock
+++ b/gemfiles/rails_4_2.gemfile.lock
@@ -168,6 +168,8 @@ GEM
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
+ rubocop-packaging (0.4.0)
+ rubocop (~> 0.89)
rubocop-rails (2.4.1)
rack (>= 1.1)
rubocop (>= 0.72.0)
@@ -238,6 +240,7 @@ DEPENDENCIES
rspec (~> 3.9)
rspec-rails (~> 3.9)
rubocop
+ rubocop-packaging
rubocop-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
diff --git a/gemfiles/rails_5_0.gemfile b/gemfiles/rails_5_0.gemfile
index 0bb6362fe..2513e53be 100644
--- a/gemfiles/rails_5_0.gemfile
+++ b/gemfiles/rails_5_0.gemfile
@@ -9,12 +9,13 @@ gem "pry-byebug"
gem "rake", "13.0.1"
gem "rspec", "~> 3.9"
gem "rubocop", require: false
+gem "rubocop-packaging", require: false
gem "rubocop-rails", require: false
gem "warnings_logger"
gem "zeus", require: false
gem "fssm"
-gem "rouge"
gem "redcarpet"
+gem "rouge"
gem "yard"
gem "spring"
gem "spring-commands-rspec"
diff --git a/gemfiles/rails_5_0.gemfile.lock b/gemfiles/rails_5_0.gemfile.lock
index ecb83c944..c0b5f9f63 100644
--- a/gemfiles/rails_5_0.gemfile.lock
+++ b/gemfiles/rails_5_0.gemfile.lock
@@ -161,6 +161,8 @@ GEM
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
+ rubocop-packaging (0.4.0)
+ rubocop (~> 0.89)
rubocop-rails (2.4.1)
rack (>= 1.1)
rubocop (>= 0.72.0)
@@ -231,6 +233,7 @@ DEPENDENCIES
rspec (~> 3.9)
rspec-rails (~> 3.9)
rubocop
+ rubocop-packaging
rubocop-rails
sass-rails (~> 5.0)
shoulda-context (~> 1.2.0)
diff --git a/gemfiles/rails_5_1.gemfile b/gemfiles/rails_5_1.gemfile
index ac7a944d6..1da437b14 100644
--- a/gemfiles/rails_5_1.gemfile
+++ b/gemfiles/rails_5_1.gemfile
@@ -9,12 +9,13 @@ gem "pry-byebug"
gem "rake", "13.0.1"
gem "rspec", "~> 3.9"
gem "rubocop", require: false
+gem "rubocop-packaging", require: false
gem "rubocop-rails", require: false
gem "warnings_logger"
gem "zeus", require: false
gem "fssm"
-gem "rouge"
gem "redcarpet"
+gem "rouge"
gem "yard"
gem "spring"
gem "spring-commands-rspec"
diff --git a/gemfiles/rails_5_1.gemfile.lock b/gemfiles/rails_5_1.gemfile.lock
index 3c60b9d00..4289da509 100644
--- a/gemfiles/rails_5_1.gemfile.lock
+++ b/gemfiles/rails_5_1.gemfile.lock
@@ -169,6 +169,8 @@ GEM
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
+ rubocop-packaging (0.4.0)
+ rubocop (~> 0.89)
rubocop-rails (2.4.1)
rack (>= 1.1)
rubocop (>= 0.72.0)
@@ -246,6 +248,7 @@ DEPENDENCIES
rspec (~> 3.9)
rspec-rails (~> 3.9)
rubocop
+ rubocop-packaging
rubocop-rails
sass-rails (~> 5.0)
selenium-webdriver
diff --git a/gemfiles/rails_5_2.gemfile b/gemfiles/rails_5_2.gemfile
index 7a253fe31..70c8dd36b 100644
--- a/gemfiles/rails_5_2.gemfile
+++ b/gemfiles/rails_5_2.gemfile
@@ -9,12 +9,13 @@ gem "pry-byebug"
gem "rake", "13.0.1"
gem "rspec", "~> 3.9"
gem "rubocop", require: false
+gem "rubocop-packaging", require: false
gem "rubocop-rails", require: false
gem "warnings_logger"
gem "zeus", require: false
gem "fssm"
-gem "rouge"
gem "redcarpet"
+gem "rouge"
gem "yard"
gem "spring"
gem "spring-commands-rspec"
diff --git a/gemfiles/rails_5_2.gemfile.lock b/gemfiles/rails_5_2.gemfile.lock
index 52124b0d4..010b51ec5 100644
--- a/gemfiles/rails_5_2.gemfile.lock
+++ b/gemfiles/rails_5_2.gemfile.lock
@@ -186,6 +186,8 @@ GEM
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
+ rubocop-packaging (0.4.0)
+ rubocop (~> 0.89)
rubocop-rails (2.4.1)
rack (>= 1.1)
rubocop (>= 0.72.0)
@@ -265,6 +267,7 @@ DEPENDENCIES
rspec (~> 3.9)
rspec-rails (~> 3.9)
rubocop
+ rubocop-packaging
rubocop-rails
sass-rails (~> 5.0)
selenium-webdriver
diff --git a/gemfiles/rails_6_0.gemfile b/gemfiles/rails_6_0.gemfile
index c702b8203..d002b112e 100644
--- a/gemfiles/rails_6_0.gemfile
+++ b/gemfiles/rails_6_0.gemfile
@@ -9,12 +9,13 @@ gem "pry-byebug"
gem "rake", "13.0.1"
gem "rspec", "~> 3.9"
gem "rubocop", require: false
+gem "rubocop-packaging", require: false
gem "rubocop-rails", require: false
gem "warnings_logger"
gem "zeus", require: false
gem "fssm"
-gem "rouge"
gem "redcarpet"
+gem "rouge"
gem "yard"
gem "spring"
gem "spring-commands-rspec"
diff --git a/gemfiles/rails_6_0.gemfile.lock b/gemfiles/rails_6_0.gemfile.lock
index e75a49623..d2ec4547d 100644
--- a/gemfiles/rails_6_0.gemfile.lock
+++ b/gemfiles/rails_6_0.gemfile.lock
@@ -196,6 +196,8 @@ GEM
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
+ rubocop-packaging (0.1.1)
+ rubocop (>= 0.75.0)
rubocop-rails (2.4.1)
rack (>= 1.1)
rubocop (>= 0.72.0)
@@ -279,6 +281,7 @@ DEPENDENCIES
rspec (~> 3.9)
rspec-rails (~> 3.9)
rubocop
+ rubocop-packaging
rubocop-rails
sass-rails (>= 6)
selenium-webdriver
diff --git a/lib/shoulda/matchers/action_controller/callback_matcher.rb b/lib/shoulda/matchers/action_controller/callback_matcher.rb
index 5b915270e..6c5cf1edb 100644
--- a/lib/shoulda/matchers/action_controller/callback_matcher.rb
+++ b/lib/shoulda/matchers/action_controller/callback_matcher.rb
@@ -179,11 +179,13 @@ def matches?(controller)
end
def failure_message
- "Expected that #{controller_class.name} would have :#{method_name} as a #{kind}_#{callback_type}"
+ "Expected that #{controller_class.name} would have :#{method_name}"\
+ " as a #{kind}_#{callback_type}"
end
def failure_message_when_negated
- "Expected that #{controller_class.name} would not have :#{method_name} as a #{kind}_#{callback_type}"
+ "Expected that #{controller_class.name} would not have"\
+ " :#{method_name} as a #{kind}_#{callback_type}"
end
def description
diff --git a/lib/shoulda/matchers/action_controller/filter_param_matcher.rb b/lib/shoulda/matchers/action_controller/filter_param_matcher.rb
index c8e06b1cb..a96a22e2f 100644
--- a/lib/shoulda/matchers/action_controller/filter_param_matcher.rb
+++ b/lib/shoulda/matchers/action_controller/filter_param_matcher.rb
@@ -31,12 +31,13 @@ def initialize(key)
@key = key
end
- def matches?(controller)
+ def matches?(_controller)
filters_key?
end
def failure_message
- "Expected #{@key} to be filtered; filtered keys: #{filtered_keys.join(', ')}"
+ "Expected #{@key} to be filtered; filtered keys:"\
+ " #{filtered_keys.join(', ')}"
end
def failure_message_when_negated
diff --git a/lib/shoulda/matchers/action_controller/permit_matcher.rb b/lib/shoulda/matchers/action_controller/permit_matcher.rb
index ef184aaf0..d2a4f656c 100644
--- a/lib/shoulda/matchers/action_controller/permit_matcher.rb
+++ b/lib/shoulda/matchers/action_controller/permit_matcher.rb
@@ -209,7 +209,8 @@ class PermitMatcher
attr_writer :stubbed_params
def initialize(expected_permitted_parameter_names)
- @expected_permitted_parameter_names = expected_permitted_parameter_names
+ @expected_permitted_parameter_names =
+ expected_permitted_parameter_names
@action = nil
@verb = nil
@request_params = {}
@@ -262,18 +263,20 @@ def matches?(controller)
end
def failure_message
- "Expected #{verb.upcase} ##{action} to #{expectation},\nbut #{reality}."
+ "Expected #{verb.upcase} ##{action} to #{expectation},"\
+ "\nbut #{reality}."
end
def failure_message_when_negated
- "Expected #{verb.upcase} ##{action} not to #{expectation},\nbut it did."
+ "Expected #{verb.upcase} ##{action} not to #{expectation},"\
+ "\nbut it did."
end
protected
- attr_reader :controller, :double_collections_by_parameter_name, :action, :verb,
- :request_params, :expected_permitted_parameter_names, :context, :subparameter_name,
- :parameters_double_registry
+ attr_reader :controller, :double_collections_by_parameter_name, :action,
+ :verb, :request_params, :expected_permitted_parameter_names,
+ :context, :subparameter_name, :parameters_double_registry
def expectation
message = 'restrict parameters '
@@ -282,7 +285,8 @@ def expectation
message << "on #{subparameter_name.inspect} "
end
- message << 'to ' + format_parameter_names(expected_permitted_parameter_names)
+ message << 'to '\
+ "#{format_parameter_names(expected_permitted_parameter_names)}"
message
end
@@ -291,9 +295,9 @@ def reality
if actual_permitted_parameter_names.empty?
'it did not restrict any parameters'
else
- 'the restricted parameters were ' +
- format_parameter_names(actual_permitted_parameter_names) +
- ' instead'
+ 'the restricted parameters were '\
+ "#{format_parameter_names(actual_permitted_parameter_names)}"\
+ ' instead'
end
end
@@ -303,12 +307,12 @@ 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
end
@@ -329,8 +333,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
@@ -346,7 +350,7 @@ def initialize
def register
double_collection = Doublespeak.double_collection_for(
- ::ActionController::Parameters.singleton_class
+ ::ActionController::Parameters.singleton_class,
)
double_collection.register_proxy(:new).to_return do |call|
params = call.return_value
@@ -389,7 +393,7 @@ def permitted_parameter_names(args = {})
if double_collections_by_parameter_name.key?(subparameter_name)
self.class.permitted_parameter_names_within(
- double_collections_by_parameter_name[subparameter_name]
+ double_collections_by_parameter_name[subparameter_name],
)
else
[]
@@ -436,7 +440,8 @@ def message
# @private
class VerbNotDefinedError < StandardError
def message
- 'You must specify an HTTP verb when using a non-RESTful action. For example: for(:authorize, verb: :post)'
+ 'You must specify an HTTP verb when using a non-RESTful action.'\
+ ' For example: for(:authorize, verb: :post)'
end
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..b998aee33 100644
--- a/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb
+++ b/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb
@@ -64,12 +64,12 @@ 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,12 @@ 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
@@ -118,7 +119,9 @@ def rendered_with_expected_layout?
end
def rendered_layouts
- recorded_layouts.keys.compact.map { |layout| layout.sub(%r{^layouts/}, '') }
+ recorded_layouts.keys.compact.map { |layout|
+ layout.sub(%r{^layouts/}, '')
+ }
end
def recorded_layouts
@@ -135,7 +138,7 @@ def expectation
def result
if rendered_with_layout?
- 'rendered with ' + rendered_layouts.map(&:inspect).join(', ')
+ "rendered with #{rendered_layouts.map(&:inspect).join(', ')}"
else
'rendered without a layout'
end
diff --git a/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb b/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb
index c791fa1fb..7c1509d5a 100644
--- a/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb
+++ b/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb
@@ -79,7 +79,8 @@ def expectation
end
unless handler_exists?
- expectation << " but #{controller} does not respond to #{expected_method}"
+ expectation << " but #{controller} does not respond to"\
+ " #{expected_method}"
end
expectation
end
diff --git a/lib/shoulda/matchers/action_controller/route_matcher.rb b/lib/shoulda/matchers/action_controller/route_matcher.rb
index 22e9c3b25..43d50480f 100644
--- a/lib/shoulda/matchers/action_controller/route_matcher.rb
+++ b/lib/shoulda/matchers/action_controller/route_matcher.rb
@@ -183,7 +183,6 @@ def add_port_to_path(path, port)
end
end
-
def guess_controller_if_necessary(controller)
params[:controller] ||= controller.controller_path
end
@@ -195,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 2e4413a05..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..4f82ec95b 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,9 @@ 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
@@ -42,12 +44,14 @@ def matches?(controller)
end
def failure_message
- "Expected #{controller.class} to #{expectation_description}, but it did not"
+ "Expected #{controller.class} to #{expectation_description},"\
+ ' but it did not'
end
alias_method :failure_message_for_should, :failure_message
def failure_message_when_negated
- "Expected #{controller.class} not to #{expectation_description}, but it did"
+ "Expected #{controller.class} not to #{expectation_description},"\
+ ' but it did'
end
alias_method :failure_message_for_should_not,
:failure_message_when_negated
@@ -81,18 +85,20 @@ 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
-
- if expected_value_set?
- if expected_value.is_a?(Regexp)
- string << " to a value matching #{expected_value.inspect}"
+ string <<
+ if key_set?
+ " #{store.name}[#{key.inspect}]"
else
- string << " to #{expected_value.inspect}"
+ " any key in #{store.name}"
end
+
+ if expected_value_set?
+ 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 2c81db7b5..4cf75f10d 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
@@ -89,23 +89,24 @@ def matches?(subject)
@subject = subject
if attr_mass_assignable?
if whitelisting?
- @failure_message_when_negated = "#{@attribute} was made accessible"
+ @failure_message_when_negated = "#{@attribute} was made "\
+ 'accessible'
+ elsif protected_attributes.empty?
+ @failure_message_when_negated = 'no attributes were protected'
else
- if protected_attributes.empty?
- @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}."
- end
+ @failure_message_when_negated =
+ "#{class_name} is protecting " <<
+ "#{protected_attributes.to_a.to_sentence}, " <<
+ "but not #{@attribute}."
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
@@ -131,15 +132,16 @@ 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 5b8969478..023e0833b 100644
--- a/lib/shoulda/matchers/active_model/allow_value_matcher.rb
+++ b/lib/shoulda/matchers/active_model/allow_value_matcher.rb
@@ -313,7 +313,7 @@ class AllowValueMatcher
:attribute_to_check_message_against,
:attribute_to_set,
:context,
- :instance
+ :instance,
)
attr_writer(
@@ -423,55 +423,56 @@ def failure_message
end
if include_attribute_changed_value_message?
- message << "\n\n" + attribute_changed_value_message.call
+ message << "\n\n#{attribute_changed_value_message.call}"
end
Shoulda::Matchers.word_wrap(message)
end
- def failure_message_when_negated
+ def failure_message_when_negated # rubocop:disable Metrics/MethodLength
attribute_setter = result.attribute_setter
if attribute_setter.unsuccessfully_checked?
message = attribute_setter.failure_message
else
validator = result.validator
- message = failure_message_preface.call + ' invalid'
+ message = "#{failure_message_preface.call} invalid"
if validator.type_of_message_matched?
if validator.has_messages?
message << ' and to'
- if validator.captured_validation_exception?
+ if validator.captured_validation_exception? # rubocop:disable Metrics/BlockNesting
message << ' raise a validation exception with message'
else
message << ' produce'
- if expected_message.is_a?(Regexp)
- message << ' a'
- else
- message << ' the'
- end
+ message <<
+ if expected_message.is_a?(Regexp) # rubocop:disable Metrics/BlockNesting
+ ' a'
+ else
+ ' the'
+ end
message << ' validation error'
end
- if expected_message.is_a?(Regexp)
+ if expected_message.is_a?(Regexp) # rubocop:disable Metrics/BlockNesting
message << ' matching '
message << Shoulda::Matchers::Util.inspect_value(
- expected_message
+ expected_message,
)
else
message << " #{expected_message.inspect}"
end
- unless validator.captured_validation_exception?
+ unless validator.captured_validation_exception? # rubocop:disable Metrics/BlockNesting
message << " on :#{attribute_to_check_message_against}"
end
message << '. The record was indeed invalid, but'
- if validator.captured_validation_exception?
+ if validator.captured_validation_exception? # rubocop:disable Metrics/BlockNesting
message << ' the exception message was '
message << validator.validation_exception_message.inspect
message << ' instead.'
@@ -492,7 +493,7 @@ def failure_message_when_negated
end
if include_attribute_changed_value_message?
- message << "\n\n" + attribute_changed_value_message.call
+ message << "\n\n#{attribute_changed_value_message.call}"
end
Shoulda::Matchers.word_wrap(message)
@@ -531,7 +532,8 @@ def last_value_set
def run(strategy)
attribute_setters_for_values_to_preset.first_failing ||
- attribute_setters_and_validators_for_values_to_set.public_send(strategy)
+ attribute_setters_and_validators_for_values_to_set.
+ public_send(strategy)
end
def failure_message_preface
@@ -597,14 +599,14 @@ def attribute_setters_and_validators_for_values_to_set
@_attribute_setters_and_validators_for_values_to_set ||=
AttributeSettersAndValidators.new(
self,
- values_to_set.map { |value| [attribute_to_set, value] }
+ values_to_set.map { |value| [attribute_to_set, value] },
)
end
def inspected_values_to_set
Shoulda::Matchers::Util.inspect_values(values_to_set).to_sentence(
- two_words_connector: " or ",
- last_word_connector: ", or "
+ two_words_connector: ' or ',
+ last_word_connector: ', or ',
)
end
@@ -619,7 +621,7 @@ def default_expected_message
def default_attribute_message
default_error_message(
options[:expected_message],
- default_attribute_message_values
+ default_attribute_message_values,
)
end
@@ -639,7 +641,7 @@ def model_name
def human_attribute_name
instance.class.human_attribute_name(
- attribute_to_check_message_against
+ attribute_to_check_message_against,
)
end
end
diff --git a/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb b/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb
index fc7570be3..fb1d3ae66 100644
--- a/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb
+++ b/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb
@@ -23,7 +23,7 @@ def initialize(args)
@value_written = args.fetch(:value)
@ignore_interference_by_writer = args.fetch(
:ignore_interference_by_writer,
- Qualifiers::IgnoreInterferenceByWriter.new
+ Qualifiers::IgnoreInterferenceByWriter.new,
)
@after_set_callback = args.fetch(:after_set_callback, -> { })
@@ -36,9 +36,9 @@ def description
description << Shoulda::Matchers::Util.inspect_value(value_written)
if attribute_changed_value?
- description << " -- which was read back as "
+ description << ' -- which was read back as '
description << Shoulda::Matchers::Util.inspect_value(value_read)
- description << " --"
+ description << ' --'
end
description
@@ -206,7 +206,7 @@ def attribute_changed_value_error
model: object.class,
attribute_name: attribute_name,
value_written: value_written,
- value_read: value_read
+ value_read: value_read,
)
end
@@ -218,7 +218,7 @@ def attribute_does_not_exist_error
AttributeDoesNotExistError.create(
model: object.class,
attribute_name: attribute_name,
- value: value_written
+ value: value_written,
)
end
diff --git a/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb b/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb
index 8d89fbe3b..a4d285d3f 100644
--- a/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb
+++ b/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb
@@ -34,7 +34,7 @@ def attribute_setter
attribute_name: attribute_name,
value: value,
ignore_interference_by_writer: ignore_interference_by_writer,
- after_set_callback: after_setting_value_callback
+ after_set_callback: after_setting_value_callback,
)
end
@@ -48,7 +48,7 @@ def validator
attribute_to_check_message_against,
context: context,
expects_strict: expects_strict?,
- expected_message: expected_message
+ expected_message: expected_message,
)
end
diff --git a/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb b/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb
index 97b618e3d..132747ec1 100644
--- a/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb
+++ b/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb
@@ -11,7 +11,7 @@ def initialize(allow_value_matcher, values)
AttributeSetterAndValidator.new(
allow_value_matcher,
attribute_name,
- value
+ value,
)
end
end
diff --git a/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb b/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
index f28f1f6a7..e71e8af89 100644
--- a/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
+++ b/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
@@ -11,7 +11,7 @@ def initialize(allow_value_matcher, values)
AttributeSetterAndValidator.new(
allow_value_matcher,
attribute_name,
- value
+ value,
)
end
end
diff --git a/lib/shoulda/matchers/active_model/disallow_value_matcher.rb b/lib/shoulda/matchers/active_model/disallow_value_matcher.rb
index e6a506476..3eb35f516 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 @@ def on(context)
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/have_secure_password_matcher.rb b/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb
index 47ac8f0d4..f5b458bb3 100644
--- a/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb
+++ b/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb
@@ -38,13 +38,15 @@ def have_secure_password(attr = :password)
class HaveSecurePasswordMatcher
attr_reader :failure_message
- CORRECT_PASSWORD = "aBcDe12345".freeze
- INCORRECT_PASSWORD = "password".freeze
+ CORRECT_PASSWORD = 'aBcDe12345'.freeze
+ INCORRECT_PASSWORD = 'password'.freeze
MESSAGES = {
- authenticated_incorrect_password: "expected %{subject} to not authenticate an incorrect %{attribute}",
- did_not_authenticate_correct_password: "expected %{subject} to authenticate the correct %{attribute}",
- method_not_found: "expected %{subject} to respond to %{methods}"
+ authenticated_incorrect_password: 'expected %{subject} to not'\
+ ' authenticate an incorrect %{attribute}',
+ did_not_authenticate_correct_password: 'expected %{subject} to'\
+ ' authenticate the correct %{attribute}',
+ method_not_found: 'expected %{subject} to respond to %{methods}',
}.freeze
def initialize(attribute)
@@ -60,7 +62,8 @@ def matches?(subject)
if failure = validate
key, params = failure
- @failure_message = MESSAGES[key] % { subject: subject.class }.merge(params)
+ @failure_message =
+ MESSAGES[key] % { subject: subject.class }.merge(params)
end
failure.nil?
@@ -71,7 +74,9 @@ def matches?(subject)
attr_reader :subject
def validate
- missing_methods = expected_methods.reject {|m| subject.respond_to?(m) }
+ missing_methods = expected_methods.reject do |m|
+ subject.respond_to?(m)
+ end
if missing_methods.present?
[:method_not_found, { methods: missing_methods.to_sentence }]
@@ -80,7 +85,8 @@ def validate
subject.send("#{@attribute}_confirmation=", CORRECT_PASSWORD)
if not subject.send(authenticate_method, CORRECT_PASSWORD)
- [:did_not_authenticate_correct_password, { attribute: @attribute }]
+ [:did_not_authenticate_correct_password,
+ { attribute: @attribute },]
elsif subject.send(authenticate_method, INCORRECT_PASSWORD)
[:authenticated_incorrect_password, { attribute: @attribute }]
end
@@ -90,7 +96,7 @@ def validate
private
def expected_methods
- @expected_methods ||= %I[
+ @_expected_methods ||= %I[
#{authenticate_method}
#{@attribute}=
#{@attribute}_confirmation=
diff --git a/lib/shoulda/matchers/active_model/helpers.rb b/lib/shoulda/matchers/active_model/helpers.rb
index cf2c5cf87..8b71a9e05 100644
--- a/lib/shoulda/matchers/active_model/helpers.rb
+++ b/lib/shoulda/matchers/active_model/helpers.rb
@@ -26,7 +26,7 @@ def default_error_message(type, options = {})
attribute.to_sym,
type,
model_name,
- options
+ options,
)
end
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 43307be95..8d41b92db 100644
--- a/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb
+++ b/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb
@@ -5,23 +5,42 @@ module NumericalityMatchers
# @private
class ComparisonMatcher < ValidationMatcher
ERROR_MESSAGES = {
- :> => :greater_than,
- :>= => :greater_than_or_equal_to,
- :< => :less_than,
- :<= => :less_than_or_equal_to,
- :== => :equal_to,
- :!= => :other_than,
- }
+ :> => {
+ label: :greater_than,
+ assertions: [false, false, true],
+ },
+ :>= => {
+ label: :greater_than_or_equal_to,
+ assertions: [false, true, true],
+ },
+ :< => {
+ label: :less_than,
+ assertions: [true, false, false],
+ },
+ :<= => {
+ label: :less_than_or_equal_to,
+ assertions: [true, true, false],
+ },
+ :== => {
+ label: :equal_to,
+ assertions: [false, true, false],
+ },
+ :!= => {
+ label: :other_than,
+ assertions: [true, false, true],
+ },
+ }.freeze
def initialize(numericality_matcher, value, operator)
super(nil)
unless numericality_matcher.respond_to? :diff_to_compare
raise ArgumentError, 'numericality_matcher is invalid'
end
+
@numericality_matcher = numericality_matcher
@value = value
@operator = operator
- @message = ERROR_MESSAGES[operator]
+ @message = ERROR_MESSAGES[operator][:label]
end
def simple_description
@@ -94,10 +113,9 @@ def submatchers
end
def submatchers_and_results
- @_submatchers_and_results ||=
- submatchers.map do |matcher|
- { matcher: matcher, matched: matcher.matches?(@subject) }
- end
+ @_submatchers_and_results ||= submatchers.map do |matcher|
+ { matcher: matcher, matched: matcher.matches?(@subject) }
+ end
end
def comparison_combos
@@ -115,20 +133,7 @@ def submatcher_method_names
end
def assertions
- case @operator
- when :>
- [false, false, true]
- when :>=
- [false, true, true]
- when :==
- [false, true, false]
- when :<
- [true, false, false]
- when :<=
- [true, true, false]
- when :!=
- [true, false, true]
- end
+ ERROR_MESSAGES[@operator][:assertions]
end
def diffs_to_compare
@@ -143,14 +148,7 @@ def diffs_to_compare
end
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'
- end
+ ERROR_MESSAGES[@operator][:label].to_s.tr('_', ' ')
end
end
end
diff --git a/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb b/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb
index 7197eba2e..33f5defce 100644
--- a/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb
+++ b/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb
@@ -44,7 +44,7 @@ def diff_to_compare
attr_reader :attribute
- def wrap_disallow_value_matcher(matcher)
+ def wrap_disallow_value_matcher(_matcher)
raise NotImplementedError
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..fd4105566 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(*)
@ignore_interference_by_writer = IgnoreInterferenceByWriter.new
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 c78ddf6ad..bd834c33d 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 @@ def value
if reflection
obj = reflection.klass.new
if collection?
- [ obj ]
+ [obj]
else
obj
end
diff --git a/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb
index 81e91bace..0865a96c8 100644
--- a/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb
+++ b/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb
@@ -148,12 +148,12 @@ def disallows_missing_confirmation
def qualify_matcher(matcher, confirmation_attribute_value)
matcher.values_to_preset = {
- confirmation_attribute => confirmation_attribute_value
+ confirmation_attribute => confirmation_attribute_value,
}
matcher.with_message(
@expected_message,
against: confirmation_attribute,
- values: { attribute: attribute }
+ values: { attribute: attribute },
)
end
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 e58cd780c..f7e6db2eb 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,12 @@ 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
@@ -238,8 +239,8 @@ def inspect_message
def inspected_array
Shoulda::Matchers::Util.inspect_values(@array).to_sentence(
- two_words_connector: " nor ",
- last_word_connector: ", nor "
+ two_words_connector: ' nor ',
+ last_word_connector: ', nor ',
)
end
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 8ae79a67a..3d0efdc61 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 = < 0 &&
allows_length_of?(
@options[:minimum] - 1,
- translated_short_message
+ translated_short_message,
)
end
@@ -402,7 +402,7 @@ def disallows_lower_length?
(@options[:minimum] == 1 && expects_to_allow_blank?) ||
disallows_length_of?(
@options[:minimum] - 1,
- translated_short_message
+ translated_short_message,
)
end
@@ -410,7 +410,7 @@ def allows_higher_length?
@options.key?(:maximum) &&
allows_length_of?(
@options[:maximum] + 1,
- translated_long_message
+ translated_long_message,
)
end
@@ -418,7 +418,7 @@ def disallows_higher_length?
!@options.key?(:maximum) ||
disallows_length_of?(
@options[:maximum] + 1,
- translated_long_message
+ translated_long_message,
)
end
@@ -470,7 +470,7 @@ def translated_short_message
model_name: @subject.class.to_s.underscore,
instance: @subject,
attribute: @attribute,
- count: @options[:minimum]
+ count: @options[:minimum],
)
else
@short_message
@@ -485,7 +485,7 @@ def translated_long_message
model_name: @subject.class.to_s.underscore,
instance: @subject,
attribute: @attribute,
- count: @options[:maximum]
+ count: @options[:maximum],
)
else
@long_message
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 80484f79a..bc7f142bf 100644
--- a/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
+++ b/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
@@ -331,8 +331,7 @@ def validate_numericality_of(attr)
# @private
class ValidateNumericalityOfMatcher
- NUMERIC_NAME = 'number'
- NON_NUMERIC_VALUE = 'abcd'
+ NUMERIC_NAME = 'number'.freeze
DEFAULT_DIFF_TO_COMPARE = 1
include Qualifiers::IgnoringInterferenceByWriter
@@ -364,7 +363,7 @@ def expects_strict?
def only_integer
prepare_submatcher(
- NumericalityMatchers::OnlyIntegerMatcher.new(self, @attribute)
+ NumericalityMatchers::OnlyIntegerMatcher.new(self, @attribute),
)
self
end
@@ -372,9 +371,9 @@ def only_integer
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
@@ -385,14 +384,14 @@ def expects_to_allow_nil?
def odd
prepare_submatcher(
- NumericalityMatchers::OddNumberMatcher.new(self, @attribute)
+ NumericalityMatchers::OddNumberMatcher.new(self, @attribute),
)
self
end
def even
prepare_submatcher(
- NumericalityMatchers::EvenNumberMatcher.new(self, @attribute)
+ NumericalityMatchers::EvenNumberMatcher.new(self, @attribute),
)
self
end
@@ -459,7 +458,7 @@ def simple_description
description << Shoulda::Matchers::Util.a_or_an(full_allowed_type)
if comparison_descriptions.present?
- description << ' ' + comparison_descriptions
+ description << " #{comparison_descriptions}"
end
description
@@ -479,7 +478,8 @@ def failure_message
def failure_message_when_negated
overall_failure_message_when_negated.dup.tap do |message|
message << "\n"
- message << failure_message_for_first_submatcher_that_fails_to_not_match
+ message <<
+ failure_message_for_first_submatcher_that_fails_to_not_match
end
end
@@ -500,15 +500,15 @@ def matches_or_does_not_match?(subject)
def overall_failure_message
Shoulda::Matchers.word_wrap(
- "Expected #{model.name} to #{description}, but this could not " +
- 'be proved.'
+ "Expected #{model.name} to #{description}, but this could not "\
+ 'be proved.',
)
end
def overall_failure_message_when_negated
Shoulda::Matchers.word_wrap(
- "Expected #{model.name} not to #{description}, but this could not " +
- 'be proved.'
+ "Expected #{model.name} not to #{description}, but this could not "\
+ 'be proved.',
)
end
@@ -530,7 +530,7 @@ def columns_hash
def add_disallow_value_matcher
disallow_value_matcher = DisallowValueMatcher.
- new(NON_NUMERIC_VALUE).
+ new(non_numeric_value).
for(@attribute).
with_message(:not_a_number)
@@ -558,7 +558,10 @@ def add_submatcher(submatcher)
end
if submatcher.respond_to?(:diff_to_compare)
- @diff_to_compare = [@diff_to_compare, submatcher.diff_to_compare].max
+ @diff_to_compare = [
+ @diff_to_compare,
+ submatcher.diff_to_compare,
+ ].max
end
@submatchers << submatcher
@@ -579,7 +582,7 @@ def qualify_submatchers
end
submatcher.ignoring_interference_by_writer(
- ignore_interference_by_writer
+ ignore_interference_by_writer,
)
end
end
@@ -600,28 +603,30 @@ def has_been_qualified?
end
def first_submatcher_that_fails_to_match
- @_failing_submatchers ||= @submatchers.detect do |submatcher|
- !submatcher.matches?(@subject)
- end
+ @_first_submatcher_that_fails_to_match ||=
+ @submatchers.detect do |submatcher|
+ !submatcher.matches?(@subject)
+ end
end
def first_submatcher_that_fails_to_not_match
- @_failing_submatchers ||= @submatchers.detect do |submatcher|
- !submatcher.does_not_match?(@subject)
- end
+ @_first_submatcher_that_fails_to_not_match ||=
+ @submatchers.detect do |submatcher|
+ !submatcher.does_not_match?(@subject)
+ end
end
def failure_message_for_first_submatcher_that_fails_to_match
build_submatcher_failure_message_for(
first_submatcher_that_fails_to_match,
- :failure_message
+ :failure_message,
)
end
def failure_message_for_first_submatcher_that_fails_to_not_match
build_submatcher_failure_message_for(
first_submatcher_that_fails_to_not_match,
- :failure_message_when_negated
+ :failure_message_when_negated,
)
end
@@ -652,7 +657,11 @@ def full_allowed_type
def comparison_descriptions
description_array = submatcher_comparison_descriptions
- description_array.empty? ? '' : submatcher_comparison_descriptions.join(' and ')
+ if description_array.empty?
+ ''
+ else
+ submatcher_comparison_descriptions.join(' and ')
+ end
end
def submatcher_comparison_descriptions
@@ -667,6 +676,10 @@ def submatcher_comparison_descriptions
def model
@subject.class
end
+
+ def non_numeric_value
+ 'abcd'
+ end
end
end
end
diff --git a/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
index de770b076..f3b7b5dd2 100644
--- a/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
+++ b/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
@@ -260,11 +260,11 @@ def should_add_footnote_about_belongs_to?
def reason_for_existing_presence_validation
if belongs_to_association_configured_to_be_required?
- "you've instructed your `belongs_to` association to add a " +
+ "you've instructed your `belongs_to` association to add a "\
'presence validation to the attribute'
else
# assume ::ActiveRecord::Base.belongs_to_required_by_default == true
- 'ActiveRecord is configured to add a presence validation to all ' +
+ 'ActiveRecord is configured to add a presence validation to all '\
'`belongs_to` associations, and this includes yours'
end
end
diff --git a/lib/shoulda/matchers/active_model/validation_matcher.rb b/lib/shoulda/matchers/active_model/validation_matcher.rb
index e2a153c40..798d4b2dc 100644
--- a/lib/shoulda/matchers/active_model/validation_matcher.rb
+++ b/lib/shoulda/matchers/active_model/validation_matcher.rb
@@ -67,7 +67,7 @@ def failure_message
message << "\n"
message << Shoulda::Matchers.word_wrap(
failure_reason,
- indent: 2
+ indent: 2,
)
end
end
@@ -79,7 +79,7 @@ def failure_message_when_negated
message << "\n"
message << Shoulda::Matchers.word_wrap(
failure_reason,
- indent: 2
+ indent: 2,
)
end
end
@@ -137,15 +137,15 @@ def allow_blank_does_not_match?
def overall_failure_message
Shoulda::Matchers.word_wrap(
- "Expected #{model.name} to #{description}, but this could not be " +
- 'proved.'
+ "Expected #{model.name} to #{description}, but this could not be "\
+ 'proved.',
)
end
def overall_failure_message_when_negated
Shoulda::Matchers.word_wrap(
- "Expected #{model.name} not to #{description}, but this could " +
- 'not be proved.'
+ "Expected #{model.name} not to #{description}, but this could "\
+ 'not be proved.',
)
end
diff --git a/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb b/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb
index 2fb1adf99..2decbc273 100644
--- a/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb
+++ b/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb
@@ -15,10 +15,8 @@ def initialize(matcher, main_description)
def call
if description_clauses_for_qualifiers.any?
- main_description +
- clause_for_allow_blank_or_nil +
- ', ' +
- description_clauses_for_qualifiers.to_sentence
+ "#{main_description}#{clause_for_allow_blank_or_nil},"\
+ " #{description_clauses_for_qualifiers.to_sentence}"
else
main_description + clause_for_allow_blank_or_nil
end
diff --git a/lib/shoulda/matchers/active_model/validation_message_finder.rb b/lib/shoulda/matchers/active_model/validation_message_finder.rb
index 33d1305e1..551393839 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 ActiveModel
class ValidationMessageFinder
include Helpers
- def initialize(instance, attribute, context=nil)
+ def initialize(instance, attribute, context = nil)
@instance = instance
@attribute = attribute
@context = context
@@ -50,7 +50,7 @@ def errors
end
def validated_instance
- @validated_instance ||= validate_instance
+ @_validated_instance ||= validate_instance
end
def validate_instance
@@ -58,8 +58,6 @@ def validate_instance
@instance
end
end
-
end
end
end
-
diff --git a/lib/shoulda/matchers/active_model/validator.rb b/lib/shoulda/matchers/active_model/validator.rb
index 426437296..740732279 100644
--- a/lib/shoulda/matchers/active_model/validator.rb
+++ b/lib/shoulda/matchers/active_model/validator.rb
@@ -108,14 +108,14 @@ def perform_validation
{
all_validation_errors: all_validation_errors,
validation_error_messages: validation_error_messages,
- validation_exception_message: nil
+ validation_exception_message: nil,
}
- rescue ::ActiveModel::StrictValidationFailed => exception
+ rescue ::ActiveModel::StrictValidationFailed => e
@captured_validation_exception = true
{
all_validation_errors: nil,
validation_error_messages: [],
- validation_exception_message: exception.message
+ validation_exception_message: e.message,
}
end
end
diff --git a/lib/shoulda/matchers/active_record.rb b/lib/shoulda/matchers/active_record.rb
index 9c97d7078..5552e65b2 100644
--- a/lib/shoulda/matchers/active_record.rb
+++ b/lib/shoulda/matchers/active_record.rb
@@ -1,29 +1,29 @@
-require "shoulda/matchers/active_record/association_matcher"
-require "shoulda/matchers/active_record/association_matchers"
-require "shoulda/matchers/active_record/association_matchers/counter_cache_matcher"
-require "shoulda/matchers/active_record/association_matchers/inverse_of_matcher"
-require "shoulda/matchers/active_record/association_matchers/join_table_matcher"
-require "shoulda/matchers/active_record/association_matchers/order_matcher"
-require "shoulda/matchers/active_record/association_matchers/through_matcher"
-require "shoulda/matchers/active_record/association_matchers/dependent_matcher"
-require "shoulda/matchers/active_record/association_matchers/required_matcher"
-require "shoulda/matchers/active_record/association_matchers/optional_matcher"
-require "shoulda/matchers/active_record/association_matchers/source_matcher"
-require "shoulda/matchers/active_record/association_matchers/model_reflector"
-require "shoulda/matchers/active_record/association_matchers/model_reflection"
-require "shoulda/matchers/active_record/association_matchers/option_verifier"
-require "shoulda/matchers/active_record/have_db_column_matcher"
-require "shoulda/matchers/active_record/have_db_index_matcher"
-require "shoulda/matchers/active_record/have_implicit_order_column"
-require "shoulda/matchers/active_record/have_readonly_attribute_matcher"
-require "shoulda/matchers/active_record/have_rich_text_matcher"
-require "shoulda/matchers/active_record/have_secure_token_matcher"
-require "shoulda/matchers/active_record/serialize_matcher"
-require "shoulda/matchers/active_record/accept_nested_attributes_for_matcher"
-require "shoulda/matchers/active_record/define_enum_for_matcher"
-require "shoulda/matchers/active_record/uniqueness"
-require "shoulda/matchers/active_record/validate_uniqueness_of_matcher"
-require "shoulda/matchers/active_record/have_attached_matcher"
+require 'shoulda/matchers/active_record/association_matcher'
+require 'shoulda/matchers/active_record/association_matchers'
+require 'shoulda/matchers/active_record/association_matchers/counter_cache_matcher'
+require 'shoulda/matchers/active_record/association_matchers/inverse_of_matcher'
+require 'shoulda/matchers/active_record/association_matchers/join_table_matcher'
+require 'shoulda/matchers/active_record/association_matchers/order_matcher'
+require 'shoulda/matchers/active_record/association_matchers/through_matcher'
+require 'shoulda/matchers/active_record/association_matchers/dependent_matcher'
+require 'shoulda/matchers/active_record/association_matchers/required_matcher'
+require 'shoulda/matchers/active_record/association_matchers/optional_matcher'
+require 'shoulda/matchers/active_record/association_matchers/source_matcher'
+require 'shoulda/matchers/active_record/association_matchers/model_reflector'
+require 'shoulda/matchers/active_record/association_matchers/model_reflection'
+require 'shoulda/matchers/active_record/association_matchers/option_verifier'
+require 'shoulda/matchers/active_record/have_db_column_matcher'
+require 'shoulda/matchers/active_record/have_db_index_matcher'
+require 'shoulda/matchers/active_record/have_implicit_order_column'
+require 'shoulda/matchers/active_record/have_readonly_attribute_matcher'
+require 'shoulda/matchers/active_record/have_rich_text_matcher'
+require 'shoulda/matchers/active_record/have_secure_token_matcher'
+require 'shoulda/matchers/active_record/serialize_matcher'
+require 'shoulda/matchers/active_record/accept_nested_attributes_for_matcher'
+require 'shoulda/matchers/active_record/define_enum_for_matcher'
+require 'shoulda/matchers/active_record/uniqueness'
+require 'shoulda/matchers/active_record/validate_uniqueness_of_matcher'
+require 'shoulda/matchers/active_record/have_attached_matcher'
module Shoulda
module Matchers
diff --git a/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb b/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb
index 737b0e52a..deaf97037 100644
--- a/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb
+++ b/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb
@@ -158,17 +158,20 @@ def exists?
end
def allow_destroy_correct?
- failure_message = "#{should_or_should_not(@options[:allow_destroy])} allow destroy"
+ failure_message = "#{should_or_should_not(@options[:allow_destroy])}"\
+ ' allow destroy'
verify_option_is_correct(:allow_destroy, failure_message)
end
def limit_correct?
- failure_message = "limit should be #{@options[:limit]}, got #{config[:limit]}"
+ failure_message = "limit should be #{@options[:limit]},"\
+ " got #{config[:limit]}"
verify_option_is_correct(:limit, failure_message)
end
def update_only_correct?
- failure_message = "#{should_or_should_not(@options[:update_only])} be update only"
+ failure_message = "#{should_or_should_not(@options[:update_only])}"\
+ ' be update only'
verify_option_is_correct(:update_only, failure_message)
end
diff --git a/lib/shoulda/matchers/active_record/association_matcher.rb b/lib/shoulda/matchers/active_record/association_matcher.rb
index 5c6a40951..851471ca5 100644
--- a/lib/shoulda/matchers/active_record/association_matcher.rb
+++ b/lib/shoulda/matchers/active_record/association_matcher.rb
@@ -985,6 +985,13 @@ def have_and_belong_to_many(name)
# @private
class AssociationMatcher
+ MACROS = {
+ 'belongs_to' => 'belong to',
+ 'has_many' => 'have many',
+ 'has_one' => 'have one',
+ 'has_and_belongs_to_many' => 'have and belong to many',
+ }.freeze
+
delegate :reflection, :model_class, :associated_class, :through?,
:polymorphic?, to: :reflector
@@ -1128,7 +1135,9 @@ def without_validating_presence
def description
description = "#{macro_description} #{name}"
- description += " class_name => #{options[:class_name]}" if options.key?(:class_name)
+ if options.key?(:class_name)
+ description += " class_name => #{options[:class_name]}"
+ end
[description, submatchers.map(&:description)].flatten.join(' ')
end
@@ -1163,7 +1172,8 @@ def join_table_name
end
def option_verifier
- @option_verifier ||= AssociationMatchers::OptionVerifier.new(reflector)
+ @_option_verifier ||=
+ AssociationMatchers::OptionVerifier.new(reflector)
end
protected
@@ -1171,7 +1181,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)
@@ -1186,16 +1196,7 @@ def remove_submatcher(matcher_class)
end
def macro_description
- case macro.to_s
- when 'belongs_to'
- 'belong to'
- when 'has_many'
- 'have many'
- when 'has_one'
- 'have one'
- when 'has_and_belongs_to_many'
- 'have and belong to many'
- end
+ MACROS[macro.to_s]
end
def expectation
@@ -1215,14 +1216,14 @@ def missing_options
end
def failing_submatchers
- @failing_submatchers ||= submatchers.select do |matcher|
- !matcher.matches?(subject)
+ @_failing_submatchers ||= submatchers.reject do |matcher|
+ matcher.matches?(subject)
end
end
def missing_options_for_failing_submatchers
- if defined?(@failing_submatchers)
- @failing_submatchers.map(&:missing_option)
+ if defined?(@_failing_submatchers)
+ @_failing_submatchers.map(&:missing_option)
else
[]
end
@@ -1252,8 +1253,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
@@ -1282,10 +1283,14 @@ def has_foreign_key_missing?
def class_name_correct?
if options.key?(:class_name)
- if option_verifier.correct_for_constant?(:class_name, options[:class_name])
+ if option_verifier.correct_for_constant?(
+ :class_name,
+ options[:class_name],
+ )
true
else
- @missing = "#{name} should resolve to #{options[:class_name]} for class_name"
+ @missing = "#{name} should resolve to #{options[:class_name]}"\
+ ' for class_name'
false
end
else
@@ -1294,7 +1299,10 @@ def class_name_correct?
end
def join_table_correct?
- if macro != :has_and_belongs_to_many || join_table_matcher.matches?(@subject)
+ if (
+ macro != :has_and_belongs_to_many ||
+ join_table_matcher.matches?(@subject)
+ )
true
else
@missing = join_table_matcher.failure_message
@@ -1303,8 +1311,10 @@ 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?
@@ -1317,10 +1327,14 @@ def class_exists?
def autosave_correct?
if options.key?(:autosave)
- if option_verifier.correct_for_boolean?(:autosave, options[:autosave])
+ if option_verifier.correct_for_boolean?(
+ :autosave,
+ options[:autosave],
+ )
true
else
- @missing = "#{name} should have autosave set to #{options[:autosave]}"
+ @missing = "#{name} should have autosave set to"\
+ " #{options[:autosave]}"
false
end
else
@@ -1333,23 +1347,27 @@ def index_errors_correct?
if option_verifier.correct_for_boolean?(
:index_errors,
- options[:index_errors]
+ options[:index_errors],
)
true
else
@missing =
"#{name} should have index_errors set to " +
- "#{options[:index_errors]}"
+ options[:index_errors].to_s
false
end
end
def conditions_correct?
if options.key?(:conditions)
- if option_verifier.correct_for_relation_clause?(:conditions, options[:conditions])
+ if option_verifier.correct_for_relation_clause?(
+ :conditions,
+ options[:conditions],
+ )
true
else
- @missing = "#{name} should have the following conditions: #{options[:conditions]}"
+ @missing = "#{name} should have the following conditions:" +
+ " #{options[:conditions]}"
false
end
else
@@ -1377,7 +1395,10 @@ def touch_correct?
def class_has_foreign_key?(klass)
if options.key?(:foreign_key)
- option_verifier.correct_for_string?(:foreign_key, options[:foreign_key])
+ option_verifier.correct_for_string?(
+ :foreign_key,
+ options[:foreign_key],
+ )
elsif column_names_for(klass).include?(foreign_key)
true
else
@@ -1388,10 +1409,14 @@ def class_has_foreign_key?(klass)
def primary_key_correct?(klass)
if options.key?(:primary_key)
- if option_verifier.correct_for_string?(:primary_key, options[:primary_key])
+ if option_verifier.correct_for_string?(
+ :primary_key,
+ options[:primary_key],
+ )
true
else
- @missing = "#{klass} does not have a #{options[:primary_key]} primary key"
+ @missing = "#{klass} does not have a #{options[:primary_key]}"\
+ ' primary key'
false
end
else
@@ -1410,8 +1435,14 @@ 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
- associated_class.reflect_on_association(reflection.options[:inverse_of])
+ 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
end
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..b012f8b33 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
@@ -19,7 +19,10 @@ def description
def matches?(subject)
self.subject = ModelReflector.new(subject, name)
- if option_verifier.correct_for_string?(:counter_cache, counter_cache)
+ if option_verifier.correct_for_string?(
+ :counter_cache,
+ counter_cache,
+ )
true
else
self.missing_option = "#{name} should have #{description}"
@@ -32,7 +35,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 973433a01..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
@@ -52,7 +52,7 @@ def generate_missing_option
[
"#{name} should have",
(dependent == true ? 'a' : dependent),
- 'dependency'
+ 'dependency',
].join(' ')
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..a6a1c4031 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?
@@ -26,10 +26,14 @@ def matches?(subject)
def join_table_option_correct?
if options.key?(:join_table_name)
- if option_verifier.correct_for_string?(:join_table, options[:join_table_name])
+ if option_verifier.correct_for_string?(
+ :join_table,
+ options[:join_table_name],
+ )
true
else
- @failure_message = "#{name} should use #{options[:join_table_name].inspect} for :join_table option"
+ @failure_message = "#{name} should use"\
+ " #{options[:join_table_name].inspect} for :join_table option"
false
end
else
@@ -38,7 +42,8 @@ def join_table_option_correct?
end
def join_table_exists?
- if RailsShim.tables_and_views(connection).include?(join_table_name.to_s)
+ if RailsShim.tables_and_views(connection).
+ include?(join_table_name.to_s)
true
else
@failure_message = missing_table_message
@@ -64,8 +69,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..13e41e55f 100644
--- a/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb
+++ b/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb
@@ -26,12 +26,7 @@ def through?
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
-
+ has_and_belongs_to_many_name_table_name || reflection.join_table
join_table_name.to_s
end
@@ -82,9 +77,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 f72ea9a5d..e9a8cc39c 100644
--- a/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb
+++ b/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb
@@ -12,13 +12,13 @@ class ModelReflector
:join_table_name,
:polymorphic?,
:validate_inverse_of_through_association!,
- to: :reflection
+ to: :reflection,
)
delegate(
:through?,
to: :reflection,
- allow_nil: true
+ allow_nil: true,
)
def initialize(subject, name)
@@ -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,12 @@ 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
+ associated_class.where(value)
+ when :order
+ associated_class.order(value)
+ else
+ raise ArgumentError, "Unknown clause '#{name}'"
end
end
@@ -59,7 +62,9 @@ def extract_relation_clause_from(relation, name)
when :conditions
relation.where_values_hash
when :order
- relation.order_values.map { |value| value_as_sql(value) }.join(', ')
+ relation.order_values.map do |value|
+ value_as_sql(value)
+ end.join(', ')
else
raise ArgumentError, "Unknown clause '#{name}'"
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 3ad93b762..7aa641093 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
@@ -40,7 +40,7 @@ def correct_for?(*args)
else
type_cast_expected_value = type_cast(
type,
- expected_value_for(type, name, expected_value)
+ expected_value_for(type, name, expected_value),
)
actual_value = type_cast(type, actual_value_for(name))
type_cast_expected_value == actual_value
@@ -94,7 +94,7 @@ def expected_value_for_relation_clause(name, value)
def expected_value_for_constant(name)
namespace = Shoulda::Matchers::Util.deconstantize(
- reflector.model_class.to_s
+ reflector.model_class.to_s,
)
["#{namespace}::#{name}", name].each do |path|
@@ -107,7 +107,10 @@ def expected_value_for_constant(name)
end
def actual_value_for_relation_clause(name)
- reflector.extract_relation_clause_from(reflector.association_relation, name)
+ reflector.extract_relation_clause_from(
+ reflector.association_relation,
+ name,
+ )
end
def actual_value_for_class_name
diff --git a/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb
index b6ab57557..a471f42ee 100644
--- a/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb
+++ b/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb
@@ -32,9 +32,9 @@ def matches?(subject)
end
missing_option << (
- 'fail validation if ' +
- ":#{attribute_name} is unset; i.e., either the association " +
- 'should have been defined with `optional: ' +
+ 'fail validation if '\
+ ":#{attribute_name} is unset; i.e., either the association "\
+ 'should have been defined with `optional: '\
"#{optional.inspect}`, or there "
)
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/required_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb
index 9a84ebc4c..576c5af5c 100644
--- a/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb
+++ b/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb
@@ -33,9 +33,9 @@ def matches?(subject)
end
missing_option << (
- 'fail validation if ' +
- ":#{attribute_name} is unset; i.e., either the association " +
- 'should have been defined with `required: ' +
+ 'fail validation if '\
+ ":#{attribute_name} is unset; i.e., either the association "\
+ 'should have been defined with `required: '\
"#{required.inspect}`, or there "
)
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..2aa3ab7d4 100644
--- a/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb
+++ b/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb
@@ -22,7 +22,8 @@ def matches?(subject)
if option_verifier.correct_for_string?(:source, source)
true
else
- self.missing_option = "#{name} should have #{source} as source option"
+ self.missing_option =
+ "#{name} should have #{source} as source option"
false
end
end
@@ -32,7 +33,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..f578e85b7 100644
--- a/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb
+++ b/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb
@@ -29,13 +29,14 @@ def through_association_exists?
if through_reflection.present?
true
else
- self.missing_option = "#{name} does not have any relationship to #{through}"
+ self.missing_option =
+ "#{name} does not have any relationship to #{through}"
false
end
end
def through_reflection
- @through_reflection ||= subject.reflect_on_association(through)
+ @_through_reflection ||= subject.reflect_on_association(through)
end
def through_association_correct?
@@ -43,8 +44,9 @@ def through_association_correct?
true
else
self.missing_option =
- "Expected #{name} to have #{name} through #{through}, " +
- "but got it through #{option_verifier.actual_value_for(:through)}"
+ "Expected #{name} to have #{name} through #{through}, "\
+ 'but got it through ' +
+ option_verifier.actual_value_for(:through).to_s
false
end
end
@@ -54,7 +56,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/define_enum_for_matcher.rb b/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb
index 6fd570e01..28f877e9a 100644
--- a/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb
+++ b/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb
@@ -237,7 +237,7 @@ def failure_message
"Expected #{model} to #{expectation}, but "
end
- message << failure_message_continuation + '.'
+ message << "#{failure_message_continuation}."
Shoulda::Matchers.word_wrap(message)
end
@@ -252,7 +252,7 @@ def failure_message_when_negated
attr_reader :attribute_name, :options, :record,
:failure_message_continuation
- def expectation
+ def expectation # rubocop:disable Metrics/MethodLength
if enum_defined?
expectation = "#{simple_description} backed by "
expectation << Shoulda::Matchers::Util.a_or_an(expected_column_type)
@@ -358,8 +358,8 @@ def column_type_matches?
true
else
@failure_message_continuation =
- "However, #{attribute_name.inspect} is " +
- Shoulda::Matchers::Util.a_or_an(column.type) +
+ "However, #{attribute_name.inspect} is "\
+ "#{Shoulda::Matchers::Util.a_or_an(column.type)}"\
' column'
false
end
@@ -421,9 +421,9 @@ def expected_singleton_methods
def expected_prefix
if options.include?(:prefix)
if options[:prefix] == true
- attribute_name#.to_sym
+ attribute_name
else
- options[:prefix]#.to_sym
+ options[:prefix]
end
end
end
@@ -431,9 +431,9 @@ def expected_prefix
def expected_suffix
if options.include?(:suffix)
if options[:suffix] == true
- attribute_name#.to_sym
+ attribute_name
else
- options[:suffix]#.to_sym
+ options[:suffix]
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 e36263573..9b6314da3 100644
--- a/lib/shoulda/matchers/active_record/have_attached_matcher.rb
+++ b/lib/shoulda/matchers/active_record/have_attached_matcher.rb
@@ -134,10 +134,8 @@ 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
@@ -163,10 +161,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..4430e72a4 100644
--- a/lib/shoulda/matchers/active_record/have_db_column_matcher.rb
+++ b/lib/shoulda/matchers/active_record/have_db_column_matcher.rb
@@ -125,13 +125,17 @@ def failure_message_when_negated
def description
desc = "have db column named #{@column}"
- desc << " of type #{@options[:column_type]}" if @options.key?(:column_type)
- desc << " of precision #{@options[:precision]}" if @options.key?(:precision)
- desc << " of limit #{@options[:limit]}" if @options.key?(:limit)
- desc << " of default #{@options[:default]}" if @options.key?(:default)
- desc << " of null #{@options[:null]}" if @options.key?(:null)
- desc << " of primary #{@options[:primary]}" if @options.key?(:primary)
- desc << " of scale #{@options[:scale]}" if @options.key?(:scale)
+ if @options.key?(:column_type)
+ desc << " of type #{@options[:column_type]}"
+ end
+ if @options.key?(:precision)
+ desc << " of precision #{@options[:precision]}"
+ end
+ desc << " of limit #{@options[:limit]}" if @options.key?(:limit)
+ desc << " of default #{@options[:default]}" if @options.key?(:default)
+ desc << " of null #{@options[:null]}" if @options.key?(:null)
+ desc << " of primary #{@options[:primary]}" if @options.key?(:primary)
+ desc << " of scale #{@options[:scale]}" if @options.key?(:scale)
desc
end
@@ -141,7 +145,8 @@ def column_exists?
if model_class.column_names.include?(@column.to_s)
true
else
- @missing = "#{model_class} does not have a db column named #{@column}."
+ @missing =
+ "#{model_class} does not have a db column named #{@column}."
false
end
end
@@ -152,8 +157,9 @@ def correct_column_type?
if matched_column.type.to_s == @options[:column_type].to_s
true
else
- @missing = "#{model_class} has a db column named #{@column} " <<
- "of type #{matched_column.type}, not #{@options[:column_type]}."
+ @missing =
+ "#{model_class} has a db column named #{@column} " <<
+ "of type #{matched_column.type}, not #{@options[:column_type]}."
false
end
end
@@ -229,18 +235,21 @@ 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
def matched_column
@_matched_column ||= begin
- column = model_class.columns.detect { |each| each.name == @column.to_s }
+ column = model_class.columns.detect do |each|
+ each.name == @column.to_s
+ end
DecoratedColumn.new(model_class, column)
end
end
diff --git a/lib/shoulda/matchers/active_record/have_db_index_matcher.rb b/lib/shoulda/matchers/active_record/have_db_index_matcher.rb
index 6cfe5d85b..e302400b3 100644
--- a/lib/shoulda/matchers/active_record/have_db_index_matcher.rb
+++ b/lib/shoulda/matchers/active_record/have_db_index_matcher.rb
@@ -156,7 +156,7 @@ def description
description <<
if qualifiers.include?(:unique)
- Shoulda::Matchers::Util.a_or_an(index_type) + ' '
+ "#{Shoulda::Matchers::Util.a_or_an(index_type)} "
else
'an '
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 4008b9926..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,22 +39,22 @@ 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
def failure_message_when_negated
Shoulda::Matchers.word_wrap(
- "Expected #{model.name} not to #{expectation}, but it did."
+ "Expected #{model.name} not to #{expectation}, but it did.",
)
end
@@ -72,7 +72,7 @@ def check_column_exists!
if !matcher.matches?(@subject)
raise SecondaryCheckFailedError.new(
"The :#{model.table_name} table does not have a " +
- ":#{column_name} column"
+ ":#{column_name} column",
)
end
end
@@ -81,7 +81,7 @@ def check_implicit_order_column_matches!
if model.implicit_order_column.to_s != column_name.to_s
message =
if model.implicit_order_column.nil?
- "implicit_order_column is not set"
+ 'implicit_order_column is not set'
else
"it is :#{model.implicit_order_column}"
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 aec93184b..58465c6e3 100644
--- a/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb
+++ b/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb
@@ -35,17 +35,19 @@ def initialize(attribute)
def matches?(subject)
@subject = subject
if readonly_attributes.include?(@attribute)
- @failure_message_when_negated = "Did not expect #{@attribute} to be read-only"
+ @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 +59,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/have_rich_text_matcher.rb b/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb
index f1f391da4..0a9081fab 100644
--- a/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb
+++ b/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb
@@ -33,7 +33,8 @@ def initialize(rich_text_attribute)
end
def description
- "have configured :#{rich_text_attribute} as a ActionText::RichText association"
+ "have configured :#{rich_text_attribute} as a "\
+ 'ActionText::RichText association'
end
def failure_message
@@ -41,7 +42,8 @@ def failure_message
end
def failure_message_when_negated
- "Did not expect #{subject.class} to have ActionText::RichText :#{rich_text_attribute}"
+ "Did not expect #{subject.class} to have ActionText::RichText"\
+ " :#{rich_text_attribute}"
end
def matches?(subject)
@@ -67,7 +69,9 @@ def has_attribute?
end
def has_expected_action_text?
- @subject.send(rich_text_attribute).class.name == 'ActionText::RichText'
+ defined?(ActionText::RichText) &&
+ @subject.send(rich_text_attribute).
+ instance_of?(ActionText::RichText)
end
def error_description
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 541c886e6..ba76d31e5 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 @@ def description
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/serialize_matcher.rb b/lib/shoulda/matchers/active_record/serialize_matcher.rb
index ca8965b01..e166e8db7 100644
--- a/lib/shoulda/matchers/active_record/serialize_matcher.rb
+++ b/lib/shoulda/matchers/active_record/serialize_matcher.rb
@@ -121,7 +121,9 @@ def failure_message_when_negated
def description
description = "serialize :#{@name}"
- description += " class_name => #{@options[:type]}" if @options.key?(:type)
+ if @options.key?(:type)
+ description += " class_name => #{@options[:type]}"
+ end
description
end
@@ -141,13 +143,12 @@ def class_valid?
klass = serialization_coder
if klass == @options[:type]
true
+ elsif klass.respond_to?(:object_class) &&
+ klass.object_class == @options[:type]
+ true
else
- if klass.respond_to?(:object_class) && klass.object_class == @options[:type]
- true
- else
- @missing = ":#{@name} should be a type of #{@options[:type]}"
- false
- end
+ @missing = ":#{@name} should be a type of #{@options[:type]}"
+ false
end
else
true
@@ -176,9 +177,12 @@ def type_valid?
end
def expectation
- expectation = "#{model_class.name} to serialize the attribute called :#{@name}"
+ expectation = "#{model_class.name} to serialize the attribute called"\
+ " :#{@name}"
expectation += " with a type of #{@options[:type]}" if @options[:type]
- expectation += " with an instance of #{@options[:instance_type]}" if @options[:instance_type]
+ if @options[:instance_type]
+ expectation += " with an instance of #{@options[:instance_type]}"
+ end
expectation
end
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 78f86e345..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
@@ -37,7 +35,7 @@ def model_name_without_namespace
def new_model
@_new_model ||= Model.next_unique_copy_of(
model_name_without_namespace,
- namespace
+ namespace,
)
end
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 6b7f9eb84..0426bced6 100644
--- a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb
+++ b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb
@@ -270,14 +270,14 @@ def initialize(attribute)
super(attribute)
@expected_message = :taken
@options = {
- case_sensitivity_strategy: :sensitive
+ case_sensitivity_strategy: :sensitive,
}
@existing_record_created = false
@failure_reason = nil
@failure_reason_when_negated = nil
@attribute_setters = {
existing_record: AttributeSetters.new,
- new_record: AttributeSetters.new
+ new_record: AttributeSetters.new,
}
end
@@ -413,11 +413,12 @@ 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 '
@@ -461,7 +462,7 @@ def inspected_expected_scopes
def inspected_actual_scopes
inspected_actual_sets_of_scopes.to_sentence(
words_connector: ' and ',
- last_word_connector: ', and'
+ last_word_connector: ', and',
)
end
@@ -497,7 +498,9 @@ def matches_allow_nil?
def does_not_match_allow_nil?
expects_to_allow_nil? && (
update_existing_record!(nil) &&
- (@failure_reason = nil || disallows_value_of(nil, @expected_message))
+ (@failure_reason = nil ||
+ disallows_value_of(nil, @expected_message)
+ )
)
end
@@ -533,21 +536,15 @@ def find_or_create_existing_record
end
def find_existing_record
- record = model.first
-
- if record.present?
- record
- else
- nil
- end
+ model.first.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)
@@ -583,7 +580,7 @@ def build_new_record
attribute_names_under_test.each do |attribute_name|
set_attribute_on_new_record!(
attribute_name,
- existing_record.public_send(attribute_name)
+ existing_record.public_send(attribute_name),
)
end
@@ -625,11 +622,12 @@ 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}."
@@ -649,11 +647,12 @@ 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}."
@@ -664,14 +663,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
@@ -703,7 +702,7 @@ def matches_uniqueness_with_case_sensitivity_strategy?
raise NonCaseSwappableValueError.create(
model: model,
attribute: @attribute,
- value: value
+ value: value,
)
end
@@ -730,7 +729,7 @@ def does_not_match_uniqueness_with_case_sensitivity_strategy?
raise NonCaseSwappableValueError.create(
model: model,
attribute: @attribute,
- value: value
+ value: value,
)
end
@@ -795,7 +794,7 @@ def dummy_value_for(scope)
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 +806,7 @@ def dummy_scalar_value_for(column)
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
@@ -863,7 +862,7 @@ def set_attribute_on!(record_type, record, attribute_name, value)
attribute_setter = build_attribute_setter(
record,
attribute_name,
- value
+ value,
)
attribute_setter.set!
@@ -875,7 +874,7 @@ def set_attribute_on_existing_record!(attribute_name, value)
:existing_record,
existing_record,
attribute_name,
- value
+ value,
)
end
@@ -884,7 +883,7 @@ def set_attribute_on_new_record!(attribute_name, value)
:new_record,
new_record,
attribute_name,
- value
+ value,
)
end
@@ -902,13 +901,14 @@ def attribute_names_under_test
end
def build_attribute_setter(record, attribute_name, value)
- Shoulda::Matchers::ActiveModel::AllowValueMatcher::AttributeSetter.new(
- matcher_name: :validate_uniqueness_of,
- object: record,
- attribute_name: attribute_name,
- value: value,
- ignore_interference_by_writer: ignore_interference_by_writer
- )
+ Shoulda::Matchers::ActiveModel::AllowValueMatcher::AttributeSetter.
+ new(
+ matcher_name: :validate_uniqueness_of,
+ object: record,
+ attribute_name: attribute_name,
+ value: value,
+ ignore_interference_by_writer: ignore_interference_by_writer,
+ )
end
def existing_value_read
@@ -935,7 +935,7 @@ def model
@given_record.class
end
- def failure_message_preface
+ def failure_message_preface # rubocop:disable Metrics/MethodLength
prefix = ''
if @existing_record_created
@@ -944,30 +944,28 @@ def failure_message_preface
if attribute_setter_for_existing_record
prefix << ', setting '
prefix << description_for_attribute_setter(
- attribute_setter_for_existing_record
+ attribute_setter_for_existing_record,
)
else
prefix << ", whose :#{attribute} is "
prefix << "‹#{existing_value_read.inspect}›"
end
- prefix << ", and saving it as the existing record, then"
+ prefix << ', and saving it as the existing record, then'
+ elsif attribute_setter_for_existing_record
+ prefix << "Given an existing #{model.name},"
+ prefix << ' after setting '
+ prefix << description_for_attribute_setter(
+ attribute_setter_for_existing_record,
+ )
+ prefix << ', then'
else
- if attribute_setter_for_existing_record
- prefix << "Given an existing #{model.name},"
- prefix << ' after setting '
- prefix << description_for_attribute_setter(
- attribute_setter_for_existing_record
- )
- prefix << ', then'
- else
- prefix << "Given an existing #{model.name} whose :#{attribute}"
- prefix << ' is '
- prefix << Shoulda::Matchers::Util.inspect_value(
- existing_value_read
- )
- prefix << ', after'
- end
+ prefix << "Given an existing #{model.name} whose :#{attribute}"
+ prefix << ' is '
+ prefix << Shoulda::Matchers::Util.inspect_value(
+ existing_value_read,
+ )
+ prefix << ', after'
end
prefix << " making a new #{model.name} and setting "
@@ -994,7 +992,10 @@ def attribute_changed_value_message
MESSAGE
end
- def description_for_attribute_setter(attribute_setter, same_as_existing: nil)
+ def description_for_attribute_setter(
+ attribute_setter,
+ same_as_existing: nil
+ )
description = "its :#{attribute_setter.attribute_name} to "
if same_as_existing == false
@@ -1002,13 +1003,13 @@ def description_for_attribute_setter(attribute_setter, same_as_existing: nil)
end
description << Shoulda::Matchers::Util.inspect_value(
- attribute_setter.value_written
+ attribute_setter.value_written,
)
if attribute_setter.attribute_changed_value?
description << ' (read back as '
description << Shoulda::Matchers::Util.inspect_value(
- attribute_setter.value_read
+ attribute_setter.value_read,
)
description << ')'
end
@@ -1032,7 +1033,7 @@ def attribute_setter_descriptions_for_new_record
)
description_for_attribute_setter(
attribute_setter,
- same_as_existing: same_as_existing
+ same_as_existing: same_as_existing,
)
end
end
diff --git a/lib/shoulda/matchers/doublespeak.rb b/lib/shoulda/matchers/doublespeak.rb
index e09b0082a..d90ade50e 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
+ puts block.call # rubocop:disable Rails/Output
end
end
end
diff --git a/lib/shoulda/matchers/doublespeak/double.rb b/lib/shoulda/matchers/doublespeak/double.rb
index 13fbbbf8a..f8f3b6667 100644
--- a/lib/shoulda/matchers/doublespeak/double.rb
+++ b/lib/shoulda/matchers/doublespeak/double.rb
@@ -82,7 +82,7 @@ def replace_method_with_double
method_name: _method_name,
args: args,
block: block,
- caller: caller
+ caller: caller,
)
implementation.call(call)
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..90b3cdc73 100644
--- a/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb
+++ b/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb
@@ -4,23 +4,26 @@ module Doublespeak
# @private
module DoubleImplementationRegistry
class << self
- REGISTRY = {}
-
def find(type)
find_class!(type).create
end
def register(klass, type)
- REGISTRY[type] = klass
+ registry[type] = klass
end
private
def find_class!(type)
- REGISTRY.fetch(type) do
- raise ArgumentError, "No double implementation class found for '#{type}'"
+ registry.fetch(type) do
+ raise ArgumentError, 'No double implementation class found for'\
+ " '#{type}'"
end
end
+
+ def registry
+ @_registry ||= {}
+ end
end
end
end
diff --git a/lib/shoulda/matchers/doublespeak/object_double.rb b/lib/shoulda/matchers/doublespeak/object_double.rb
index 17b27af43..03a5fbb8b 100644
--- a/lib/shoulda/matchers/doublespeak/object_double.rb
+++ b/lib/shoulda/matchers/doublespeak/object_double.rb
@@ -27,7 +27,7 @@ def method_missing(method_name, *args, &block)
method_name: method_name,
args: args,
block: block,
- caller: ::Kernel.caller
+ caller: ::Kernel.caller,
)
calls << call
(calls_by_method_name[method_name] ||= []) << call
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/error.rb b/lib/shoulda/matchers/error.rb
index e2b9f6b57..08d3bd6f8 100644
--- a/lib/shoulda/matchers/error.rb
+++ b/lib/shoulda/matchers/error.rb
@@ -18,7 +18,7 @@ def initialize(*args)
end
def message
- ""
+ ''
end
def inspect
diff --git a/lib/shoulda/matchers/independent/delegate_method_matcher.rb b/lib/shoulda/matchers/independent/delegate_method_matcher.rb
index 31fd52319..5948188ec 100644
--- a/lib/shoulda/matchers/independent/delegate_method_matcher.rb
+++ b/lib/shoulda/matchers/independent/delegate_method_matcher.rb
@@ -219,9 +219,9 @@ def description
end
if expects_to_allow_nil_delegate_object?
- string << ", allowing "
+ string << ', allowing '
string << formatted_delegate_object_reader_method_name
- string << " to return nil"
+ string << ' to return nil'
end
string
@@ -245,7 +245,7 @@ def with_arguments(*arguments)
def with_prefix(prefix = nil)
@delegating_method =
:"#{build_delegating_method_prefix(prefix)}_#{delegate_method}"
- delegate_method
+ delegate_method
self
end
@@ -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
@@ -344,7 +344,7 @@ def possible_class_under_test(options)
if options[:include_module]
class_under_test.to_s
else
- ""
+ ''
end
end
@@ -398,11 +398,12 @@ 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
@@ -439,17 +440,17 @@ def calls_on_delegate_object
end
def formatted_calls_on_delegate_object
- string = ""
+ string = ''
if calls_on_delegate_object.any?
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(', ')
- string << "#{i+1}) #{name}(#{args})\n"
+ args = call.args.map(&:inspect).join(', ')
+ string << "#{i + 1}) #{name}(#{args})\n"
end
else
- string << " (none)"
+ string << ' (none)'
end
string.rstrip!
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..013832e0e 100644
--- a/lib/shoulda/matchers/integrations/libraries/action_controller.rb
+++ b/lib/shoulda/matchers/integrations/libraries/action_controller.rb
@@ -13,7 +13,7 @@ def integrate_with(test_framework)
test_framework.include(matchers_module, type: :controller)
include_into(::ActionController::TestCase, matchers_module) do
- def subject
+ def subject # rubocop:disable Lint/NestedMethodDefinition
@controller
end
end
diff --git a/lib/shoulda/matchers/integrations/libraries/rails.rb b/lib/shoulda/matchers/integrations/libraries/rails.rb
index 6deade234..380c59d19 100644
--- a/lib/shoulda/matchers/integrations/libraries/rails.rb
+++ b/lib/shoulda/matchers/integrations/libraries/rails.rb
@@ -12,8 +12,8 @@ class Rails
:active_model,
:active_record,
:action_controller,
- :routing
- ]
+ :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 90dce71e7..532e3d22c 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
@@ -9,7 +9,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 1351b8afe..1d5b30b2c 100644
--- a/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb
+++ b/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb
@@ -9,7 +9,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 14553fd9e..92674ca47 100644
--- a/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb
+++ b/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb
@@ -10,7 +10,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/missing_test_framework.rb b/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb
index 0a5f8c55d..13d51db2a 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 @@ def validate!
with.test_framework :test_unit
end
end
-EOT
+ EOT
end
def include(*modules, **options)
diff --git a/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb b/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb
index 951c1df55..1f2e52f95 100644
--- a/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb
+++ b/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb
@@ -9,7 +9,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..b426b575a 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)
@@ -180,10 +180,12 @@ def simply_generate_validation_message(
options
)
default_translation_keys = [
- :"activemodel.errors.models.#{model_name}.attributes.#{attribute}.#{type}",
+ :"activemodel.errors.models.#{model_name}.attributes.#{attribute}
+ .#{type}",
:"activemodel.errors.models.#{model_name}.#{type}",
:"activemodel.errors.messages.#{type}",
- :"activerecord.errors.models.#{model_name}.attributes.#{attribute}.#{type}",
+ :"activerecord.errors.models.#{model_name}.attributes.#{attribute}
+ .#{type}",
:"activerecord.errors.models.#{model_name}.#{type}",
:"activerecord.errors.messages.#{type}",
:"errors.attributes.#{attribute}.#{type}",
diff --git a/lib/shoulda/matchers/util.rb b/lib/shoulda/matchers/util.rb
index 3f84fbbdf..46d512637 100644
--- a/lib/shoulda/matchers/util.rb
+++ b/lib/shoulda/matchers/util.rb
@@ -7,8 +7,10 @@ module Util
MAXIMUM_LENGTH_OF_VALUE_TO_DISPLAY = 500
def self.deconstantize(path)
- if defined?(ActiveSupport::Inflector) &&
+ if (
+ defined?(ActiveSupport::Inflector) &&
ActiveSupport::Inflector.respond_to?(:deconstantize)
+ )
ActiveSupport::Inflector.deconstantize(path)
else
path.to_s[0...(path.to_s.rindex('::') || 0)]
@@ -16,8 +18,10 @@ def self.deconstantize(path)
end
def self.safe_constantize(camel_cased_word)
- if defined?(ActiveSupport::Inflector) &&
+ if (
+ defined?(ActiveSupport::Inflector) &&
ActiveSupport::Inflector.respond_to?(:safe_constantize)
+ )
ActiveSupport::Inflector.safe_constantize(camel_cased_word)
else
begin
@@ -30,6 +34,7 @@ def self.safe_constantize(camel_cased_word)
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 5962e0167..79badecb2 100644
--- a/lib/shoulda/matchers/util/word_wrap.rb
+++ b/lib/shoulda/matchers/util/word_wrap.rb
@@ -41,10 +41,10 @@ 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[ ]+/
+ self =~ /\A +/
end
def list_item?
@@ -88,11 +88,11 @@ 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
- combined_lines.last << (' ' + line).squeeze(' ')
+ combined_lines.last << (" #{line}").squeeze(' ')
end
combined_lines
@@ -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)
index = nil
if line.length > Shoulda::Matchers::WordWrap::TERMINAL_WIDTH
@@ -185,7 +185,7 @@ def wrap_line(line, direction: :left)
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/lib/shoulda/matchers/warn.rb b/lib/shoulda/matchers/warn.rb
index b0f45af39..174df9570 100644
--- a/lib/shoulda/matchers/warn.rb
+++ b/lib/shoulda/matchers/warn.rb
@@ -5,13 +5,13 @@ module Matchers
# @private
def self.warn(message)
- header = "Warning from shoulda-matchers:"
- divider = "*" * TERMINAL_MAX_WIDTH
+ header = 'Warning from shoulda-matchers:'
+ divider = '*' * TERMINAL_MAX_WIDTH
wrapped_message = word_wrap(message)
full_message = [
divider,
[header, wrapped_message.strip].join("\n\n"),
- divider
+ divider,
].join("\n")
Kernel.warn(full_message)
diff --git a/script/supported_ruby_versions b/script/supported_ruby_versions
index 003e2b1c7..1b0fc6ce5 100755
--- a/script/supported_ruby_versions
+++ b/script/supported_ruby_versions
@@ -2,6 +2,6 @@
require 'yaml'
-travis_config_path = File.expand_path('../../.travis.yml', __FILE__)
+travis_config_path = File.expand_path('../.travis.yml', __dir__)
travis_config = YAML.load_file(travis_config_path)
puts travis_config.fetch('rvm').join(' ')
diff --git a/shoulda-matchers.gemspec b/shoulda-matchers.gemspec
index f61d76412..a02bb3877 100644
--- a/shoulda-matchers.gemspec
+++ b/shoulda-matchers.gemspec
@@ -18,8 +18,13 @@ 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.metadata = {
+ s.description = <<~DESC.tr("\n", ' ').squeeze(' ')
+ 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.
+ DESC
+
+ s.metadata = {
'bug_tracker_uri' => 'https://github.com/thoughtbot/shoulda-matchers/issues',
'changelog_uri' => 'https://github.com/thoughtbot/shoulda-matchers/blob/master/CHANGELOG.md',
'documentation_uri' => 'https://matchers.shoulda.io/docs',
@@ -27,7 +32,8 @@ Gem::Specification.new do |s|
'source_code_uri' => 'https://github.com/thoughtbot/shoulda-matchers',
}
- s.files = Dir['{docs,lib}/**/*', 'README.md', 'LICENSE', 'shoulda-matchers.gemspec']
+ s.files = Dir['{docs,lib}/**/*', 'README.md', 'LICENSE',
+ 'shoulda-matchers.gemspec']
s.require_paths = ['lib']
s.required_ruby_version = '>= 2.4.0'
diff --git a/spec/acceptance_spec_helper.rb b/spec/acceptance_spec_helper.rb
index f1022c79c..b3b38f211 100644
--- a/spec/acceptance_spec_helper.rb
+++ b/spec/acceptance_spec_helper.rb
@@ -8,7 +8,7 @@
require 'spec_helper'
-Dir[ File.join(File.expand_path('../support/acceptance/**/*.rb', __FILE__)) ].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/spec_helper.rb b/spec/spec_helper.rb
index b7f73972b..1b0bd9de8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,4 +1,4 @@
-PROJECT_ROOT = File.expand_path('../..', __FILE__)
+PROJECT_ROOT = File.expand_path('..', __dir__)
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
require 'pry'
diff --git a/spec/support/acceptance/adds_shoulda_matchers_to_project.rb b/spec/support/acceptance/adds_shoulda_matchers_to_project.rb
index c684e1962..cfab02501 100644
--- a/spec/support/acceptance/adds_shoulda_matchers_to_project.rb
+++ b/spec/support/acceptance/adds_shoulda_matchers_to_project.rb
@@ -43,7 +43,7 @@ def configure_test_helper_files
add_configuration_block_to(
test_helper_file,
test_framework,
- library
+ library,
)
end
end
@@ -94,16 +94,17 @@ def test_helper_files_for(test_framework, libraries)
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
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 +119,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/array_helpers.rb b/spec/support/acceptance/helpers/array_helpers.rb
index e9d3b2eb5..3f1444a6e 100644
--- a/spec/support/acceptance/helpers/array_helpers.rb
+++ b/spec/support/acceptance/helpers/array_helpers.rb
@@ -1,9 +1,10 @@
module AcceptanceTests
module ArrayHelpers
def to_sentence(array)
- if array.size == 1
+ case array.size
+ when 1
array[0]
- elsif array.size == 2
+ when 2
array.join(' and ')
else
to_sentence(array[1..-2].join(', '), [array[-1]])
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/pluralization_helpers.rb b/spec/support/acceptance/helpers/pluralization_helpers.rb
index 9aacd7ae8..a8af3f1ca 100644
--- a/spec/support/acceptance/helpers/pluralization_helpers.rb
+++ b/spec/support/acceptance/helpers/pluralization_helpers.rb
@@ -1,7 +1,7 @@
module AcceptanceTests
module PluralizationHelpers
def pluralize(count, singular_version, plural_version = nil)
- plural_version ||= singular_version + 's'
+ plural_version ||= "#{singular_version}s"
if count == 1
"#{count} #{singular_version}"
diff --git a/spec/support/acceptance/helpers/step_helpers.rb b/spec/support/acceptance/helpers/step_helpers.rb
index 35898eb4e..49111244b 100644
--- a/spec/support/acceptance/helpers/step_helpers.rb
+++ b/spec/support/acceptance/helpers/step_helpers.rb
@@ -58,11 +58,12 @@ 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/have_output.rb b/spec/support/acceptance/matchers/have_output.rb
index 4f8e60e00..8bf5bb542 100644
--- a/spec/support/acceptance/matchers/have_output.rb
+++ b/spec/support/acceptance/matchers/have_output.rb
@@ -15,10 +15,10 @@ def matches?(runner)
end
def failure_message
- "Expected command to have output, but did not.\n\n" +
- "Command: #{runner.formatted_command}\n\n" +
+ "Expected command to have output, but did not.\n\n"\
+ "Command: #{runner.formatted_command}\n\n"\
"Expected output:\n" +
- output.inspect + "\n\n" +
+ output.inspect + "\n\n"\
"Actual output:\n" +
runner.output
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 7ca88c8ff..f6ffe98cf 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,13 +22,14 @@ def matches?(runner)
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)'
- 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
@@ -48,7 +49,7 @@ def actual_output
end
def some_tests_were_run
- pluralize(number, 'test was', 'tests were') + ' run'
+ "#{pluralize(number, 'test was', 'tests were')} run"
end
end
end
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 f84884312..307896157 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
@@ -39,7 +39,7 @@ def expected_outputs
[
expected_output_for_rails_3,
expected_output_for_turn,
- expected_output_for_rails_4
+ expected_output_for_rails_4,
]
end
@@ -61,7 +61,7 @@ def expected_output_for_rails_3
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
@@ -75,7 +75,7 @@ def formatted_expected_output
if matching_expected_output
"Expected output:\n#{matching_actual_output}"
else
- "Expected output: (n/a)"
+ 'Expected output: (n/a)'
end
end
@@ -85,7 +85,7 @@ def actual_output
def formatted_actual_output
if actual_output.empty?
- "Actual output: (empty)"
+ 'Actual output: (empty)'
else
"Actual output:\n#{actual_output}"
end
diff --git a/spec/support/tests/bundle.rb b/spec/support/tests/bundle.rb
index 5042c9100..7bde94c56 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
if already_updating?
yield self
return
@@ -35,7 +35,7 @@ def add_gem(gem, *args)
def remove_gem(gem)
updating do
- fs.comment_lines_matching('Gemfile', /^[ ]*gem ("|')#{gem}\1/)
+ fs.comment_lines_matching('Gemfile', /^ *gem ("|')#{gem}\1/)
end
end
diff --git a/spec/support/tests/command_runner.rb b/spec/support/tests/command_runner.rb
index fbb27bcba..000f8cbdb 100644
--- a/spec/support/tests/command_runner.rb
+++ b/spec/support/tests/command_runner.rb
@@ -30,11 +30,11 @@ def initialize(*args)
@args = args
@options = options.merge(
err: [:child, :out],
- out: writer
+ out: writer,
)
@env = extract_env_from(@options)
- @wrapper = ->(block) { block.call }
+ @wrapper = -> (block) { block.call }
@command_prefix = ''
self.directory = Dir.pwd
@run_quickly = false
@@ -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
@@ -179,7 +177,7 @@ def run_with_debugging
run_with_wrapper
- debug { "\n" + divider('START') + output + divider('END') }
+ debug { "\n#{divider('START')}#{output}#{divider('END')}" }
end
def possibly_running_quickly(&block)
@@ -190,7 +188,7 @@ def possibly_running_quickly(&block)
stop
message =
- "Command timed out after #{timeout} seconds: #{formatted_command}\n" +
+ "Command timed out after #{timeout} seconds: #{formatted_command}\n"\
"Output:\n" +
output
@@ -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 80a08cd95..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
@@ -40,7 +40,7 @@ def available_appraisals
def current_appraisal
if appraisal_in_use?
- File.basename(path, ".gemfile")
+ File.basename(path, '.gemfile')
end
end
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..c1bc215be 100644
--- a/spec/support/tests/filesystem.rb
+++ b/spec/support/tests/filesystem.rb
@@ -63,14 +63,14 @@ 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") }
+ open(path, 'a') { |f| f.puts("#{content}\n") } # rubocop: disable Security/Open
end
def remove_from_file(path, pattern)
unless pattern.is_a?(Regexp)
- pattern = Regexp.new('^' + Regexp.escape(pattern) + '$')
+ pattern = Regexp.new("^#{Regexp.escape(pattern)}$")
end
transform(path) do |lines|
@@ -94,7 +94,7 @@ def transform(path)
content = read(path)
lines = content.split(/\n/)
transformed_lines = yield lines
- write(path, transformed_lines.join("\n") + "\n")
+ write(path, "#{transformed_lines.join("\n")}\n")
end
end
end
diff --git a/spec/support/tests/version.rb b/spec/support/tests/version.rb
index 4a2a66e4e..fe4baf01d 100644
--- a/spec/support/tests/version.rb
+++ b/spec/support/tests/version.rb
@@ -1,7 +1,7 @@
module Tests
class Version
def initialize(version)
- @version = Gem::Version.new(version.to_s + '')
+ @version = Gem::Version.new(version.to_s)
end
def <(other_version)
@@ -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/active_record/create_table.rb b/spec/support/unit/active_record/create_table.rb
index 9fea462cf..a80ac444e 100644
--- a/spec/support/unit/active_record/create_table.rb
+++ b/spec/support/unit/active_record/create_table.rb
@@ -36,14 +36,14 @@ def call
UnitTests::ModelBuilder.create_table(
table_name,
connection: connection,
- id: false
+ id: false,
) do |table|
add_columns_to_table(table)
end
else
UnitTests::ModelBuilder.create_table(
table_name,
- connection: connection
+ connection: connection,
) do |table|
add_columns_to_table(table)
end
@@ -102,16 +102,16 @@ def add_column_to_table(table, column_name, column_specification)
if column_options[:array]
if !active_record_supports_array_columns?
raise ArgumentError.new(
- 'An array column is being added to a table, but this version ' +
- "of ActiveRecord (#{active_record_version}) " +
+ 'An array column is being added to a table, but this version '\
+ "of ActiveRecord (#{active_record_version}) "\
'does not support array columns.',
)
end
if !database_supports_array_columns?
raise ArgumentError.new(
- 'An array column is being added to a table, but this ' +
- "database adapter (#{database_adapter}) " +
+ 'An array column is being added to a table, but this '\
+ "database adapter (#{database_adapter}) "\
'does not support array columns.',
)
end
@@ -119,8 +119,8 @@ def add_column_to_table(table, column_name, column_specification)
if column_specification.any?
raise ArgumentError.new(
- "Invalid column specification.\nYou need to put " +
- "#{column_specification.keys.map(&:inspect).to_sentence} " +
+ "Invalid column specification.\nYou need to put "\
+ "#{column_specification.keys.map(&:inspect).to_sentence} "\
'inside an :options key!',
)
end
diff --git a/spec/support/unit/attribute.rb b/spec/support/unit/attribute.rb
index 21f6cb116..f3e8ad49f 100644
--- a/spec/support/unit/attribute.rb
+++ b/spec/support/unit/attribute.rb
@@ -3,8 +3,8 @@ class Attribute
DEFAULT_COLUMN_TYPE = :string
DEFAULT_COLUMN_OPTIONS = {
null: false,
- array: false
- }
+ array: false,
+ }.freeze
def initialize(args)
@args = args
@@ -21,7 +21,7 @@ def column_type
def column_options
{
type: column_type,
- options: DEFAULT_COLUMN_OPTIONS.merge(args.fetch(:column_options, {}))
+ options: DEFAULT_COLUMN_OPTIONS.merge(args.fetch(:column_options, {})),
}
end
diff --git a/spec/support/unit/capture.rb b/spec/support/unit/capture.rb
index a5879954f..ecdbde106 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)
@@ -41,6 +41,6 @@ def silence_stream(stream)
end
def silence_stderr
- silence_stream(STDERR) { yield }
+ silence_stream($stderr) { yield if block_given? }
end
end
diff --git a/spec/support/unit/change_value.rb b/spec/support/unit/change_value.rb
index 404fc6869..dca61ab2c 100644
--- a/spec/support/unit/change_value.rb
+++ b/spec/support/unit/change_value.rb
@@ -85,7 +85,7 @@ def always_nil
end
def add_character
- value + 'a'
+ "#{value}a"
end
def remove_character
diff --git a/spec/support/unit/create_model_arguments/basic.rb b/spec/support/unit/create_model_arguments/basic.rb
index 7c0c4c789..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
@@ -22,7 +22,7 @@ def self.wrap(args)
:column_type,
:column_options,
:default_value,
- :value_type
+ :value_type,
)
def initialize(args)
@@ -61,7 +61,7 @@ def all_attribute_overrides
@_all_attribute_overrides ||= begin
attribute_overrides = args.slice(
:changing_values_with,
- :default_value
+ :default_value,
)
overrides =
@@ -127,7 +127,7 @@ def map_matcher_name_to_validation_name
def attribute_args
args.slice(:column_type).deep_merge(
- attribute_overrides.deep_merge(name: attribute_name)
+ attribute_overrides.deep_merge(name: attribute_name),
)
end
end
diff --git a/spec/support/unit/create_model_arguments/uniqueness_matcher.rb b/spec/support/unit/create_model_arguments/uniqueness_matcher.rb
index e26913465..c3fe9b5c7 100644
--- a/spec/support/unit/create_model_arguments/uniqueness_matcher.rb
+++ b/spec/support/unit/create_model_arguments/uniqueness_matcher.rb
@@ -16,12 +16,12 @@ 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,
- options: attribute.column_options
- }
+ options: attribute.column_options,
+ },
)
end
end
@@ -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
@@ -54,13 +54,13 @@ def scope_attribute_names
def scope_attributes
@_scope_attributes ||= self.class.normalize_attributes(
- args.fetch(:scopes, [])
+ args.fetch(:scopes, []),
)
end
def additional_attributes
@_additional_attributes ||= self.class.normalize_attributes(
- args.fetch(:additional_attributes, [])
+ args.fetch(:additional_attributes, []),
)
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/confirmation_matcher_helpers.rb b/spec/support/unit/helpers/confirmation_matcher_helpers.rb
index 70933203c..433a09be1 100644
--- a/spec/support/unit/helpers/confirmation_matcher_helpers.rb
+++ b/spec/support/unit/helpers/confirmation_matcher_helpers.rb
@@ -9,8 +9,9 @@ def builder_for_record_validating_confirmation(options = {})
def builder_for_record_validating_confirmation_with_18n_message(options = {})
builder = builder_for_record_validating_confirmation(options)
- RecordBuilderWithI18nValidationMessage.new(builder,
- validation_message_key: :confirmation
+ RecordBuilderWithI18nValidationMessage.new(
+ builder,
+ validation_message_key: :confirmation,
)
end
end
diff --git a/spec/support/unit/helpers/controller_builder.rb b/spec/support/unit/helpers/controller_builder.rb
index e5e651a89..544b38ae0 100644
--- a/spec/support/unit/helpers/controller_builder.rb
+++ b/spec/support/unit/helpers/controller_builder.rb
@@ -27,7 +27,7 @@ def build_fake_response(opts = {}, &block)
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/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/message_helpers.rb b/spec/support/unit/helpers/message_helpers.rb
index 67203387d..ce6a470be 100644
--- a/spec/support/unit/helpers/message_helpers.rb
+++ b/spec/support/unit/helpers/message_helpers.rb
@@ -10,7 +10,7 @@ def format_message(message, one_line: false)
stripped_message = message.strip_heredoc.strip
if one_line
- stripped_message.tr("\n", " ").squeeze(" ")
+ stripped_message.tr("\n", ' ').squeeze(' ')
else
word_wrap(stripped_message)
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/helpers/validation_matcher_scenario_helpers.rb b/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb
index 8e5579a9f..84e302186 100644
--- a/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb
+++ b/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb
@@ -6,7 +6,7 @@ def self.configure_example_group(example_group)
def build_scenario_for_validation_matcher(args)
UnitTests::ValidationMatcherScenario.new(
- build_validation_matcher_scenario_args(args)
+ build_validation_matcher_scenario_args(args),
)
end
@@ -27,7 +27,7 @@ def build_validation_matcher_scenario_args(args)
deep_merge(validation_matcher_scenario_args).
deep_merge(
matcher_name: matcher_name,
- matcher_proc: method(matcher_name)
+ matcher_proc: method(matcher_name),
)
end
diff --git a/spec/support/unit/matchers/deprecate.rb b/spec/support/unit/matchers/deprecate.rb
index 37527b637..08ccf88a3 100644
--- a/spec/support/unit/matchers/deprecate.rb
+++ b/spec/support/unit/matchers/deprecate.rb
@@ -50,7 +50,7 @@ def expectation
def actual_warning
if captured_stderr.empty?
- "nothing"
+ 'nothing'
else
"\n #{captured_stderr}"
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/matchers/match_against.rb b/spec/support/unit/matchers/match_against.rb
index 76cf1ee46..1d761c089 100644
--- a/spec/support/unit/matchers/match_against.rb
+++ b/spec/support/unit/matchers/match_against.rb
@@ -48,7 +48,7 @@ def matches?(generate_matcher)
if expected_message && should_be_negated?
raise ArgumentError.new(
- 'Use `or_fail_with`, not `and_fail_with`, when using ' +
+ 'Use `or_fail_with`, not `and_fail_with`, when using '\
'`should match_against(...)`!',
)
end
@@ -73,7 +73,7 @@ def does_not_match?(generate_matcher)
if expected_message && !should_be_negated?
raise ArgumentError.new(
- 'Use `and_fail_with`, not `or_fail_with`, when using ' +
+ 'Use `and_fail_with`, not `or_fail_with`, when using '\
'`should_not match_against(...)`!',
)
end
@@ -148,7 +148,7 @@ def matcher_fails_in_negative?
end
else
@failure_message =
- 'Expected the negative version of the matcher not to match, ' +
+ 'Expected the negative version of the matcher not to match, '\
'but it did.'
false
end
@@ -198,7 +198,7 @@ def matcher_fails_in_positive?
end
else
@failure_message_when_negated =
- 'Expected the positive version of the matcher not to match, ' +
+ 'Expected the positive version of the matcher not to match, '\
'but it did.'
false
end
diff --git a/spec/support/unit/model_creation_strategies/active_model.rb b/spec/support/unit/model_creation_strategies/active_model.rb
index 45b5f7550..163356a9a 100644
--- a/spec/support/unit/model_creation_strategies/active_model.rb
+++ b/spec/support/unit/model_creation_strategies/active_model.rb
@@ -104,10 +104,10 @@ 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(' '),
+ " #{inspected_attributes.join(' ')}",
]
"#<#{middle.strip}>"
diff --git a/spec/support/unit/model_creation_strategies/active_record.rb b/spec/support/unit/model_creation_strategies/active_record.rb
index 54dcc37ef..a98dd8d02 100644
--- a/spec/support/unit/model_creation_strategies/active_record.rb
+++ b/spec/support/unit/model_creation_strategies/active_record.rb
@@ -43,7 +43,7 @@ def create_table_for_model
def define_class_for_model
model = UnitTests::ModelBuilder.define_model_class(
class_name,
- parent_class: parent_class
+ parent_class: parent_class,
)
model_customizers.each do |block|
diff --git a/spec/support/unit/model_creators/active_model.rb b/spec/support/unit/model_creators/active_model.rb
index dd0d68012..eae21a059 100644
--- a/spec/support/unit/model_creators/active_model.rb
+++ b/spec/support/unit/model_creators/active_model.rb
@@ -19,8 +19,8 @@ def self.call(args)
def initialize(args)
@arguments = CreateModelArguments::Basic.wrap(
args.merge(
- model_creation_strategy: UnitTests::ModelCreationStrategies::ActiveModel
- )
+ model_creation_strategy: UnitTests::ModelCreationStrategies::ActiveModel,
+ ),
)
@model_creator = Basic.new(arguments)
end
diff --git a/spec/support/unit/model_creators/active_record.rb b/spec/support/unit/model_creators/active_record.rb
index 23898a196..77708134f 100644
--- a/spec/support/unit/model_creators/active_record.rb
+++ b/spec/support/unit/model_creators/active_record.rb
@@ -22,8 +22,8 @@ def self.call(args)
def initialize(args)
@arguments = CreateModelArguments::Basic.wrap(
args.merge(
- model_creation_strategy: UnitTests::ModelCreationStrategies::ActiveRecord
- )
+ model_creation_strategy: UnitTests::ModelCreationStrategies::ActiveRecord,
+ ),
)
@model_creator = Basic.new(arguments)
end
diff --git a/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb b/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb
index 267c0a662..35f935809 100644
--- a/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb
+++ b/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb
@@ -43,22 +43,22 @@ def parent_child_table_creator
columns: {
foreign_key_for_child_model => :integer,
foreign_key_for_parent_model => :integer,
- :id => false
- }
+ :id => false,
+ },
)
end
def child_model_creator
@_child_model_creator ||=
UnitTests::ModelCreationStrategies::ActiveRecord.new(
- child_model_name
+ child_model_name,
)
end
def parent_model_creator
@_parent_model_creator ||= begin
model_creator = UnitTests::ModelCreators::ActiveRecord.new(
- parent_model_creator_arguments
+ parent_model_creator_arguments,
)
# TODO: doesn't this need to be a has_many :through?
diff --git a/spec/support/unit/model_creators/active_record/has_many.rb b/spec/support/unit/model_creators/active_record/has_many.rb
index 77d293d4e..1b6689ecb 100644
--- a/spec/support/unit/model_creators/active_record/has_many.rb
+++ b/spec/support/unit/model_creators/active_record/has_many.rb
@@ -38,14 +38,14 @@ def call
def child_model_creator
@_child_model_creator ||=
UnitTests::ModelCreationStrategies::ActiveRecord.new(
- child_model_name
+ child_model_name,
)
end
def parent_model_creator
@_parent_model_creator ||= begin
model_creator = UnitTests::ModelCreators::ActiveRecord.new(
- parent_model_creator_arguments
+ parent_model_creator_arguments,
)
model_creator.customize_model do |model|
diff --git a/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb b/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb
index cd23ce02f..e762f22d0 100644
--- a/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb
+++ b/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb
@@ -20,7 +20,7 @@ def self.call(args)
def initialize(args)
@arguments = CreateModelArguments::UniquenessMatcher.wrap(args)
@model_creator = UnitTests::ModelCreators::ActiveRecord.new(
- arguments
+ arguments,
)
end
@@ -36,7 +36,7 @@ def call
register(
:"active_record/uniqueness_matcher",
- ActiveRecord::UniquenessMatcher
+ ActiveRecord::UniquenessMatcher,
)
end
end
diff --git a/spec/support/unit/model_creators/basic.rb b/spec/support/unit/model_creators/basic.rb
index 1d549c5a7..596eb0681 100644
--- a/spec/support/unit/model_creators/basic.rb
+++ b/spec/support/unit/model_creators/basic.rb
@@ -43,7 +43,7 @@ def build_model_creator
model_creator = model_creation_strategy.new(
model_name,
columns,
- arguments
+ arguments,
)
model_creator.customize_model do |model|
@@ -76,7 +76,7 @@ def possibly_override_attribute_writer_method_for(model)
model.send(:define_method, "#{attribute_name}=") do |value|
new_value = _change_value.call(
value,
- overrides[:changing_values_with]
+ overrides[:changing_values_with],
)
if (
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 1cc1d2ab9..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
@@ -32,7 +32,7 @@ def stub_validation_messages
def stub_default_validation_message
keys = [
'activerecord.errors.messages',
- validation_message_key
+ validation_message_key,
]
I18nFaker.stub_translation(keys, default_message)
@@ -43,12 +43,12 @@ def stub_attribute_specific_validation_message
'activerecord.errors',
"models.#{builder.model_name.to_s.underscore}",
"attributes.#{builder.attribute_that_receives_error}",
- validation_message_key
+ validation_message_key,
]
I18nFaker.stub_translation(
keys,
- message_for_attribute_that_receives_error
+ message_for_attribute_that_receives_error,
)
end
@@ -62,7 +62,7 @@ def message_for_attribute_that_receives_error
def default_options
{
- validation_message_key: :validation_message_key
+ validation_message_key: :validation_message_key,
}
end
end
diff --git a/spec/support/unit/record_validating_confirmation_builder.rb b/spec/support/unit/record_validating_confirmation_builder.rb
index da32262c2..ff9189b0d 100644
--- a/spec/support/unit/record_validating_confirmation_builder.rb
+++ b/spec/support/unit/record_validating_confirmation_builder.rb
@@ -31,7 +31,7 @@ def attribute_to_confirm
def confirmation_attribute
options.fetch(
:confirmation_attribute,
- :"#{attribute_to_confirm}_confirmation"
+ :"#{attribute_to_confirm}_confirmation",
)
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 d6405b72d..c712e18d4 100644
--- a/spec/support/unit/record_with_different_error_attribute_builder.rb
+++ b/spec/support/unit/record_with_different_error_attribute_builder.rb
@@ -52,7 +52,7 @@ def context
valid_value: valid_value,
attribute_to_validate: attribute_to_validate,
attribute_that_receives_error: attribute_that_receives_error,
- message: message
+ message: message,
}
end
@@ -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
@@ -77,7 +77,7 @@ def validation_method_name
def model_columns
{
attribute_to_validate => :string,
- attribute_that_receives_error => :string
+ attribute_that_receives_error => :string,
}
end
@@ -85,7 +85,7 @@ def default_options
{
attribute_that_receives_error: :attribute_that_receives_error,
attribute_to_validate: :attribute_to_validate,
- message: 'some message'
+ message: 'some message',
}
end
end
diff --git a/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb b/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb
index 2fc45360d..cf3f96926 100644
--- a/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb
+++ b/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb
@@ -1,7 +1,7 @@
shared_examples_for 'ignoring_interference_by_writer' do |common_config|
valid_tests = [
:accept_if_qualified_but_changing_value_does_not_interfere,
- :reject_if_qualified_but_changing_value_interferes
+ :reject_if_qualified_but_changing_value_interferes,
]
tests = common_config.fetch(:tests)
tests.assert_valid_keys(valid_tests)
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 d1ad08ea6..14bcc5006 100644
--- a/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb
@@ -8,7 +8,7 @@
end
expect(controller).to permit_with_conditional_slice_of_params(
- permit(:name).for(:create)
+ permit(:name).for(:create),
)
end
@@ -18,7 +18,7 @@
end
expect(controller).to permit_with_conditional_slice_of_params(
- permit(:name, :age).for(:create)
+ permit(:name, :age).for(:create),
)
end
@@ -28,7 +28,7 @@
end
expect(controller).not_to permit_with_conditional_slice_of_params(
- permit(:name, :admin).for(:create)
+ permit(:name, :admin).for(:create),
)
end
@@ -36,14 +36,14 @@
define_controller_with_strong_parameters(action: :create)
expect(controller).not_to permit_with_conditional_slice_of_params(
- permit(:name).for(:create)
+ permit(:name).for(:create),
)
end
it 'tracks multiple calls to #permit for different subparameters' do
sets_of_attributes = [
[:eta, :diner_id],
- [:phone_number, :address_1, :address_2, :city, :state, :zip]
+ [:phone_number, :address_1, :address_2, :city, :state, :zip],
]
define_controller_with_strong_parameters(action: :create) do |ctrl|
@@ -57,13 +57,13 @@
expect(controller).to permit_with_conditional_slice_of_params(
permit(*sets_of_attributes[0]).for(:create),
all_params: [:order, :diner],
- selected_param: :order
+ selected_param: :order,
)
expect(controller).to permit_with_conditional_slice_of_params(
permit(*sets_of_attributes[1]).for(:create),
all_params: [:order, :diner],
- selected_param: :diner
+ selected_param: :diner,
)
end
end
@@ -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
@@ -141,8 +141,8 @@ def params_with_conditional_require(params, *filters)
params = {
foo: {
bar: 'some value',
- baz: 'some value'
- }
+ baz: 'some value',
+ },
}
expect(controller).
to permit(:bar).
@@ -168,7 +168,7 @@ def params_with_conditional_require(params, *filters)
options = {
controller_name: 'Posts',
action: :show,
- routes: -> { get '/posts/:slug', to: 'posts#show' }
+ routes: -> { get '/posts/:slug', to: 'posts#show' },
}
define_controller_with_strong_parameters(options) do
@@ -217,7 +217,7 @@ def params_with_conditional_require(params, *filters)
actual_foo_param = nil
matcher = permit(:name).for(
:create,
- params: { user: { some: 'params' } }
+ params: { user: { some: 'params' } },
)
define_controller_with_strong_parameters(action: :create) do
@@ -239,14 +239,14 @@ def params_with_conditional_require(params, *filters)
actual_user_params = nil
matcher = permit(:name).for(
:update,
- params: { id: 1, user: expected_user_params }
+ params: { id: 1, user: expected_user_params },
)
define_controller_with_strong_parameters(action: :update) do
actual_user_params = params.require(:user)
begin
actual_user_params.permit(:name)
- rescue
+ rescue StandardError
end
end
@@ -294,7 +294,7 @@ def params_with_conditional_require(params, *filters)
matcher = described_class.new([:name, :age, :height]).for(:create)
expect(matcher.description).to eq(
- '(for POST #create) restrict parameters to :name, :age, and :height'
+ '(for POST #create) restrict parameters to :name, :age, and :height',
)
end
@@ -310,7 +310,7 @@ def params_with_conditional_require(params, *filters)
new([:name]).
for(:some_action, verb: :put)
expect(matcher.description).to eq(
- '(for PUT #some_action) restrict parameters to :name'
+ '(for PUT #some_action) restrict parameters to :name',
)
end
end
@@ -328,8 +328,8 @@ def params_with_conditional_require(params, *filters)
end
message =
- 'Expected POST #create to restrict parameters to ' +
- ":name, :age, :city, and :country,\n" +
+ 'Expected POST #create to restrict parameters to '\
+ ":name, :age, :city, and :country,\n"\
'but it did not restrict any parameters.'
expect(&assertion).to fail_with_message(message)
@@ -349,8 +349,8 @@ def params_with_conditional_require(params, *filters)
end
message =
- 'Expected POST #create to restrict parameters to ' +
- ":name, :age, :city, and :country,\n" +
+ 'Expected POST #create to restrict parameters to '\
+ ":name, :age, :city, and :country,\n"\
'but the restricted parameters were :name and :age instead.'
expect(&assertion).to fail_with_message(message)
@@ -372,8 +372,8 @@ def params_with_conditional_require(params, *filters)
end
message =
- 'Expected POST #create to restrict parameters on :person to ' +
- ":name, :age, :city, and :country,\n" +
+ 'Expected POST #create to restrict parameters on :person to '\
+ ":name, :age, :city, and :country,\n"\
'but it did not restrict any parameters.'
expect(&assertion).to fail_with_message(message)
@@ -391,8 +391,8 @@ def params_with_conditional_require(params, *filters)
params = {
person: {
name: 'some name',
- age: 'some age'
- }
+ age: 'some age',
+ },
}
expect(@controller).
to permit(:name, :age, :city, :country).
@@ -401,8 +401,8 @@ def params_with_conditional_require(params, *filters)
end
message =
- 'Expected POST #create to restrict parameters on :person to ' +
- ":name, :age, :city, and :country,\n" +
+ 'Expected POST #create to restrict parameters on :person to '\
+ ":name, :age, :city, and :country,\n"\
'but it did not restrict any parameters.'
expect(&assertion).to fail_with_message(message)
@@ -419,8 +419,8 @@ def params_with_conditional_require(params, *filters)
params = {
person: {
name: 'some name',
- age: 'some age'
- }
+ age: 'some age',
+ },
}
expect(@controller).
to permit(:name, :age, :city, :country).
@@ -429,8 +429,8 @@ def params_with_conditional_require(params, *filters)
end
message =
- 'Expected POST #create to restrict parameters on :person to ' +
- ":name, :age, :city, and :country,\n" +
+ 'Expected POST #create to restrict parameters on :person to '\
+ ":name, :age, :city, and :country,\n"\
'but the restricted parameters were :name and :age instead.'
expect(&assertion).to fail_with_message(message)
@@ -453,8 +453,8 @@ def params_with_conditional_require(params, *filters)
end
message =
- 'Expected POST #create not to restrict parameters to ' +
- ":name, :age, :city, and :country,\n" +
+ 'Expected POST #create not to restrict parameters to '\
+ ":name, :age, :city, and :country,\n"\
'but it did.'
expect(&assertion).to fail_with_message(message)
@@ -470,8 +470,8 @@ def params_with_conditional_require(params, *filters)
params = {
person: {
name: 'some name',
- age: 'some age'
- }
+ age: 'some age',
+ },
}
expect(@controller).
not_to permit(:name, :age).
@@ -480,8 +480,8 @@ def params_with_conditional_require(params, *filters)
end
message =
- 'Expected POST #create not to restrict parameters on :person to ' +
- ":name and :age,\n" +
+ 'Expected POST #create not to restrict parameters on :person to '\
+ ":name and :age,\n"\
'but it did.'
expect(&assertion).to fail_with_message(message)
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 1ad1cde79..0ce8d1afa 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 @@ def controller_with_customer_partial
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 571d633e3..cdd632085 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 @@ def controller_with_wide_layout
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 ef5b4e5d0..5f2022573 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 @@
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_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb
index db397221d..60d5a34f5 100644
--- a/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb
@@ -13,8 +13,8 @@
route(:get, '/'),
build_expected_route_options(
include_controller_in_expected_route_options,
- action: 'index'
- )
+ action: 'index',
+ ),
)
end
@@ -27,8 +27,8 @@
route(:get, '/'),
build_expected_route_options(
include_controller_in_expected_route_options,
- action: 'index'
- )
+ action: 'index',
+ ),
)
end
end
@@ -42,8 +42,8 @@
route(:get, '/'),
build_expected_route_options(
include_controller_in_expected_route_options,
- action: :index
- )
+ action: :index,
+ ),
)
end
end
@@ -54,7 +54,7 @@
assert_rejects add_target_to(
route(:get, '/non_existent_route'),
controller: 'no_controller',
- action: 'no_action'
+ action: 'no_action',
)
end
end
@@ -67,8 +67,8 @@
route(:get, '/'),
build_expected_route_options(
include_controller_in_expected_route_options,
- action: 'index'
- )
+ action: 'index',
+ ),
)
end
end
@@ -81,8 +81,8 @@
route(:get, '/different_path'),
build_expected_route_options(
include_controller_in_expected_route_options,
- action: 'index'
- )
+ action: 'index',
+ ),
)
end
end
@@ -96,8 +96,8 @@
route(:get, '/'),
build_expected_route_options(
include_controller_in_expected_route_options,
- action: 'index'
- )
+ action: 'index',
+ ),
)
end
end
@@ -111,8 +111,8 @@
route(:get, '/'),
build_expected_route_options(
include_controller_in_expected_route_options,
- action: 'another_action'
- )
+ action: 'another_action',
+ ),
)
end
end
@@ -128,7 +128,7 @@
route(:get, "/#{controller_name}/1"),
controller: controller_name,
action: 'show',
- id: '1'
+ id: '1',
)
end
@@ -140,7 +140,7 @@
route(:get, "/#{controller_name}/1"),
controller: controller_name,
action: 'show',
- id: 1
+ id: 1,
)
end
end
@@ -154,11 +154,11 @@
controller: controller_name,
action: 'show',
some: 'other',
- params: 'here'
+ params: 'here',
}
assert_rejects add_target_to(
route(:get, "/#{controller_name}/:id"),
- params
+ params,
)
end
end
@@ -176,7 +176,7 @@
route(:post, "/#{controller_name}"),
controller: controller_name,
action: 'create',
- format: :json
+ format: :json,
)
end
end
@@ -191,7 +191,7 @@
route(:post, "/#{controller_name}"),
controller: controller_name,
action: 'create',
- format: 'json'
+ format: 'json',
)
end
end
@@ -207,7 +207,7 @@
route(:get, "/#{controller_name}/foo/bar"),
controller: controller_name,
action: 'whatever',
- id: 'foo/bar'
+ id: 'foo/bar',
)
end
end
@@ -219,7 +219,7 @@
assert_rejects add_target_to(
route(:get, "/#{controller_name}"),
controller: controller_name,
- action: 'whatever'
+ action: 'whatever',
)
end
end
@@ -307,7 +307,7 @@ def define_route(method, path, args)
public_send(
method,
path,
- args.merge(controller: controller, action: action)
+ args.merge(controller: controller, action: action),
)
end
end
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 dcc348167..5d213bf5a 100644
--- a/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb
+++ b/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb
@@ -1,25 +1,25 @@
require 'unit_spec_helper'
describe Shoulda::Matchers::ActionController::RouteParams, type: :controller do
- describe "#normalize" do
- context "when the route parameters is a hash" do
- it "stringifies the values in the hash" do
+ describe '#normalize' do
+ context 'when the route parameters is a hash' do
+ it 'stringifies the values in the hash' do
expect(build_route_params(controller: :examples, action: 'example', id: '1').normalize).
- to eq({ controller: "examples", action: "example", id: "1" })
+ to eq({ controller: 'examples', action: 'example', id: '1' })
end
end
- context "when the route parameters is a string and a hash" do
- it "produces a hash of route parameters" do
- expect(build_route_params("examples#example", id: '1').normalize).
- to eq({ controller: "examples", action: "example", id: "1" })
+ context 'when the route parameters is a string and a hash' do
+ it 'produces a hash of route parameters' do
+ expect(build_route_params('examples#example', id: '1').normalize).
+ to eq({ controller: 'examples', action: 'example', id: '1' })
end
end
- 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"})
+ 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' })
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 3c374f3c5..e9dbd32d3 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
@@ -32,8 +32,11 @@
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
+ model = define_model(
+ :example,
+ not_whitelisted: :string,
+ whitelisted: :string,
+ ) do
attr_accessible :whitelisted
end.new
@@ -51,8 +54,11 @@
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
+ model = define_model(
+ :example,
+ not_blacklisted: :string,
+ 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 5ca50f36e..881758a1f 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
@@ -9,12 +9,12 @@
end
describe Shoulda::Matchers::ActiveModel::AllowValueMatcher, type: :model do
- context "#description" do
+ context '#description' do
it 'describes itself with two values' do
matcher = allow_value('foo', 'bar').for(:baz)
expect(matcher.description).to eq(
- 'allow :baz to be ‹"foo"› or ‹"bar"›'
+ 'allow :baz to be ‹"foo"› or ‹"bar"›',
)
end
@@ -22,7 +22,7 @@
matcher = allow_value('foo', 'bar', 'qux').for(:baz)
expect(matcher.description).to eq(
- 'allow :baz to be ‹"foo"›, ‹"bar"›, or ‹"qux"›'
+ 'allow :baz to be ‹"foo"›, ‹"bar"›, or ‹"qux"›',
)
end
@@ -37,15 +37,15 @@
strict_matcher = allow_value('xyz').for(:attr).strict
expect(strict_matcher.description).to eq(
- 'allow :attr to be ‹"xyz"›, raising a validation exception on failure'
+ 'allow :attr to be ‹"xyz"›, raising a validation exception on failure',
)
end
end
it 'truncates the description when long' do
- matcher = allow_value("A" * 10000).for(:baz)
+ 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
@@ -300,12 +300,12 @@
it 'accepts' do
options = {
attribute_name: :attr,
- attribute_type: :string
+ attribute_type: :string,
}
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
@@ -320,12 +320,12 @@
it 'rejects with an appropriate failure message' do
options = {
attribute_name: :attr,
- attribute_type: :string
+ attribute_type: :string,
}
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
@@ -363,7 +363,7 @@
for(builder.attribute_to_validate).
with_message(
builder.message,
- against: builder.attribute_that_receives_error
+ against: builder.attribute_that_receives_error,
)
end
end
@@ -378,14 +378,14 @@
for(builder.attribute_to_validate).
with_message(
builder.message,
- against: builder.attribute_that_receives_error
+ against: builder.attribute_that_receives_error,
)
end
context 'if the messages do not match' do
it 'technically accepts' do
builder = builder_for_record_with_different_error_attribute(
- message: "a different error"
+ message: 'a different error',
)
invalid_value = "#{builder.valid_value} (invalid)"
@@ -394,8 +394,8 @@
not_to allow_value(invalid_value).
for(builder.attribute_to_validate).
with_message(
- "some error",
- against: builder.attribute_that_receives_error
+ 'some error',
+ against: builder.attribute_that_receives_error,
)
end
@@ -422,7 +422,7 @@
for(builder.attribute_to_validate).
with_message(
builder.validation_message_key,
- against: builder.attribute_that_receives_error
+ against: builder.attribute_that_receives_error,
)
end
@@ -434,26 +434,26 @@
for(builder.attribute_to_validate).
with_message(
builder.validation_message_key,
- against: builder.attribute_that_receives_error
+ against: builder.attribute_that_receives_error,
)
end
end
end
- context "an attribute with a context-dependent validation" do
- context "without the validation context" do
- it "allows a bad value" do
- expect(validating_format(with: /abc/, on: :customisable)).to allow_value("xyz").for(:attr)
+ context 'an attribute with a context-dependent validation' do
+ context 'without the validation context' do
+ it 'allows a bad value' do
+ expect(validating_format(with: /abc/, on: :customisable)).to allow_value('xyz').for(:attr)
end
end
- context "with the validation context" do
- it "allows a good value" do
- expect(validating_format(with: /abc/, on: :customisable)).to allow_value("abcde").for(:attr).on(:customisable)
+ context 'with the validation context' do
+ it 'allows a good value' do
+ expect(validating_format(with: /abc/, on: :customisable)).to allow_value('abcde').for(:attr).on(:customisable)
end
- it "rejects a bad value" do
- expect(validating_format(with: /abc/, on: :customisable)).not_to allow_value("xyz").for(:attr).on(:customisable)
+ it 'rejects a bad value' do
+ expect(validating_format(with: /abc/, on: :customisable)).not_to allow_value('xyz').for(:attr).on(:customisable)
end
end
end
@@ -463,8 +463,11 @@
define_model :example, attr: :string do
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
+ validates_numericality_of(
+ :attr,
+ greater_than_or_equal_to: 1,
+ less_than_or_equal_to: 50000,
+ )
end.new
end
@@ -490,7 +493,7 @@
ignoring_interference_by_writer
end
- it "does not match given good values along with bad values" do
+ it 'does not match given good values along with bad values' do
message = <<-MESSAGE.strip_heredoc
After setting :attr to ‹"12345"›, the matcher expected the Example to be
invalid, but it was valid instead.
@@ -503,7 +506,7 @@
expect(&assertion).to fail_with_message(message)
end
- it "does not match given bad values along with good values" do
+ it 'does not match given bad values along with good values' do
message = <<-MESSAGE.strip_heredoc
After setting :attr to ‹"12345"›, the matcher expected the Example to be
invalid, but it was valid instead.
@@ -694,7 +697,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
@@ -741,7 +744,7 @@ def name=(value)
expect(&assertion).to raise_error(
described_class::AttributeDoesNotExistError,
- message
+ message,
)
end
end
@@ -761,7 +764,7 @@ def name=(value)
expect(&assertion).to raise_error(
described_class::AttributeDoesNotExistError,
- message
+ message,
)
end
end
@@ -784,11 +787,11 @@ def name=(value)
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,
- message
+ message,
)
end
end
@@ -810,11 +813,11 @@ def name=(value)
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,
- message
+ message,
)
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 436204aa1..9d7aaf175 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
@@ -11,20 +11,20 @@
end
end
- context "an attribute with a context-dependent validation" do
- context "without the validation context" do
- it "does not match" do
- expect(validating_format(with: /abc/, on: :customisable)).not_to matcher("xyz").for(:attr)
+ context 'an attribute with a context-dependent validation' do
+ context 'without the validation context' do
+ it 'does not match' do
+ expect(validating_format(with: /abc/, on: :customisable)).not_to matcher('xyz').for(:attr)
end
end
- context "with the validation context" do
- it "disallows a bad value" do
- expect(validating_format(with: /abc/, on: :customisable)).to matcher("xyz").for(:attr).on(:customisable)
+ context 'with the validation context' do
+ it 'disallows a bad value' do
+ expect(validating_format(with: /abc/, on: :customisable)).to matcher('xyz').for(:attr).on(:customisable)
end
- it "does not match a good value" do
- expect(validating_format(with: /abc/, on: :customisable)).not_to matcher("abcde").for(:attr).on(:customisable)
+ it 'does not match a good value' do
+ expect(validating_format(with: /abc/, on: :customisable)).not_to matcher('abcde').for(:attr).on(:customisable)
end
end
end
@@ -36,7 +36,8 @@
end
it "delegates its failure message to its allow matcher's negative failure message" do
- allow_matcher = double('allow_matcher',
+ allow_matcher = double(
+ 'allow_matcher',
failure_message_when_negated: 'allow matcher failure',
).as_null_object
allow(Shoulda::Matchers::ActiveModel::AllowValueMatcher).
@@ -70,9 +71,9 @@ def record_with_custom_validation
define_model :example, attr: :string, attr2: :string do
validate :custom_validation
- def custom_validation
+ def custom_validation # rubocop:disable Lint/NestedMethodDefinition
if self[:attr] != 'good value'
- self.errors[:attr2] << 'some message'
+ errors[:attr2] << 'some message'
end
end
end.new
diff --git a/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb
index e01ad18bd..32ae832f1 100644
--- a/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb
@@ -1,7 +1,7 @@
require 'unit_spec_helper'
describe Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher, type: :model do
- context "with no arguments passed to has_secure_password" do
+ context 'with no arguments passed to has_secure_password' do
it 'matches when the subject configures has_secure_password with default options' do
working_model = define_model(:example, password_digest: :string) { has_secure_password }
expect(working_model.new).to have_secure_password
@@ -19,7 +19,7 @@
end
if active_model_supports_custom_has_secure_password_attribute?
- context "when custom attribute is given to has_secure_password" do
+ context 'when custom attribute is given to has_secure_password' do
it 'matches when the subject configures has_secure_password with correct options' do
working_model = define_model(:example, reset_password_digest: :string) { has_secure_password :reset_password }
expect(working_model.new).to have_secure_password :reset_password
diff --git a/spec/unit/shoulda/matchers/active_model/helpers_spec.rb b/spec/unit/shoulda/matchers/active_model/helpers_spec.rb
index b81780541..8246997c2 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
@@ -80,8 +81,10 @@
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.')
+ stub_active_model_message_generation(
+ type: :blank,
+ message: 'Behavior has diverged.',
+ )
assert_presence_validation_has_correct_message
end
end
@@ -101,7 +104,7 @@ def assert_length_validation_has_correct_message
expect(record).to validate_length_of(:attr).is_equal_to(40)
end
- def store_translations(options = {without: []})
+ def store_translations(options = { without: [] }) # rubocop:disable Metrics/MethodLength
options[:without] = Array.wrap(options[:without] || [])
translations = {
@@ -110,19 +113,19 @@ def store_translations(options = {without: []})
models: {
example: {
attributes: {
- attr: {}
- }
- }
+ attr: {},
+ },
+ },
},
- messages: {}
- }
+ messages: {},
+ },
},
errors: {
attributes: {
- attr: {}
+ attr: {},
},
- messages: {}
- }
+ messages: {},
+ },
}
unless options[:without].include?(:model_attribute)
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 546278532..a8a99cda6 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
@@ -13,7 +13,7 @@ def self.available_column_types
:timestamp,
:time,
:date,
- :binary
+ :binary,
]
end
@@ -28,7 +28,7 @@ def self.available_column_types
available_column_types.each do |type|
context "when column is of type #{type}" do
- it "accepts" do
+ it 'accepts' do
expect(validating_absence_of(:attr, {}, type: type)).
to validate_absence_of(:attr)
end
@@ -37,9 +37,9 @@ def self.available_column_types
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :next_value
+ changing_values_with: :next_value,
},
- }
+ },
)
define_method(:validation_matcher_scenario_args) do |*args|
@@ -106,9 +106,9 @@ def validation_matcher_scenario_args
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :upcase
+ changing_values_with: :upcase,
},
- }
+ },
)
def validation_matcher_scenario_args
@@ -142,9 +142,9 @@ def validation_matcher_scenario_args
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :next_value
+ changing_values_with: :next_value,
},
- }
+ },
)
def validation_matcher_scenario_args
@@ -169,9 +169,9 @@ def validation_matcher_scenario_args
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :next_value
+ changing_values_with: :next_value,
},
- }
+ },
)
def validation_matcher_scenario_args
@@ -198,12 +198,12 @@ def validation_matcher_scenario_args
end
end
- context "an i18n translation containing %{attribute} and %{model}" do
+ context 'an i18n translation containing %{attribute} and %{model}' do
after { I18n.backend.reload! }
- it "does not raise an exception" do
- stub_translation("activerecord.errors.messages.present",
- "%{attribute} must be blank in a %{model}")
+ it 'does not raise an exception' do
+ stub_translation('activerecord.errors.messages.present',
+ '%{attribute} must be blank in a %{model}',)
expect {
expect(validating_absence_of(:attr)).to validate_absence_of(:attr)
@@ -211,15 +211,15 @@ def validation_matcher_scenario_args
end
end
- context "an attribute with a context-dependent validation" do
- context "without the validation context" do
- it "does not match" do
+ context 'an attribute with a context-dependent validation' do
+ context 'without the validation context' do
+ it 'does not match' do
expect(validating_absence_of(:attr, on: :customisable)).not_to validate_absence_of(:attr)
end
end
- context "with the validation context" do
- it "matches" do
+ context 'with the validation context' do
+ it 'matches' do
expect(validating_absence_of(:attr, on: :customisable)).to validate_absence_of(:attr).on(:customisable)
end
end
@@ -242,7 +242,7 @@ def validating_absence_of(attr, validation_options = {}, given_column_options =
model = define_model_validating_absence_of(
attr,
validation_options,
- given_column_options
+ given_column_options,
)
model.new
end
diff --git a/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
index 8cabdd36f..50bcbf6e4 100644
--- a/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
@@ -20,7 +20,7 @@
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :always_nil,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr has been set to "1", but this
could not be proved.
After setting :attr to ‹false› -- which was read back as ‹nil› -- the
@@ -34,7 +34,7 @@
MESSAGE
},
},
- model_creator: :active_model
+ model_creator: :active_model,
)
it 'fails when used in the negative' do
diff --git a/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb
index ef01fe1c5..10d60cacf 100644
--- a/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb
@@ -35,7 +35,7 @@
model_name: 'Example',
attribute_name: :password,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :password_confirmation matches
:password, but this could not be proved.
After setting :password_confirmation to ‹"same value"›, then setting
@@ -53,14 +53,14 @@
MESSAGE
},
},
- model_creator: :active_model
+ model_creator: :active_model,
)
it 'fails when used in the negative' do
builder = builder_for_record_validating_confirmation(
model_name: 'Example',
attribute: :password,
- confirmation_attribute: :password_confirmation
+ confirmation_attribute: :password_confirmation,
)
assertion = lambda do
@@ -95,7 +95,7 @@
expect(&assertion).to raise_error(
Shoulda::Matchers::ActiveModel::AllowValueMatcher::AttributeDoesNotExistError,
- message
+ message,
)
end
end
@@ -115,7 +115,7 @@
expect(&assertion).to raise_error(
Shoulda::Matchers::ActiveModel::AllowValueMatcher::AttributeDoesNotExistError,
- message
+ message,
)
end
end
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 899316d3a..de42eb847 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
@@ -39,7 +39,7 @@
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr lies outside the range ‹2› to
‹5›, but this could not be proved.
After setting :attr to ‹1› -- which was read back as ‹2› -- the
@@ -56,7 +56,7 @@
MESSAGE
},
},
- model_creator: :active_model
+ model_creator: :active_model,
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { in: 2..5 })
@@ -105,7 +105,7 @@ def configure_validation_matcher(matcher)
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
@@ -136,7 +136,7 @@ def configure_validation_matcher(matcher)
matcher = validate_exclusion_of(:attr).in_range(1..10)
expect(matcher.description).to eq(
- 'validate that :attr lies outside the range ‹1› to ‹10›'
+ 'validate that :attr lies outside the range ‹1› to ‹10›',
)
end
end
@@ -169,7 +169,7 @@ def configure_validation_matcher(matcher)
matcher = validate_exclusion_of(:attr).in_array([true, 'dog'])
expect(matcher.description).to eq(
- 'validate that :attr is neither ‹true› nor ‹"dog"›'
+ 'validate that :attr is neither ‹true› nor ‹"dog"›',
)
end
end
@@ -179,7 +179,7 @@ def configure_validation_matcher(matcher)
matcher = validate_exclusion_of(:attr).in_array([true, 'dog', 'cat'])
expect(matcher.description).to eq(
- 'validate that :attr is neither ‹true›, ‹"dog"›, nor ‹"cat"›'
+ 'validate that :attr is neither ‹true›, ‹"dog"›, nor ‹"cat"›',
)
end
end
@@ -191,7 +191,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr is neither ‹"one"› nor ‹"two"›,
but this could not be proved.
After setting :attr to ‹"one"› -- which was read back as ‹"onf"› --
@@ -203,10 +203,10 @@ def configure_validation_matcher(matcher)
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
+ model_creator: :active_model,
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { in: ['one', 'two'] })
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..733d28eef 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]) }.
@@ -770,7 +768,7 @@ def configure_validation_matcher(matcher)
valid_values = booleans
builder = build_object_allowing(valid_values)
message =
- 'You are using `validate_inclusion_of` to assert that a boolean ' +
+ 'You are using `validate_inclusion_of` to assert that a boolean '\
'column allows boolean values and disallows non-boolean ones'
stderr = capture(:stderr) do
@@ -831,7 +829,7 @@ def validation_matcher_scenario_args
valid_values = [nil]
builder = build_object_allowing(valid_values)
message =
- 'You are using `validate_inclusion_of` to assert that a ' +
+ 'You are using `validate_inclusion_of` to assert that a '\
'boolean column allows nil'
stderr = capture(:stderr) do
@@ -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_length_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb
index bcd568049..0b7f62648 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
@@ -32,7 +32,7 @@
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :add_character,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that the length of :attr is at least 4, but
this could not be proved.
After setting :attr to ‹"xxx"› -- which was read back as ‹"xxxa"› --
@@ -45,8 +45,8 @@
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { minimum: 4 })
@@ -112,7 +112,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :remove_character,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that the length of :attr is at most 4, but
this could not be proved.
After setting :attr to ‹"xxxxx"› -- which was read back as ‹"xxxx"› --
@@ -125,8 +125,8 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { maximum: 4 })
@@ -169,7 +169,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :add_character,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that the length of :attr is 4, but this
could not be proved.
After setting :attr to ‹"xxx"› -- which was read back as ‹"xxxa"› --
@@ -182,8 +182,8 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { is: 4 })
@@ -237,14 +237,15 @@ def configure_validation_matcher(matcher)
context 'using translations' do
after { I18n.backend.reload! }
- context "a too_long translation containing %{attribute}, %{model}" do
+ context 'a too_long translation containing %{attribute}, %{model}' do
before do
stub_translation(
- "activerecord.errors.messages.too_long",
- "The %{attribute} of your %{model} is too long (maximum is %{count} characters)")
+ 'activerecord.errors.messages.too_long',
+ 'The %{attribute} of your %{model} is too long (maximum is %{count} characters)',
+ )
end
- it "does not raise an exception" do
+ it 'does not raise an exception' do
expect {
expect(validating_length(maximum: 4)).
to validate_length_of(:attr).is_at_most(4)
@@ -252,28 +253,30 @@ def configure_validation_matcher(matcher)
end
end
- context "a too_short translation containing %{attribute}, %{model}" do
+ context 'a too_short translation containing %{attribute}, %{model}' do
before do
stub_translation(
- "activerecord.errors.messages.too_short",
- "The %{attribute} of your %{model} is too short (minimum is %{count} characters)")
+ 'activerecord.errors.messages.too_short',
+ 'The %{attribute} of your %{model} is too short (minimum is %{count} characters)',
+ )
end
- it "does not raise an exception" do
+ it 'does not raise an exception' do
expect {
expect(validating_length(minimum: 4)).to validate_length_of(:attr).is_at_least(4)
}.to_not raise_exception
end
end
- context "a wrong_length translation containing %{attribute}, %{model}" do
+ context 'a wrong_length translation containing %{attribute}, %{model}' do
before do
stub_translation(
- "activerecord.errors.messages.wrong_length",
- "The %{attribute} of your %{model} is the wrong length (should be %{count} characters)")
+ 'activerecord.errors.messages.wrong_length',
+ 'The %{attribute} of your %{model} is the wrong length (should be %{count} characters)',
+ )
end
- it "does not raise an exception" do
+ it 'does not raise an exception' do
expect {
expect(validating_length(is: 4)).
to validate_length_of(:attr).is_equal_to(4)
@@ -385,7 +388,7 @@ def validating_length(options = {})
def validation_matcher_scenario_args
super.deep_merge(
matcher_name: :validate_length_of,
- model_creator: :active_model
+ model_creator: :active_model,
)
end
end
diff --git a/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb
index 84595afb0..d1d5c6d44 100644
--- a/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb
@@ -2,7 +2,7 @@
describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :model do
class << self
- def all_qualifiers
+ def all_qualifiers # rubocop:disable Metrics/MethodLength
[
{
category: :comparison,
@@ -67,8 +67,8 @@ def all_qualifiers
name: :on,
argument: :customizable,
validation_name: :on,
- validation_value: :customizable
- }
+ validation_value: :customizable,
+ },
]
end
@@ -144,7 +144,7 @@ def default_validation_values
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :numeric_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like a number, but this
could not be proved.
After setting :attr to ‹"abcd"› -- which was read back as ‹"1"› -- the
@@ -156,8 +156,8 @@ def default_validation_values
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
)
context 'when the attribute is a virtual attribute in an ActiveRecord model' do
@@ -254,7 +254,7 @@ def default_validation_values
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value_or_non_numeric_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like a number as long as
it is not nil, but this could not be proved.
In checking that Example allows :attr to be ‹nil›, after setting :attr
@@ -270,8 +270,8 @@ def default_validation_values
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { allow_nil: true })
@@ -340,7 +340,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :numeric_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like an integer, but this
could not be proved.
After setting :attr to ‹"0.1"› -- which was read back as ‹"1"› -- the
@@ -352,8 +352,8 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { only_integer: true })
@@ -419,7 +419,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like an odd number, but
this could not be proved.
After setting :attr to ‹"2"› -- which was read back as ‹"3"› -- the
@@ -431,8 +431,8 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { odd: true })
@@ -446,7 +446,7 @@ def configure_validation_matcher(matcher)
context 'when the attribute is a virtual attribute in ActiveRecord model' do
it 'accepts' do
record = build_record_validating_numericality_of_virtual_attribute(
- odd: true
+ odd: true,
)
expect(record).to validate_numericality.odd
end
@@ -456,7 +456,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :integer,
- odd: true
+ odd: true,
)
expect(record).to validate_numericality.odd
@@ -467,7 +467,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :float,
- odd: true
+ odd: true,
)
expect(record).to validate_numericality.odd
@@ -540,7 +540,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like an even number, but
this could not be proved.
After setting :attr to ‹"1"› -- which was read back as ‹"2"› -- the
@@ -552,8 +552,8 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { even: true })
@@ -577,7 +577,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :integer,
- even: true
+ even: true,
)
expect(record).to validate_numericality.even
@@ -588,7 +588,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :float,
- even: true
+ even: true,
)
expect(record).to validate_numericality.even
@@ -660,7 +660,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like a number less than or
equal to 18, but this could not be proved.
After setting :attr to ‹"18"› -- which was read back as ‹"19"› -- the
@@ -675,12 +675,12 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(
- validation_options: { less_than_or_equal_to: 18 }
+ validation_options: { less_than_or_equal_to: 18 },
)
end
@@ -702,7 +702,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :integer,
- less_than_or_equal_to: 18
+ less_than_or_equal_to: 18,
)
expect(record).to validate_numericality.is_less_than_or_equal_to(18)
@@ -713,7 +713,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :float,
- less_than_or_equal_to: 18
+ less_than_or_equal_to: 18,
)
expect(record).to validate_numericality.is_less_than_or_equal_to(18)
@@ -786,7 +786,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like a number less than
18, but this could not be proved.
After setting :attr to ‹"17"› -- which was read back as ‹"18"› -- the
@@ -801,8 +801,8 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { less_than: 18 })
@@ -826,7 +826,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :integer,
- less_than: 18
+ less_than: 18,
)
expect(record).to validate_numericality.is_less_than(18)
@@ -837,7 +837,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :float,
- less_than: 18
+ less_than: 18,
)
expect(record).to validate_numericality.is_less_than(18)
@@ -908,7 +908,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like a number equal to 18,
but this could not be proved.
After setting :attr to ‹"18"› -- which was read back as ‹"19"› -- the
@@ -923,8 +923,8 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { equal_to: 18 })
@@ -948,7 +948,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :integer,
- equal_to: 18
+ equal_to: 18,
)
expect(record).to validate_numericality.is_equal_to(18)
@@ -959,7 +959,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :float,
- equal_to: 18
+ equal_to: 18,
)
expect(record).to validate_numericality.is_equal_to(18)
@@ -1030,7 +1030,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like a number other than
18, but this could not be proved.
After setting :attr to ‹"18"› -- which was read back as ‹"19"› -- the
@@ -1042,8 +1042,8 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { other_than: 18 })
@@ -1067,7 +1067,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :integer,
- other_than: 18
+ other_than: 18,
)
expect(record).to validate_numericality.is_other_than(18)
@@ -1078,7 +1078,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :float,
- other_than: 18
+ other_than: 18,
)
expect(record).to validate_numericality.is_other_than(18)
@@ -1121,7 +1121,7 @@ def configure_validation_matcher(matcher)
context 'validating with greater_than_or_equal_to' do
it 'accepts' do
record = build_record_validating_numericality(
- greater_than_or_equal_to: 18
+ greater_than_or_equal_to: 18,
)
expect(record).
to validate_numericality.
@@ -1156,7 +1156,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like a number greater than
or equal to 18, but this could not be proved.
After setting :attr to ‹"17"› -- which was read back as ‹"18"› -- the
@@ -1168,12 +1168,12 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(
- validation_options: { greater_than_or_equal_to: 18 }
+ validation_options: { greater_than_or_equal_to: 18 },
)
end
@@ -1196,7 +1196,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :integer,
- greater_than_or_equal_to: 18
+ greater_than_or_equal_to: 18,
)
expect(record).
@@ -1209,7 +1209,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :float,
- greater_than_or_equal_to: 18
+ greater_than_or_equal_to: 18,
)
expect(record).
@@ -1288,7 +1288,7 @@ def configure_validation_matcher(matcher)
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like a number greater than
18, but this could not be proved.
After setting :attr to ‹"18"› -- which was read back as ‹"19"› -- the
@@ -1300,8 +1300,8 @@ def configure_validation_matcher(matcher)
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
) do
def validation_matcher_scenario_args
super.deep_merge(validation_options: { greater_than: 18 })
@@ -1325,7 +1325,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :integer,
- greater_than: 18
+ greater_than: 18,
)
expect(record).
@@ -1338,7 +1338,7 @@ def configure_validation_matcher(matcher)
it 'accepts (and does not raise an error)' do
record = build_record_validating_numericality(
column_type: :float,
- greater_than: 18
+ greater_than: 18,
)
expect(record).
@@ -1518,7 +1518,7 @@ def configure_validation_matcher(matcher)
specify 'such as validating even but testing that only_integer is validated' do
record = build_record_validating_numericality(
even: true,
- greater_than: 18
+ greater_than: 18,
)
assertion = lambda do
@@ -1571,7 +1571,7 @@ def configure_validation_matcher(matcher)
specify 'such as validating greater_than_or_equal_to (+ even) but testing that greater_than is validated' do
record = build_record_validating_numericality(
even: true,
- greater_than_or_equal_to: 18
+ greater_than_or_equal_to: 18,
)
assertion = lambda do
@@ -1595,7 +1595,7 @@ def configure_validation_matcher(matcher)
specify 'such as validating odd (+ greater_than) but testing that even is validated' do
record = build_record_validating_numericality(
odd: true,
- greater_than: 18
+ greater_than: 18,
)
assertion = lambda do
@@ -1623,7 +1623,7 @@ def configure_validation_matcher(matcher)
specify 'such as validating greater_than_or_equal_to (+ odd) but testing that is_less_than_or_equal_to is validated' do
record = build_record_validating_numericality(
odd: true,
- greater_than_or_equal_to: 99
+ greater_than_or_equal_to: 99,
)
assertion = lambda do
@@ -1648,7 +1648,7 @@ def configure_validation_matcher(matcher)
record = build_record_validating_numericality(
only_integer: true,
greater_than_or_equal_to: 18,
- less_than: 99
+ less_than: 99,
)
assertion = lambda do
@@ -1675,7 +1675,7 @@ def configure_validation_matcher(matcher)
specify 'such as testing greater_than (+ only_integer) with lower value' do
record = build_record_validating_numericality(
only_integer: true,
- greater_than: 19
+ greater_than: 19,
)
assertion = lambda do
@@ -1703,7 +1703,7 @@ def configure_validation_matcher(matcher)
specify 'such as testing greater_than (+ only_integer) with higher value' do
record = build_record_validating_numericality(
only_integer: true,
- greater_than: 17
+ greater_than: 17,
)
assertion = lambda do
@@ -1727,7 +1727,7 @@ def configure_validation_matcher(matcher)
specify 'such as testing greater_than (+ even) with lower value' do
record = build_record_validating_numericality(
even: true,
- greater_than: 20
+ greater_than: 20,
)
assertion = lambda do
@@ -1755,7 +1755,7 @@ def configure_validation_matcher(matcher)
specify 'such as testing greater than (+ even) with higher value' do
record = build_record_validating_numericality(
even: true,
- greater_than: 16
+ greater_than: 16,
)
assertion = lambda do
@@ -1779,7 +1779,7 @@ def configure_validation_matcher(matcher)
specify 'such as testing less_than_or_equal_to (+ odd) with lower value' do
record = build_record_validating_numericality(
odd: true,
- less_than_or_equal_to: 101
+ less_than_or_equal_to: 101,
)
assertion = lambda do
@@ -1803,7 +1803,7 @@ def configure_validation_matcher(matcher)
specify 'such as testing less_than_or_equal_to (+ odd) with higher value' do
record = build_record_validating_numericality(
odd: true,
- less_than_or_equal_to: 97
+ less_than_or_equal_to: 97,
)
assertion = lambda do
@@ -1833,7 +1833,7 @@ def configure_validation_matcher(matcher)
record = build_record_validating_numericality(
only_integer: true,
greater_than: 19,
- less_than: 99
+ less_than: 99,
)
assertion = lambda do
@@ -1863,7 +1863,7 @@ def configure_validation_matcher(matcher)
record = build_record_validating_numericality(
only_integer: true,
greater_than: 18,
- less_than: 100
+ less_than: 100,
)
assertion = lambda do
@@ -1904,7 +1904,7 @@ def configure_validation_matcher(matcher)
it do
record = build_record_validating_numericality(
- greater_than_or_equal_to: 100_000
+ greater_than_or_equal_to: 100_000,
)
expect(record).
to validate_numericality.
@@ -1913,7 +1913,7 @@ def configure_validation_matcher(matcher)
it do
record = build_record_validating_numericality(
- less_than_or_equal_to: 100_000
+ less_than_or_equal_to: 100_000,
)
expect(record).
to validate_numericality.
@@ -1955,7 +1955,7 @@ def set_attr!; self.attr = 5 end
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :numeric_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr looks like a number, but this
could not be proved.
After setting :attr to ‹"abcd"› -- which was read back as ‹"1"› -- the
@@ -1967,8 +1967,8 @@ def set_attr!; self.attr = 5 end
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
)
def validation_matcher_scenario_args
@@ -1981,7 +1981,7 @@ def validation_matcher_scenario_args
it 'describes that it allows numbers' do
matcher = validate_numericality_of(:attr)
expect(matcher.description).to eq(
- 'validate that :attr looks like a number'
+ 'validate that :attr looks like a number',
)
end
end
@@ -1990,7 +1990,7 @@ def validation_matcher_scenario_args
it 'describes that it allows integers' do
matcher = validate_numericality_of(:attr).only_integer
expect(matcher.description).to eq(
- 'validate that :attr looks like an integer'
+ 'validate that :attr looks like an integer',
)
end
end
@@ -2000,7 +2000,7 @@ def validation_matcher_scenario_args
it "describes that it allows #{qualifier[:name]} numbers" do
matcher = validate_numericality_of(:attr).__send__(qualifier[:name])
expect(matcher.description).to eq(
- "validate that :attr looks like an #{qualifier[:name]} number"
+ "validate that :attr looks like an #{qualifier[:name]} number",
)
end
end
@@ -2015,20 +2015,20 @@ def validation_matcher_scenario_args
__send__(qualifier[:name], 18)
expect(matcher.description).to eq(
- "validate that :attr looks like a number #{comparison_phrase} 18"
+ "validate that :attr looks like a number #{comparison_phrase} 18",
)
end
end
end
context 'qualified with odd + is_greater_than_or_equal_to' do
- it "describes that it allows odd numbers greater than or equal to a certain value" do
+ it 'describes that it allows odd numbers greater than or equal to a certain value' do
matcher = validate_numericality_of(:attr).
odd.
is_greater_than_or_equal_to(18)
expect(matcher.description).to eq(
- 'validate that :attr looks like an odd number greater than or equal to 18'
+ 'validate that :attr looks like an odd number greater than or equal to 18',
)
end
end
@@ -2041,7 +2041,7 @@ def validation_matcher_scenario_args
is_less_than_or_equal_to(100)
expect(matcher.description).to eq(
- 'validate that :attr looks like an integer greater than 18 and less than or equal to 100'
+ 'validate that :attr looks like an integer greater than 18 and less than or equal to 100',
)
end
end
@@ -2050,7 +2050,7 @@ def validation_matcher_scenario_args
it 'describes that it relies upon a strict validation' do
matcher = validate_numericality_of(:attr).strict
expect(matcher.description).to eq(
- 'validate that :attr looks like a number, raising a validation exception on failure'
+ 'validate that :attr looks like a number, raising a validation exception on failure',
)
end
@@ -2058,7 +2058,7 @@ def validation_matcher_scenario_args
it 'places the comparison description after "strictly"' do
matcher = validate_numericality_of(:attr).is_less_than(18).strict
expect(matcher.description).to eq(
- 'validate that :attr looks like a number less than 18, raising a validation exception on failure'
+ 'validate that :attr looks like a number less than 18, raising a validation exception on failure',
)
end
end
@@ -2129,7 +2129,7 @@ def attribute_name
def validation_matcher_scenario_args
super.deep_merge(
matcher_name: :validate_numericality_of,
- model_creator: :active_record
+ model_creator: :active_record,
)
end
end
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 3fc3a4db7..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
@@ -16,13 +16,13 @@
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :nil_to_blank
+ changing_values_with: :nil_to_blank,
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :never_falsy,
- expected_message: <<-MESSAGE
+ expected_message: <<-MESSAGE,
Expected Example to validate that :attr cannot be empty/falsy, but this
could not be proved.
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
@@ -35,8 +35,8 @@
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
)
it 'fails when used in the negative' do
@@ -202,13 +202,13 @@
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :nil_to_blank
+ changing_values_with: :nil_to_blank,
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :never_falsy,
- expected_message: <<-MESSAGE
+ expected_message: <<-MESSAGE,
Expected Example to validate that :attr cannot be empty/falsy, but this
could not be proved.
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
@@ -221,8 +221,8 @@
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
)
if active_model_supports_full_attributes_api?
@@ -305,13 +305,13 @@ def model_creator
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :nil_to_blank
+ changing_values_with: :nil_to_blank,
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :never_falsy,
- expected_message: <<-MESSAGE
+ expected_message: <<-MESSAGE,
Expected Example to validate that :attr cannot be empty/falsy, but this
could not be proved.
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
@@ -324,8 +324,8 @@ def model_creator
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
)
end
@@ -345,13 +345,13 @@ def model_creator
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :nil_to_blank
+ changing_values_with: :nil_to_blank,
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :never_falsy,
- expected_message: <<-MESSAGE
+ expected_message: <<-MESSAGE,
Expected Example to validate that :attr cannot be empty/falsy, but this
could not be proved.
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
@@ -364,8 +364,8 @@ def model_creator
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
)
end
@@ -386,13 +386,13 @@ def model_creator
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :nil_to_blank
+ changing_values_with: :nil_to_blank,
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :never_falsy,
- expected_message: <<-MESSAGE
+ expected_message: <<-MESSAGE,
Expected Example to validate that :attr cannot be empty/falsy, but this
could not be proved.
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
@@ -405,8 +405,8 @@ def model_creator
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
)
def model_creator
@@ -445,13 +445,13 @@ def build_record_having_and_belonging_to_many
'ignoring_interference_by_writer',
tests: {
accept_if_qualified_but_changing_value_does_not_interfere: {
- changing_values_with: :nil_to_blank
+ changing_values_with: :nil_to_blank,
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :never_falsy,
- expected_message: <<-MESSAGE
+ expected_message: <<-MESSAGE,
Expected Example to validate that :attr cannot be empty/falsy, but this
could not be proved.
After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
@@ -464,8 +464,8 @@ def build_record_having_and_belonging_to_many
attribute, then you may need to change it to make this test pass, or
do something else entirely.
MESSAGE
- }
- }
+ },
+ },
)
def model_creator
@@ -882,16 +882,17 @@ def record_belonging_to(
end
end
- context "an i18n translation containing %{attribute} and %{model}" do
+ context 'an i18n translation containing %{attribute} and %{model}' do
before do
stub_translation(
- "activerecord.errors.messages.blank",
- "Please enter a %{attribute} for your %{model}")
+ 'activerecord.errors.messages.blank',
+ 'Please enter a %{attribute} for your %{model}',
+ )
end
after { I18n.backend.reload! }
- it "does not raise an exception" do
+ it 'does not raise an exception' do
expect {
expect(validating_presence).to validate_presence_of(:attr)
}.to_not raise_exception
@@ -932,15 +933,15 @@ def record_belonging_to(
end
end
- context "an attribute with a context-dependent validation" do
- context "without the validation context" do
- it "does not match" do
+ context 'an attribute with a context-dependent validation' do
+ context 'without the validation context' do
+ it 'does not match' do
expect(validating_presence(on: :customisable)).not_to matcher
end
end
- context "with the validation context" do
- it "matches" do
+ context 'with the validation context' do
+ it 'matches' do
expect(validating_presence(on: :customisable)).to matcher.on(:customisable)
end
end
@@ -961,7 +962,7 @@ def record_belonging_to(
end
expect(&assertion).to raise_error(
- Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError
+ Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError,
)
end
end
@@ -971,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
@@ -1189,7 +1190,7 @@ def active_resource_model
def validation_matcher_scenario_args
super.deep_merge(
matcher_name: :validate_presence_of,
- model_creator: :active_record
+ model_creator: :active_record,
)
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 fa4fa3144..5fe336a70 100644
--- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
@@ -489,6 +489,7 @@
with_belongs_to_as_optional_by_default do
child_model = create_child_model_belonging_to_parent do
attr_accessor :condition
+
validates_presence_of :parent, if: :condition
end
@@ -504,6 +505,7 @@
with_belongs_to_as_optional_by_default do
child_model = create_child_model_belonging_to_parent do
attr_accessor :condition
+
validates_presence_of :parent, if: :condition
end
@@ -535,6 +537,7 @@
it 'passes' do
child_model = create_child_model_belonging_to_parent do
attr_accessor :condition
+
validates_presence_of :parent, if: :condition
end
@@ -548,6 +551,7 @@
it 'passes' do
child_model = create_child_model_belonging_to_parent do
attr_accessor :condition
+
validates_presence_of :parent, if: :condition
end
@@ -858,10 +862,9 @@ def belonging_to_non_existent_class(model_name, assoc_name, options = {})
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 +880,9 @@ def belonging_to_non_existent_class(model_name, assoc_name, options = {})
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
@@ -919,8 +920,11 @@ def belonging_to_non_existent_class(model_name, assoc_name, options = {})
end
it 'rejects an association with a bad :as option' do
- define_model :child, caretaker_type: :string,
- caretaker_id: :integer
+ define_model(
+ :child,
+ caretaker_type: :string,
+ caretaker_id: :integer,
+ )
define_model :parent do
has_many :children, as: :guardian
end
@@ -940,7 +944,7 @@ def belonging_to_non_existent_class(model_name, assoc_name, options = {})
define_model :child
define_model :conception, child_id: :integer,
- parent_id: :integer do
+ parent_id: :integer do
belongs_to :child
end
@@ -1162,7 +1166,7 @@ def belonging_to_non_existent_class(model_name, assoc_name, options = {})
end
message =
- 'Expected Parent to have a has_many association called children ' +
+ 'Expected Parent to have a has_many association called children '\
'(children should have index_errors set to true)'
expect {
@@ -1251,7 +1255,7 @@ def having_many_non_existent_class(model_name, assoc_name, options = {})
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 +1298,7 @@ def having_many_non_existent_class(model_name, assoc_name, options = {})
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 +1446,6 @@ def having_many_non_existent_class(model_name, assoc_name, options = {})
}.to fail_with_message(message)
end
-
it 'accepts an association with a through' do
define_model :detail
@@ -1539,7 +1542,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
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
@@ -1582,7 +1585,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: :people_and_their_families
+ join_table: :people_and_their_families,
)
end
@@ -1611,7 +1614,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: :people_and_their_families
+ join_table: :people_and_their_families,
)
end
@@ -1638,7 +1641,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: :people_and_their_families
+ join_table: :people_and_their_families,
)
end
@@ -1663,7 +1666,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: :people_and_their_families
+ join_table: :people_and_their_families,
)
end
@@ -1722,7 +1725,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: 'people_and_their_families'
+ join_table: 'people_and_their_families',
)
end
@@ -1751,7 +1754,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: 'people_and_their_families'
+ join_table: 'people_and_their_families',
)
end
@@ -1778,7 +1781,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: 'people_and_their_families'
+ join_table: 'people_and_their_families',
)
end
@@ -1803,7 +1806,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: 'people_and_their_families'
+ join_table: 'people_and_their_families',
)
end
@@ -1861,7 +1864,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: :people_and_their_families
+ join_table: :people_and_their_families,
)
end
@@ -1887,7 +1890,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: :people_and_their_families
+ join_table: :people_and_their_families,
)
end
@@ -1911,7 +1914,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
define_model :person do
has_and_belongs_to_many(
:relatives,
- join_table: :people_and_their_families
+ join_table: :people_and_their_families,
)
end
@@ -1967,19 +1970,17 @@ def having_one_non_existent(model_name, assoc_name, options = {})
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 +1998,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
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 +2009,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
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 +2026,7 @@ def having_one_non_existent(model_name, assoc_name, options = {})
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
@@ -2138,10 +2139,10 @@ 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
+ relative_id: :integer
define_model :person do
has_and_belongs_to_many :relatives
end.new
@@ -2154,7 +2155,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?
@@ -2166,7 +2167,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/define_enum_for_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb
index 8b3517f61..b7e631472 100644
--- a/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb
@@ -24,7 +24,8 @@
context 'if a method to hold enum values exists on the model but was not created via the enum macro' do
it 'rejects with an appropriate failure message' do
model = define_model 'Example' do
- def self.statuses; end
+ def self.statuses
+ end
end
message = format_message(<<-MESSAGE)
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 2cdf4b43b..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
@@ -10,12 +10,12 @@
record = record_with_implicit_order_column_on(
:created_at,
class_name: 'Employee',
- columns: [:created_at]
+ 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
@@ -27,12 +27,12 @@
record = record_with_implicit_order_column_on(
:created_at,
class_name: 'Employee',
- columns: [:created_at]
+ 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
@@ -46,12 +46,12 @@
record = record_with_implicit_order_column_on(
:created_at,
class_name: 'Employee',
- columns: [:created_at, :email]
+ 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
@@ -63,12 +63,12 @@
record = record_with_implicit_order_column_on(
:created_at,
class_name: 'Employee',
- columns: [:created_at, :email]
+ 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
@@ -82,12 +82,12 @@
it 'does not match, producing an appropriate message' do
record = record_without_implicit_order_column(
class_name: 'Employee',
- columns: [:created_at]
+ 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
@@ -98,12 +98,12 @@
it 'does not match, producing an appropriate message' do
record = record_without_implicit_order_column(
class_name: 'Employee',
- columns: [:created_at]
+ 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.
@@ -147,7 +147,7 @@
matcher = have_implicit_order_column(:created_at)
expect(matcher.description).to eq(
- 'have an implicit_order_column of :created_at'
+ 'have an implicit_order_column of :created_at',
)
end
end
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 c5f5470b8..c53420714 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 @@ def self.rich_text_is_defined?
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 cc2b203af..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,9 +1,7 @@
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/serialize_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb
index 07cc1d360..6f90583c3 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,11 @@ def with_serialized_attr(type = nil)
def define_serializer(name)
define_class(name) do
- def load(*); end
- def dump(*); end
+ def load(*) # rubocop:disable Lint/NestedMethodDefinition
+ end
+
+ def dump(*) # rubocop:disable Lint/NestedMethodDefinition
+ end
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 93a8fa524..7d4247ec3 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
@@ -12,15 +12,15 @@
record = build_record_validating_uniqueness(
scopes: [
build_attribute(name: :scope1),
- { name: :scope2 }
- ]
+ { name: :scope2 },
+ ],
)
expect(record).to validate_uniqueness.scoped_to(:scope1, :scope2)
end
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)
@@ -32,8 +32,8 @@
record = create_record_validating_uniqueness(
scopes: [
build_attribute(name: :scope1),
- { name: :scope2 }
- ]
+ { name: :scope2 },
+ ],
)
expect(record).to validate_uniqueness.scoped_to(:scope1, :scope2)
@@ -41,7 +41,7 @@
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 @@
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)
@@ -70,9 +70,9 @@
record = build_record_validating_uniqueness(
scopes: [
build_attribute(name: :scope1),
- build_attribute(name: :scope2)
+ build_attribute(name: :scope2),
],
- additional_attributes: [:other]
+ additional_attributes: [:other],
)
assertion = lambda do
@@ -98,7 +98,7 @@
record = build_record_validating_uniqueness(
scopes: [
build_attribute(name: :scope1),
- build_attribute(name: :scope2)
+ build_attribute(name: :scope2),
],
)
@@ -122,8 +122,8 @@
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) ],
- additional_attributes: [:scope]
+ scopes: [build_attribute(name: :other)],
+ additional_attributes: [:scope],
)
assertion = lambda do
expect(record).
@@ -145,7 +145,7 @@
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 @@
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 @@
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,13 +208,13 @@
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
expect(record).to validate_uniqueness.scoped_to(
:non_existent1,
- :non_existent2
+ :non_existent2,
)
end
@@ -265,24 +265,24 @@
'Example',
attribute_name => :string,
scope1: column_type,
- scope2: column_type
+ scope2: column_type,
) do |m|
m.validates_uniqueness_of(
attribute_name,
scope: [:scope1],
- message: 'first message'
+ message: 'first message',
)
m.validates_uniqueness_of(
attribute_name,
scope: [:scope2],
- message: 'second message'
+ message: 'second message',
)
end
model.create!(
attribute_name => dummy_value_for(:string),
scope1: dummy_value_for(column_type),
- scope2: dummy_value_for(column_type)
+ scope2: dummy_value_for(column_type),
)
expect(model.new).
@@ -321,7 +321,7 @@
attribute_options.deep_merge(
column_type: column_type,
value_type: value_type,
- options: { array: array }
+ options: { array: array },
)
end
end
@@ -352,7 +352,7 @@
it 'accepts' do
record = build_record_validating_uniqueness(
attribute_type: :string,
- attribute_options: { limit: 1 }
+ attribute_options: { limit: 1 },
)
expect(record).to validate_uniqueness
@@ -405,7 +405,7 @@
it 'can save the subject without the attributes being set' do
options = {
attribute_name: :attr,
- additional_attributes: [:required_attribute]
+ additional_attributes: [:required_attribute],
}
model = define_model_validating_uniqueness(options) do |m|
m.validates_presence_of :attr
@@ -434,8 +434,8 @@
it 'can save the subject' do
options = {
additional_attributes: [
- { name: :required_attribute, options: { null: false } }
- ]
+ { name: :required_attribute, options: { null: false } },
+ ],
}
model = define_model_validating_uniqueness(options)
record = model.new
@@ -449,8 +449,8 @@
it 'raises a useful exception' do
options = {
additional_attributes: [
- { name: :required_attribute, options: { null: false } }
- ]
+ { name: :required_attribute, options: { null: false } },
+ ],
}
model = define_model_validating_uniqueness(options)
@@ -459,7 +459,7 @@
end
expect(&assertion).to raise_error(
- described_class::ExistingRecordInvalid
+ described_class::ExistingRecordInvalid,
)
end
end
@@ -468,7 +468,7 @@
context 'and the model has required attributes other than the attribute being validated' do
it 'can save the subject without the attributes being set' do
options = {
- additional_attributes: [:required_attribute]
+ additional_attributes: [:required_attribute],
}
model = define_model_validating_uniqueness(options) do |m|
m.validates_presence_of :required_attribute
@@ -493,8 +493,8 @@
it 'can save the subject' do
options = {
additional_attributes: [
- { name: :required_attribute, options: { null: false } }
- ]
+ { name: :required_attribute, options: { null: false } },
+ ],
}
model = define_model_validating_uniqueness(options)
@@ -506,7 +506,7 @@
context 'and the model has required attributes other than the attribute being validated, set beforehand' do
it 'can save the subject' do
options = {
- additional_attributes: [:required_attribute]
+ additional_attributes: [:required_attribute],
}
model = define_model_validating_uniqueness(options) do |m|
m.validates_presence_of :required_attribute
@@ -522,7 +522,7 @@
context 'when the validation has no scope and a scope is specified' do
it 'rejects with an appropriate failure message' do
model = define_model_validating_uniqueness(
- additional_attributes: [:other]
+ additional_attributes: [:other],
)
create_record_from(model)
record = build_record_from(model)
@@ -547,7 +547,7 @@
it 'rejects with an appropriate failure message' do
record = build_record_validating_uniqueness(
attribute_value: 'some value',
- validation_options: { message: 'bad value' }
+ validation_options: { message: 'bad value' },
)
assertion = lambda do
@@ -576,7 +576,7 @@
it 'rejects with an appropriate failure message' do
record = build_record_validating_uniqueness(
attribute_value: 'some value',
- validation_options: { message: 'something else entirely' }
+ validation_options: { message: 'something else entirely' },
)
assertion = lambda do
@@ -606,7 +606,7 @@
context 'when the given and actual messages match' do
it 'accepts' do
record = build_record_validating_uniqueness(
- validation_options: { message: 'bad value' }
+ validation_options: { message: 'bad value' },
)
expect(record).
to validate_uniqueness.
@@ -620,7 +620,7 @@
it 'rejects with an appropriate failure message' do
record = build_record_validating_uniqueness(
attribute_value: 'some value',
- validation_options: { message: 'something else entirely' }
+ validation_options: { message: 'something else entirely' },
)
assertion = lambda do
@@ -650,7 +650,7 @@
context 'when the given and actual messages match' do
it 'accepts' do
record = build_record_validating_uniqueness(
- validation_options: { message: 'bad value' }
+ validation_options: { message: 'bad value' },
)
expect(record).
to validate_uniqueness.
@@ -668,7 +668,7 @@
attribute_name: :attr,
default_value: 'some value',
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr is case-sensitively unique, but
this could not be proved.
After taking the given Example, whose :attr is ‹"some valuf"›, and
@@ -687,15 +687,15 @@
yourself, or do something different altogether.
MESSAGE
- }
- }
+ },
+ },
)
it 'fails when used in the negative' do
assertion = lambda do
record = build_record_validating_uniqueness(
attribute_type: :string,
- attribute_options: { limit: 1 }
+ attribute_options: { limit: 1 },
)
expect(record).not_to validate_uniqueness
@@ -730,8 +730,8 @@
record = build_record_validating_uniqueness(
scopes: [
{ type: :boolean, name: :scope1, value: true },
- { type: :boolean, name: :scope2, value: true }
- ]
+ { type: :boolean, name: :scope2, value: true },
+ ],
)
expect(record).to validate_uniqueness.scoped_to(:scope1, :scope2)
end
@@ -740,8 +740,8 @@
record = build_record_validating_uniqueness(
scopes: [
{ type: :boolean, name: :scope1, value: false },
- { type: :boolean, name: :scope2, value: false }
- ]
+ { type: :boolean, name: :scope2, value: false },
+ ],
)
expect(record).to validate_uniqueness.scoped_to(:scope1, :scope2)
end
@@ -750,8 +750,8 @@
record = build_record_validating_uniqueness(
scopes: [
{ type: :boolean, name: :scope1, value: true },
- { type: :boolean, name: :scope2, value: false }
- ]
+ { type: :boolean, name: :scope2, value: false },
+ ],
)
expect(record).to validate_uniqueness.scoped_to(:scope1, :scope2)
end
@@ -764,7 +764,7 @@
context 'when one of the scoped attributes is an enum' do
it 'accepts' do
record = build_record_validating_scoped_uniqueness_with_enum(
- enum_scope: :scope
+ enum_scope: :scope,
)
expect(record).to validate_uniqueness.scoped_to(:scope)
end
@@ -774,7 +774,7 @@
record = build_record_validating_scoped_uniqueness_with_enum(
enum_scope: :scope1,
additional_scopes: [:scope2],
- additional_attributes: [:other]
+ additional_attributes: [:other],
)
assertion = lambda do
@@ -799,7 +799,7 @@
it 'rejects with an appropriate failure message' do
record = build_record_validating_scoped_uniqueness_with_enum(
enum_scope: :scope1,
- additional_scopes: [:scope2]
+ additional_scopes: [:scope2],
)
assertion = lambda do
@@ -895,7 +895,7 @@
end
end
- context "when an existing record that is not the first has a nil value for the scoped attribute" do
+ context 'when an existing record that is not the first has a nil value for the scoped attribute' do
# This fails intermittently
# it 'still works' do
# model = define_model_validating_uniqueness(scopes: [:scope])
@@ -913,7 +913,7 @@
it 'accepts' do
record = build_record_validating_uniqueness(
attribute_type: :string,
- validation_options: { case_sensitive: true }
+ validation_options: { case_sensitive: true },
)
expect(record).to validate_uniqueness
@@ -939,7 +939,7 @@
record = build_record_validating_uniqueness(
attribute_type: :string,
attribute_value: 'some value',
- validation_options: { case_sensitive: true }
+ validation_options: { case_sensitive: true },
)
assertion = lambda do
@@ -965,7 +965,7 @@
it 'rejects with an appropriate failure message' do
record = build_record_validating_uniqueness(
attribute_type: :string,
- validation_options: { case_sensitive: false }
+ validation_options: { case_sensitive: false },
)
assertion = lambda do
@@ -992,7 +992,7 @@
it 'accepts' do
record = build_record_validating_uniqueness(
attribute_type: :string,
- validation_options: { case_sensitive: false }
+ validation_options: { case_sensitive: false },
)
expect(record).to validate_uniqueness.case_insensitive
@@ -1006,7 +1006,7 @@
attribute_name: :attr,
default_value: 'some value',
changing_values_with: :next_value,
- expected_message: <<-MESSAGE.strip
+ expected_message: <<-MESSAGE.strip,
Expected Example to validate that :attr is case-insensitively unique,
but this could not be proved.
After taking the given Example, whose :attr is ‹"some valuf"›, and
@@ -1024,8 +1024,8 @@
of the uniqueness matcher. Otherwise, you may need to write the test
yourself, or do something different altogether.
MESSAGE
- }
- }
+ },
+ },
)
def validation_matcher_scenario_args
@@ -1042,7 +1042,7 @@ def configure_validation_matcher(matcher)
context 'given a new record whose attribute is nil' do
it 'accepts' do
model = define_model_validating_uniqueness(
- validation_options: { allow_nil: true }
+ validation_options: { allow_nil: true },
)
record = build_record_from(model, attribute_name => nil)
expect(record).to validate_uniqueness.allow_nil
@@ -1052,7 +1052,7 @@ def configure_validation_matcher(matcher)
context 'given an existing record whose attribute is nil' do
it 'accepts' do
model = define_model_validating_uniqueness(
- validation_options: { allow_nil: true }
+ validation_options: { allow_nil: true },
)
record = create_record_from(model, attribute_name => nil)
expect(record).to validate_uniqueness.allow_nil
@@ -1114,7 +1114,7 @@ def configure_validation_matcher(matcher)
context 'given a new record whose attribute is nil' do
it 'accepts' do
model = define_model_validating_uniqueness(
- validation_options: { allow_blank: true }
+ validation_options: { allow_blank: true },
)
record = build_record_from(model, attribute_name => nil)
expect(record).to validate_uniqueness.allow_blank
@@ -1124,7 +1124,7 @@ def configure_validation_matcher(matcher)
context 'given an existing record whose attribute is nil' do
it 'accepts' do
model = define_model_validating_uniqueness(
- validation_options: { allow_blank: true }
+ validation_options: { allow_blank: true },
)
record = create_record_from(model, attribute_name => nil)
expect(record).to validate_uniqueness.allow_blank
@@ -1135,7 +1135,7 @@ def configure_validation_matcher(matcher)
it 'accepts' do
model = define_model_validating_uniqueness(
attribute_type: :string,
- validation_options: { allow_blank: true }
+ validation_options: { allow_blank: true },
)
record = build_record_from(model, attribute_name => '')
expect(record).to validate_uniqueness.allow_blank
@@ -1146,7 +1146,7 @@ def configure_validation_matcher(matcher)
it 'accepts' do
model = define_model_validating_uniqueness(
attribute_type: :string,
- validation_options: { allow_blank: true }
+ validation_options: { allow_blank: true },
)
record = create_record_from(model, attribute_name => '')
expect(record).to validate_uniqueness.allow_blank
@@ -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
@@ -1241,7 +1233,7 @@ def configure_validation_matcher(matcher)
context 'given a new record whose attribute is empty' do
it 'rejects with an appropriate failure message' do
model = define_model_validating_uniqueness(
- attribute_type: :string
+ attribute_type: :string,
)
record = build_record_from(model, attribute_name => '')
@@ -1267,7 +1259,7 @@ def configure_validation_matcher(matcher)
context 'given an existing record whose attribute is empty' do
it 'rejects with an appropriate failure message' do
model = define_model_validating_uniqueness(
- attribute_type: :string
+ attribute_type: :string,
)
record = create_record_from(model, attribute_name => '')
@@ -1296,7 +1288,7 @@ def configure_validation_matcher(matcher)
user_model = define_model 'User'
favorite_columns = {
favoriteable_id: { type: :integer, options: { null: false } },
- favoriteable_type: { type: :string, options: { null: false } }
+ favoriteable_type: { type: :string, options: { null: false } },
}
favorite_model = define_model 'Favorite', favorite_columns do
if respond_to?(:attr_accessible)
@@ -1324,7 +1316,7 @@ def configure_validation_matcher(matcher)
user_model = define_model 'Models::User'
favorite_columns = {
favoriteable_id: { type: :integer, options: { null: false } },
- favoriteable_type: { type: :string, options: { null: false } }
+ favoriteable_type: { type: :string, options: { null: false } },
}
favorite_model = define_model 'Models::Favorite', favorite_columns do
if respond_to?(:attr_accessible)
@@ -1370,7 +1362,7 @@ def configure_validation_matcher(matcher)
context 'and the matcher is ensuring that the validation is case-sensitive' do
it 'rejects with an appropriate failure message' do
model = define_model_validating_uniqueness(
- attribute_name: :name
+ attribute_name: :name,
)
model.class_eval do
@@ -1412,7 +1404,7 @@ def name=(name)
context 'and the matcher is ignoring case sensitivity' do
it 'accepts (and not raise an error)' do
model = define_model_validating_uniqueness(
- attribute_name: :name
+ attribute_name: :name,
)
model.class_eval do
@@ -1479,9 +1471,7 @@ def name=(name)
record = build_record_validating_uniqueness(attribute_type: :boolean)
running_validation = -> { expect(record).to validate_uniqueness }
message =
- 'You attempted to assign a value which is not explicitly `true` or ' +
- '`false`'
-
+ 'You attempted to assign a value which is not explicitly `true` or `false`'
expect(&running_validation).not_to print_warning_including(message)
end
end
@@ -1492,7 +1482,7 @@ def default_attribute
{
value_type: :string,
column_type: :string,
- options: { array: false, null: true }
+ options: { array: false, null: true },
}
end
@@ -1521,7 +1511,7 @@ def column_options_from(attributes)
attributes.inject({}) do |options, attribute|
options[attribute[:name]] = {
type: attribute[:column_type],
- options: attribute.fetch(:options, {})
+ options: attribute.fetch(:options, {}),
}
options
end
@@ -1535,7 +1525,7 @@ def attributes_with_values_for(model)
else
dummy_value_for(
attribute[:value_type],
- array: attribute[:options][:array]
+ array: attribute[:options][:array],
)
end
end
@@ -1548,7 +1538,7 @@ def dummy_value_for(attribute_type, array: false)
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)
@@ -1566,9 +1556,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)
@@ -1579,7 +1567,7 @@ def define_model_validating_uniqueness(options = {}, &block)
name: attribute_name,
value_type: attribute_type,
column_type: attribute_type,
- options: attribute_options
+ options: attribute_options,
)
if options.key?(:attribute_value)
@@ -1589,7 +1577,7 @@ def define_model_validating_uniqueness(options = {}, &block)
scope_attributes = normalize_attributes(options.fetch(:scopes, []))
scope_attribute_names = scope_attributes.map { |attr| attr[:name] }
additional_attributes = normalize_attributes(
- options.fetch(:additional_attributes, [])
+ options.fetch(:additional_attributes, []),
)
attributes = [attribute] + scope_attributes + additional_attributes
validation_options = options.fetch(:validation_options, {})
@@ -1600,12 +1588,10 @@ def define_model_validating_uniqueness(options = {}, &block)
validation_options.merge(scope: scope_attribute_names)
if m.respond_to?(:attr_accessible)
- attributes.each do |attr|
- m.attr_accessible(attr[:name])
- end
+ attributes.each { |attr| m.attr_accessible(attr[:name]) }
end
- block.call(m) if block
+ block&.call(m)
end
model_attributes[model] = attributes
@@ -1621,9 +1607,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
@@ -1632,7 +1616,7 @@ def build_record_validating_scoped_uniqueness_with_enum(options = {})
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]
@@ -1662,7 +1646,7 @@ def attribute_name
def validation_matcher_scenario_args
super.deep_merge(
matcher_name: :validate_uniqueness_of,
- model_creator: :"active_record/uniqueness_matcher"
+ model_creator: :"active_record/uniqueness_matcher",
)
end
end
diff --git a/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb b/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb
index 88be260ab..1eef2a092 100644
--- a/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb
+++ b/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb
@@ -156,7 +156,7 @@ module Shoulda::Matchers::Doublespeak
actual_calls = [
{ args: [:some, :args, :here] },
- { args: [:some, :args], block: -> { :whatever } }
+ { args: [:some, :args], block: -> { :whatever } },
]
instance = klass.new
instance.a_method(*actual_calls[0][:args])
@@ -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 815829c6b..295a84a05 100644
--- a/spec/unit/shoulda/matchers/doublespeak/double_spec.rb
+++ b/spec/unit/shoulda/matchers/doublespeak/double_spec.rb
@@ -29,7 +29,7 @@ module Shoulda::Matchers::Doublespeak
build_world,
:klass,
:a_method,
- implementation
+ implementation,
)
double.to_return(&sent_block)
expect(actual_block).to eq sent_block
@@ -41,7 +41,7 @@ module Shoulda::Matchers::Doublespeak
build_world,
:klass,
:a_method,
- implementation
+ implementation,
)
double.to_return(:implementation)
@@ -60,7 +60,7 @@ module Shoulda::Matchers::Doublespeak
build_world,
:klass,
:a_method,
- implementation
+ implementation,
)
double.to_return(:value, &sent_block)
expect(actual_block).to eq sent_block
@@ -77,7 +77,7 @@ module Shoulda::Matchers::Doublespeak
build_world,
klass,
method_name,
- implementation
+ implementation,
)
args = [:any, :args]
block = -> {}
@@ -87,7 +87,7 @@ module Shoulda::Matchers::Doublespeak
method_name: method_name,
args: args,
block: block,
- caller: :some_caller
+ caller: :some_caller,
)
double.activate
@@ -103,14 +103,14 @@ module Shoulda::Matchers::Doublespeak
it 'restores the original method after being doubled' do
klass = create_class(a_method: 42)
world = build_world(
- original_method_for: klass.instance_method(:a_method)
+ original_method_for: klass.instance_method(:a_method),
)
instance = klass.new
double = described_class.new(
world,
klass,
:a_method,
- build_implementation
+ build_implementation,
)
double.activate
@@ -122,14 +122,14 @@ module Shoulda::Matchers::Doublespeak
method_name = :a_method
klass = create_class(method_name => 42)
world = build_world(
- original_method_for: klass.instance_method(:a_method)
+ original_method_for: klass.instance_method(:a_method),
)
instance = klass.new
double = described_class.new(
world,
klass,
:a_method,
- build_implementation
+ build_implementation,
)
double.activate
@@ -145,7 +145,7 @@ module Shoulda::Matchers::Doublespeak
build_world,
klass,
:a_method,
- build_implementation
+ build_implementation,
)
double.deactivate
@@ -159,7 +159,7 @@ module Shoulda::Matchers::Doublespeak
build_world,
:a_klass,
:a_method,
- :an_implementation
+ :an_implementation,
)
double.record_call(:some_call)
expect(double.calls.last).to eq :some_call
@@ -179,20 +179,19 @@ module Shoulda::Matchers::Doublespeak
method_called = true
end
world = build_world(
- original_method_for: klass.instance_method(method_name)
+ original_method_for: klass.instance_method(method_name),
)
instance = klass.new
call = double('call',
object: instance,
method_name: method_name,
args: expected_args,
- block: expected_block
- )
+ block: expected_block,)
double = described_class.new(
world,
klass,
method_name,
- :an_implementation
+ :an_implementation,
)
double.activate
@@ -211,7 +210,7 @@ module Shoulda::Matchers::Doublespeak
world,
:klass,
method_name,
- :an_implementation
+ :an_implementation,
)
expect { double.call_original_method(call) }.not_to raise_error
end
@@ -225,7 +224,7 @@ module Shoulda::Matchers::Doublespeak
world,
klass,
method_name,
- build_implementation
+ build_implementation,
)
end
instance = klass.new
@@ -251,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
@@ -264,7 +263,7 @@ def build_world(methods = {})
defaults = {
original_method_for: nil,
store_original_method_for: nil,
- doubles_activated?: nil
+ doubles_activated?: nil,
}
double('world', defaults.merge(methods))
end
diff --git a/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb b/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb
index 4500b3b8f..e973f7fc7 100644
--- a/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb
+++ b/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb
@@ -41,12 +41,14 @@ 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,
args: expected_args,
- block: expected_block
+ block: expected_block,
)
actual_object, actual_args, actual_block = []
implementation = described_class.new
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 d0106b4c6..0eb0b44e3 100644
--- a/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb
@@ -180,7 +180,7 @@ def company
message = [
'Expected PostOffice to delegate #deliver_mail to the #mailman object.',
'',
- 'Method calls sent to PostOffice#mailman: (none)'
+ 'Method calls sent to PostOffice#mailman: (none)',
].join("\n")
expect {
@@ -194,7 +194,7 @@ def company
message = [
'Expected PostOffice to delegate .deliver_mail to the .mailman object.',
'',
- 'Method calls sent to PostOffice.mailman: (none)'
+ 'Method calls sent to PostOffice.mailman: (none)',
].join("\n")
expect {
@@ -264,7 +264,7 @@ def mailman
define_class('Mailman')
define_class('PostOffice') do
- def deliver_mail(*args)
+ def deliver_mail(*)
mailman.deliver_mail('221B Baker St.', hastily: true)
end
@@ -306,7 +306,7 @@ def mailman
'',
'Method calls sent to PostOffice#mailman:',
'',
- '1) deliver_mail("221B Baker St.", {:hastily=>true})'
+ '1) deliver_mail("221B Baker St.", {:hastily=>true})',
].join("\n")
expect {
@@ -364,7 +364,7 @@ def mailman
'',
'Method calls sent to PostOffice#mailman:',
'',
- '1) deliver_mail_and_avoid_dogs()'
+ '1) deliver_mail_and_avoid_dogs()',
].join("\n")
expect {
@@ -394,7 +394,7 @@ def country
end
person = Person.new
- expect(person).to delegate_method(:hello). to(:country).with_prefix
+ expect(person).to delegate_method(:hello).to(:country).with_prefix
end
end
@@ -412,7 +412,7 @@ def country
'Expected Person to delegate #country_hello to the #country object as',
'#hello.',
'',
- 'Method calls sent to Person#country: (none)'
+ 'Method calls sent to Person#country: (none)',
].join("\n")
person = Person.new
@@ -462,7 +462,7 @@ def country
'Expected Person to delegate #country_hello to the #country object as',
'#hello.',
'',
- 'Method calls sent to Person#country: (none)'
+ 'Method calls sent to Person#country: (none)',
].join("\n")
person = Person.new
@@ -514,7 +514,7 @@ def country
'Expected Person to delegate #county_hello to the #country object as',
'#hello.',
'',
- 'Method calls sent to Person#country: (none)'
+ 'Method calls sent to Person#country: (none)',
].join("\n")
person = Person.new
@@ -535,7 +535,8 @@ def country
it 'accepts' do
define_class('Person') do
delegate :hello, to: :country, allow_nil: true
- def country; end
+ def country
+ end
end
person = Person.new
@@ -548,7 +549,8 @@ def country; end
it 'rejects with the correct failure message' do
define_class('Person') do
delegate :hello, to: :country
- def country; end
+ def country
+ end
end
person = Person.new
@@ -578,7 +580,8 @@ def country; end
def_delegators :country, :hello
- def country; end
+ def country
+ end
end
person = Person.new
@@ -606,10 +609,12 @@ def country; end
context 'when the delegating method accounts for the delegate object being nil' do
it 'accepts' do
define_class('Person') do
- def country; end
+ def country
+ end
def hello
return unless country
+
country.hello
end
end
@@ -623,7 +628,8 @@ def hello
context 'when the delegating method does not account for the delegate object being nil' do
it 'rejects with the correct failure message' do
define_class('Person') do
- def country; end
+ def country
+ end
def hello
country.hello
diff --git a/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb b/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb
index 38f560230..179a4afb9 100644
--- a/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb
@@ -15,7 +15,7 @@
method: :get,
path: '/',
controller: 'things',
- action: 'index'
+ action: 'index',
)
is_expected.to(matcher)
@@ -34,7 +34,7 @@
method: :get,
path: '/',
controller: :things,
- action: 'index'
+ action: 'index',
)
is_expected.to(matcher)
diff --git a/spec/unit/shoulda/matchers/util/word_wrap_spec.rb b/spec/unit/shoulda/matchers/util/word_wrap_spec.rb
index 7e9f62aae..ba7b1f620 100644
--- a/spec/unit/shoulda/matchers/util/word_wrap_spec.rb
+++ b/spec/unit/shoulda/matchers/util/word_wrap_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
require 'shoulda/matchers/util/word_wrap'
-describe Shoulda::Matchers, ".word_wrap" do
- it "can wrap a simple paragraph" do
+describe Shoulda::Matchers, '.word_wrap' do
+ it 'can wrap a simple paragraph' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat
MESSAGE
@@ -13,7 +13,7 @@
MESSAGE
end
- it "does not split words up when wrapping" do
+ it 'does not split words up when wrapping' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean lusciousness, ipsum sit amet efficitur feugiat
MESSAGE
@@ -24,7 +24,7 @@
MESSAGE
end
- it "considers punctuation as part of a word" do
+ it 'considers punctuation as part of a word' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luscious, ipsum sit amet efficitur feugiat
MESSAGE
@@ -35,7 +35,7 @@
MESSAGE
end
- it "does not break at the maximum line length, but afterward" do
+ it 'does not break at the maximum line length, but afterward' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luscius, ipsum sit amet efficitur feugiat
MESSAGE
@@ -46,7 +46,7 @@
MESSAGE
end
- it "re-wraps entire paragraphs" do
+ it 're-wraps entire paragraphs' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
@@ -62,11 +62,11 @@
MESSAGE
end
- it "can wrap multiple paragraphs" do
+ it 'can wrap multiple paragraphs' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
-Etiam ultrices cursus ligula eget feugiat. Vestibulum eget tincidunt risus, non faucibus sem.
+Etiam ultrices cursus ligula eget feugiat. Vestibulum eget tincidunt risus, non faucibus sem.
MESSAGE
expect(wrapped_message).to eq(<<-MESSAGE.rstrip)
@@ -79,7 +79,7 @@
MESSAGE
end
- it "can wrap a bulleted list" do
+ it 'can wrap a bulleted list' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
* And the beat goes on.
@@ -93,7 +93,7 @@
MESSAGE
end
- it "re-wraps bulleted lists" do
+ it 're-wraps bulleted lists' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
* Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
@@ -112,7 +112,7 @@
MESSAGE
end
- it "can wrap a numbered list" do
+ it 'can wrap a numbered list' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
1. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
2. And the beat goes on.
@@ -126,7 +126,7 @@
MESSAGE
end
- it "re-wraps numbered lists" do
+ it 're-wraps numbered lists' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
1. Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
@@ -145,7 +145,7 @@
MESSAGE
end
- it "can wrap a numbered list, using x) instead of x. as the leader" do
+ it 'can wrap a numbered list, using x) instead of x. as the leader' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
1) Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat, dolor mauris fringilla erat, sed posuere diam ex ut velit.
2) And the beat goes on.
@@ -159,7 +159,7 @@
MESSAGE
end
- it "re-wraps numbered lists using x) instead of x. as the leader" do
+ it 're-wraps numbered lists using x) instead of x. as the leader' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
1) Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
@@ -196,9 +196,9 @@
MESSAGE
end
- context "given a string with a word longer than the max character limit" do
- context "which stands on its own" do
- it "simply returns the string" do
+ context 'given a string with a word longer than the max character limit' do
+ context 'which stands on its own' do
+ it 'simply returns the string' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
Foo bar baz and stuff and things Loremipsumdolorsitamet,consecteturadipiscingelit.Aeneanluctus,ipsumsitametefficiturfeugiat,
MESSAGE
@@ -210,8 +210,8 @@
end
end
- context "which is preceded by some text" do
- it "leaves the word on its own line" do
+ context 'which is preceded by some text' do
+ it 'leaves the word on its own line' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
Foo bar baz and stuff and things Loremipsumdolorsitamet,consecteturadipiscingelit.Aeneanluctus,ipsumsitametefficiturfeugiat,
MESSAGE
@@ -223,8 +223,8 @@
end
end
- context "which is followed by some text" do
- it "leaves the word on its own line" do
+ context 'which is followed by some text' do
+ it 'leaves the word on its own line' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.rstrip)
Loremipsumdolorsitamet,consecteturadipiscingelit.Aeneanluctus,ipsumsitametefficiturfeugiat, and something goes after this
MESSAGE
@@ -237,8 +237,8 @@
end
end
- context "when :indent is given" do
- it "uses the given indentation level when determining where to wrap lines" do
+ context 'when :indent is given' do
+ it 'uses the given indentation level when determining where to wrap lines' do
wrapped_message = described_class.word_wrap(<<-MESSAGE.strip, indent: 2)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean luctus, ipsum sit amet efficitur feugiat
MESSAGE
diff --git a/spec/unit_spec_helper.rb b/spec/unit_spec_helper.rb
index c35178673..18a01c23f 100644
--- a/spec/unit_spec_helper.rb
+++ b/spec/unit_spec_helper.rb
@@ -8,7 +8,7 @@
$VERBOSE = true
-Dir[ File.join(File.expand_path('../support/unit/**/*.rb', __FILE__)) ].sort.each do |file|
+Dir[File.join(File.expand_path('support/unit/**/*.rb', __dir__))].sort.each do |file|
require file
end
@@ -34,8 +34,8 @@
config.include UnitTests::Matchers
config.infer_spec_type_from_file_location!
- config.example_status_persistence_file_path = "spec/examples.txt"
- config.alias_it_behaves_like_to(:it_supports, "it supports")
+ config.example_status_persistence_file_path = 'spec/examples.txt'
+ config.alias_it_behaves_like_to(:it_supports, 'it supports')
config.before(:all, type: :controller) do
self.class.controller(ApplicationController) { }
diff --git a/tasks/documentation.rb b/tasks/documentation.rb
index 3abb38a71..9a6405c45 100644
--- a/tasks/documentation.rb
+++ b/tasks/documentation.rb
@@ -6,7 +6,7 @@ module Matchers
module DocumentationTasks
extend Rake::DSL
- def self.create
+ def self.create # rubocop:disable Metrics/MethodLength
publisher = DocumentationPublisher.new
namespace :docs do
@@ -14,30 +14,35 @@ def self.create
publisher.create_reference_to_gh_pages_branch
end
- file DocumentationPublisher.docs_dir => DocumentationPublisher.gh_pages_dir
+ file DocumentationPublisher.docs_dir =>
+ DocumentationPublisher.gh_pages_dir
- task :setup => DocumentationPublisher.docs_dir do
+ task setup: DocumentationPublisher.docs_dir do
publisher.reset_repo_directory
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"
+ raise ArgumentError, 'Missing version'
end
unless args.latest_version
- raise ArgumentError, "Missing latest_version"
+ raise ArgumentError, 'Missing latest_version'
end
- publisher.generate_docs_for(args.version, latest_version: args.latest_version)
+ publisher.generate_docs_for(
+ args.version,
+ latest_version: args.latest_version,
+ )
end
- desc 'Watch source files for this project for changes and autogenerate docs accordingly'
+ desc 'Watch source files for this project for changes and'\
+ ' autogenerate docs accordingly'
task :autogenerate do
require 'fssm'
- project_directory = File.expand_path(File.dirname(__FILE__) + "/..")
+ project_directory = File.expand_path("#{File.dirname(__FILE__)}/..")
regenerate_docs = proc do
print 'Regenerating docs... '
@@ -54,7 +59,8 @@ def self.create
FSSM.monitor do
path project_directory do
- glob '{README.md,CHANGELOG.md,.yardopts,docs/**/*.md,doc_config/yard/**/*.{rb,js,css,erb},lib/**/*.rb}'
+ glob '{README.md,CHANGELOG.md,.yardopts,docs/**/*.md,'\
+ 'doc_config/yard/**/*.{rb,js,css,erb},lib/**/*.rb}'
create(®enerate_docs)
update(®enerate_docs)
end
@@ -62,21 +68,28 @@ 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"
+ raise ArgumentError, 'Missing version'
end
unless args.latest_version
- raise ArgumentError, "Missing latest_version"
+ raise ArgumentError, 'Missing latest_version'
end
- publisher.generate_docs_for(args.version, latest_version: args.latest_version)
- publisher.publish_docs_for(args.version, latest_version: args.latest_version)
+ publisher.generate_docs_for(
+ args.version,
+ latest_version: args.latest_version,
+ )
+ publisher.publish_docs_for(
+ args.version,
+ latest_version: args.latest_version,
+ )
end
- desc "Generate docs for version #{DocumentationPublisher.current_version} and push them to GitHub"
- task :publish_latest => :setup do
+ desc 'Generate docs for version'\
+ " #{DocumentationPublisher.current_version} and push them to GitHub"
+ task publish_latest: :setup do
publisher.publish_latest_version
end
end
@@ -85,10 +98,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
@@ -103,7 +116,8 @@ def self.docs_dir
end
def create_reference_to_gh_pages_branch
- system "git clone git@github.com:#{GITHUB_USERNAME}/shoulda-matchers.git #{GH_PAGES_DIR} --branch gh-pages"
+ system "git clone git@github.com:#{GITHUB_USERNAME}"\
+ "/shoulda-matchers.git #{GH_PAGES_DIR} --branch gh-pages"
end
def reset_repo_directory
@@ -126,11 +140,13 @@ def generate_docs_for(version, options = {})
end
if options[:latest_version]
- generate_file_that_redirects_to_latest_version(options[:latest_version])
+ generate_file_that_redirects_to_latest_version(
+ options[:latest_version],
+ )
end
end
- def publish_docs_for(version, options = {})
+ def publish_docs_for(version, _options = {})
message = build_commit_message(version)
within_gh_pages_dir do
@@ -158,7 +174,10 @@ def add_version_to_index_page_for(ref, version)
within_docs_dir do
filename = "#{ref}/index.html"
content = File.read(filename)
- content.sub!(%r{shoulda-matchers.+
}, "shoulda-matchers (#{version})
")
+ content.sub!(
+ %r{shoulda-matchers.+
},
+ "shoulda-matchers (#{version})
",
+ )
File.open(filename, 'w') {|f| f.write(content) }
end
end
@@ -177,7 +196,7 @@ def generate_file_that_redirects_to_latest_version(version)
def determine_ref_from(version)
if version =~ /^\d+\.\d+\.\d+/
- 'v' + version
+ "v#{version}"
else
version
end