0
brief.rb早该且小于语法
# encoding: utf-8
class Brief < ActiveRecord::Base
belongs_to :project
validate :can_only_be_edited_if_project_is_not_started
validates_presence_of :project, :inverse_of => :brief
validates_numericality_of :duration, :only_integer => true, :less_than_or_equal_to => 15, :greater_than_or_equal_to => 5
validates_length_of :brand_info, :maximum => 4000
def can_only_be_edited_if_project_is_not_started
errors.add(:base, 'Proje can't edit if duration is end!') if
!project.nil? && !project.brief_can_be_edited?
end
end
如何测试持续时间应大于或等于5且小于或等于15早该宝石?
我尝试下面的代码
brief_spec.rb
it { should ensure_inclusion_of(:duration).in_range(5..15)
,但我得到这个错误
1) Brief non-specific tests
Failure/Error: it { should ensure_inclusion_of(:duration).in_range(5..15) }
Did not expect errors to include "It's not suitable word" when duration is set to 4, got error:
# ./spec/models/brief_spec.rb:23:in `block (3 levels) in <top (required)>'
您能否澄清'没有工作' - 您是否遇到异常或失败?请发布你看到的结果。 – PinnyM 2013-04-04 14:46:11
谢谢你的建议。我编辑了问题。 – 2013-04-04 14:51:29
您是否尝试过http://rubydoc.info/gems/thoughtbot-shoulda/2.11.1/Shoulda/ActiveRecord/Matchers#ensure_inclusion_of-instance_method? – pjam 2013-04-04 14:53:42