From 0f8ab46b6235ea67683cc4eb1bab6956f1113600 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 20 Mar 2024 11:28:56 -0400 Subject: [PATCH 1/3] Add shoulda-matchers gem --- Gemfile | 2 ++ Gemfile.lock | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index 135b94c7739..1ab3e555863 100644 --- a/Gemfile +++ b/Gemfile @@ -155,6 +155,8 @@ group :test do # Test harness fo rack components gem 'rack-test', '~> 2.1' + gem 'shoulda-matchers' + # Coverage formatter for RSpec test if DISABLE_SIMPLECOV is false gem 'simplecov', '~> 0.22', require: false gem 'simplecov-lcov', '~> 0.8', require: false diff --git a/Gemfile.lock b/Gemfile.lock index c08c14cb5cb..e0938c96085 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -788,6 +788,8 @@ GEM rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) semantic_range (3.0.0) + shoulda-matchers (6.2.0) + activesupport (>= 5.2.0) sidekiq (6.5.12) connection_pool (>= 2.2.5, < 3) rack (~> 2.0) @@ -1036,6 +1038,7 @@ DEPENDENCIES sanitize (~> 6.0) scenic (~> 1.7) selenium-webdriver + shoulda-matchers sidekiq (~> 6.5) sidekiq-bulk (~> 0.2.0) sidekiq-scheduler (~> 5.0) From 9f758fe4b0bcaca7b6ce2899461f2a12e93f7d2f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 20 Mar 2024 11:29:15 -0400 Subject: [PATCH 2/3] Configure shoulda matchers to integrate with rspec --- spec/support/shoulda_matchers.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 spec/support/shoulda_matchers.rb diff --git a/spec/support/shoulda_matchers.rb b/spec/support/shoulda_matchers.rb new file mode 100644 index 00000000000..edcf9dd8590 --- /dev/null +++ b/spec/support/shoulda_matchers.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end From db88595632e675e024e02b54efa1caa718fe1b44 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 12 Jul 2024 10:26:15 -0400 Subject: [PATCH 3/3] Use `validate_presence_of` for `Account.username` spec --- spec/models/account_spec.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index dfb1f5bc615..981d9966117 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -714,11 +714,7 @@ RSpec.describe Account do end describe 'validations' do - it 'is invalid without a username' do - account = Fabricate.build(:account, username: nil) - account.valid? - expect(account).to model_have_error_on_field(:username) - end + it { is_expected.to validate_presence_of(:username) } it 'squishes the username before validation' do account = Fabricate(:account, domain: nil, username: " \u3000bob \t \u00a0 \n ")