我目前正在 Sinatra/Datamapper 中测试这个类
class Score
include DataMapper::Resource
property :score, Integer
property :created_at, DateTime, :default => DateTime.now, :lazy => [:show]
property :updated_at, DateTime, :default => DateTime.now, :lazy => [:show]
belongs_to :pageant, :key => true
belongs_to :candidate, :key => true
belongs_to :category, :key => true
belongs_to :judge, :key => true
end
通过这个 rspec 测试
it 'that can be inserted by a judge if a pageant is active' do
score_count = Score.all.length
post '/score', @correct_score_data
Score.all.length.should eq score_count+1
end
it 'cannot be duplicated if it has been sent' do
score_count = Score.all.length
post '/score', @correct_score_data
Score.all.length.should eq score_count
end
基本上应该发生的是,法官只能为特定类别+候选人+选美组合发送一次分数,之后我想否认下一个分数。现在,当我运行它时,我得到一个 IntegrityError (这是我所期望的)。我如何告诉 rspec 我“希望看到这个错误”?你们也可以批评我的代码,我还在一起学习所有这些