とgems を使用して ( Reformgemを使用して) フォームの仕様を設定しています。検証の問題が発生している理由がわかりません。 RSpecShoulda Matchers
私の実際の構成:
ruby '2.5.1'
gem 'rails', '~> 5.2.0'
gem 'rspec-rails', '~> 3.8'
gem 'shoulda-matchers', '~> 4.0'
gem 'reform-rails', '~> 0.1'
フォームでさまざまな種類の長さの検証を既に試しました。しかし、物事をより良くするものは何もありません。
テストに使用される最小形式は次のとおりです。
# frozen_string_literal: true
class UserForm < Reform::Form
# == Properties ==========================================================
property :nickname
# == Validations ==========================================================
validates :nickname, presence: true, length: { minimum: 3, maximum: 100 }
end
仕様は次のとおりです。
# frozen_string_literal: true
RSpec.describe UserForm, type: :model do
subject { described_class.new(User.new) }
it { is_expected.to validate_presence_of :nickname }
it { is_expected.to validate_length_of(:nickname).is_at_least(3).is_at_most(100) }
end
validate_presence_ofマッチャーが完全に機能することに注意してください。
私はRSpec出力として持っています:
1) UserForm should validate that the length of :nickname is between 3 and 100
Failure/Error: it { is_expected.to validate_length_of(:nickname).is_at_least(3).is_at_most(100) }
Expected UserForm to validate that the length of :nickname is between
3 and 100, but this could not be proved.
After setting :nickname to ‹"xxx"›, the matcher expected the
UserForm to be valid, but it was invalid instead, producing these
validation errors:
* nickname: ["is too short (at least 3 characters)"]
私は明らかに、これらの種類の検証を機能させることを除いています。
ここで助けが見つかることを願っています:)