【发布时间】:2011-06-24 01:20:51
【问题描述】:
完全被这个难住了。我发誓,这看起来应该有效,但它没有。测试数据库已更新(rake db:migrate - rake:db:test:clone)。我希望我在做一些愚蠢的事情。
完全披露,我正在运行 3.1 RC4。
型号
class ExerciseSet < ActiveRecord::Base
TYPES = %w[time rep]
validates :type,
:presence => true,
:inclusion => { :in => TYPES }
end
规格文件
require 'spec_helper'
describe ExerciseSet do
before(:each) do
@attr = { :value => 12,
:value_max => 15,
:type => "timed",
:target => "range"
}
end
describe "type" do
it "must be either 'time' or 'rep'" do
values = %w[time rep]
values.each do |value|
exercise_instance = ExerciseSet.new(@attr.merge(:type => value))
exercise_instance.should be_valid
end
end
end
end
输出
Failures:
1) ExerciseSet type must be either 'time' or 'rep'
Failure/Error: exercise_instance.should be_valid
expected valid? to return true, got false
# ./spec/models/exercise_set_spec.rb:19:in `block (4 levels) in <top (required)>'
# ./spec/models/exercise_set_spec.rb:17:in `each'
# ./spec/models/exercise_set_spec.rb:17:in `block (3 levels) in <top (required)>'
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 rspec rspec2