From 0bac1efe72a1f6a8afeb1b41969e079480f6d3d4 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 1 Mar 2023 18:53:27 -0300 Subject: [PATCH] Expand tests to check for the actual validatable exception message This was raising a `FrozenError` on Ruby < 3 where interpolated strings were considered frozen. This [changed in Ruby 3], since such strings are dynamic there's no point in freezing them by default. The test wasn't catching this because `FrozenError` actually inherits from `RuntimeError`: >> FrozenError.ancestors => [FrozenError, RuntimeError, StandardError, Exception, Object ...] So the exception check passed. Now we're also checking for the error message to ensure it raised the exception we really expected there. Closes #5465 [changed in Ruby 3] https://bugs.ruby-lang.org/issues/17104 --- test/models/validatable_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/models/validatable_test.rb b/test/models/validatable_test.rb index f96cfa9182..d3b5c9dc00 100644 --- a/test/models/validatable_test.rb +++ b/test/models/validatable_test.rb @@ -110,9 +110,12 @@ class ValidatableTest < ActiveSupport::TestCase end test 'should not be included in objects with invalid API' do - assert_raise RuntimeError do + exception = assert_raise RuntimeError do Class.new.send :include, Devise::Models::Validatable end + + expected_message = /Could not use :validatable module since .* does not respond to the following methods: validates_presence_of.*/ + assert_match expected_message, exception.message end test 'required_fields should be an empty array' do