模型
validates_length_of :description, :maximum => 255, :allow_nil => true
Run Code Online (Sandbox Code Playgroud)
spec_file
it { should ensure_length_of(:description).is_at_most(255).allow_nil }
Run Code Online (Sandbox Code Playgroud)
回归
Failure/Error: it { should ensure_length_of(:description).is_at_most(255).allow_nil }
NoMethodError:
undefined method `allow_nil' for #<Shoulda::Matchers::ActiveModel::EnsureLengthOfMatcher:0x0000000acb03e0>
Run Code Online (Sandbox Code Playgroud)
请帮忙!