You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When errors.format translation is defined differently than %{attribute} %{message}, a test using validate_presence_of
matcher with strict seems not to be proved.
class A
incude ActiveModel::Model
include ActiveModel::Validations
attr_accessor :value
validates :value, presence: true, strict: true
end
class MenuItemTest < ActiveSupport::TestCase
subject { A.new }
context "Validations" do
should validate_presence_of(:value).strict
end
end
The test above isn't proved with message like;
After setting :value to ‹nil›, the matcher expected the
A to be invalid and to raise a validation
exception with message "Value を入力してください". The record was indeed
invalid, but the exception message was "Valueを入力してください"
instead.
The matcher seems to expect a space exists between attribute name and message, but actually doesn't.
Problem
When
errors.format
translation is defined differently than%{attribute} %{message}
, a test usingvalidate_presence_of
matcher with
strict
seems not to be proved.Example
If the translations are defined as;
And if you write a test as below;
The test above isn't proved with message like;
The matcher seems to expect a space exists between attribute name and message, but actually doesn't.
Possible Solution
Taking
errors.format
definition into account might be a good solution.Seeing how Ruby on Rails raise exceptions, it uses
errors.format
to compose attribute name and message into a string.https://github.com/rails/rails/blob/4bbd05c90e5a62c0316307b3ca7c2262ed98b567/activemodel/lib/active_model/errors.rb#L290-L294
But validation matcher seems to check messages with fixed format.
shoulda-matchers/lib/shoulda/matchers/active_model/allow_value_matcher.rb
Line 615 in 206d2da
Changing this code into the same manner as in RoR may solve the problem.
The text was updated successfully, but these errors were encountered: