From d9036f034f3719d3d97c76c188c3e7eecdb3a6b1 Mon Sep 17 00:00:00 2001 From: texpert Date: Mon, 13 Jan 2025 10:21:37 +0200 Subject: [PATCH] Fix the `missing password confirmation` test case Add `require 'pathname'` to the spec_helper.rb to avoid `Uninitialized Pathname constant` error Use expect(response.body).to include('password_confirmation') to avoid errors caused by changes in responses on different Rails' versions --- spec/requests/admin/users_controller/updated_ajax_spec.rb | 6 +++--- spec/spec_helper.rb | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/requests/admin/users_controller/updated_ajax_spec.rb b/spec/requests/admin/users_controller/updated_ajax_spec.rb index 196dde1c..a377b075 100644 --- a/spec/requests/admin/users_controller/updated_ajax_spec.rb +++ b/spec/requests/admin/users_controller/updated_ajax_spec.rb @@ -49,10 +49,10 @@ patch "/admin/users/#{current_user.id}/updated_ajax", params: { password: { password: 'new password' } } expect(response.status).to eql(400) - expect(response.body).to eql( - 'ERROR: ActionController::ParameterMissing, ' \ - 'param is missing or the value is empty or invalid: password_confirmation' + expect(response.body).to start_with( + 'ERROR: ActionController::ParameterMissing, param is missing or the value is empty' ) + expect(response.body).to include('password_confirmation') expect(current_user.reload.authenticate('secret')).to be_truthy expect(current_user.reload.authenticate('new password')).to be_falsey end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 58df177e..a81f54d7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ ENV['RAILS_ENV'] ||= 'test' +require 'pathname' CAMALEON_CMS_ROOT = Pathname.new(__FILE__).join('../..') require File.expand_path('dummy/config/environment.rb', __dir__)