0

これをテストしているときに問題に直面すると、shoulda_matchers ensure_length_ofで長さが検証されます

モデル

class Plant < ActiveRecord::Base
  validates :code, :length => { :in => 2..6 } 
end

Rspec

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)>'

ありがとう!

4

1 に答える 1