当我测试这个时遇到一个问题,用 shoulda_matchers ensure_length_of验证长度
模型
class Plant < ActiveRecord::Base
validates :code, :length => { :in => 2..6 }
end
规格
require 'spec_helper'
describe Plant do
before { @plant = FactoryGirl.create(:plant) }
it { should ensure_length_of(:code).is_at_least(2).with_message("is too short (minimum is 2 characters)")}
end
错误:
Failures:
1) Plant
Failure/Error: it { should ensure_length_of(:code).is_at_least(2).with_message("is too short (minimum is 2 characters)")}
Did not expect errors to include "is too short (minimum is 2 characters)" when naics_code is set to "xx", got error: is too short (minimum is 2 characters)
# ./spec/models/plant_spec.rb:11:in `block (2 levels) in <top (required)>'
谢谢!