我的模型看起来像这样:
class User < ActiveRecord::Base
belongs_to :administration
validates :administration, presence: true, allow_blank: true
end
和看起来像这样的规范:
require 'spec_helper'
describe User, type: :model do
it { is_expected.to validate_presence_of(:administration).allow_blank }
end
运行此规范会返回我:
NoMethodError:
undefined method `allow_blank' for #<Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher:0x0000000b7f27a8>
为什么?
答案 0 :(得分:0)
it { should allow_value("", nil).for(:administration) }
应该有用。