使用lambda测试Rails中的回调?
|
我有一个基于redis的新闻提要,当某些事件发生时,它会通过回调将项目插入其中。例如,当用户在书上记笔记时,便将其插入到书的读者的新闻提要中。
class Note < ActiveRecord::Base
after_save do |note|
notify_the note.book.readers
end
...
end
现在这很好,我99%的确定它可以正常工作,因为我可以查看自己的供稿并查看其中的注释。我的问题是使用最新的rspec-rails在Rails 3上对其进行测试。
由于某种原因,通过了:
spec/models/note_spec.rb
describe \"note creation\" do
it \"should notify the readers of the book the note is on\" do
@user.feed.count.should == 0
@note.save!
@user.feed.count.should == 1
end
end
但这不是:
spec/models/note_spec.rb
describe \"note creation\" do
it \"should notify the readers of the book the note is on\" do
lambda do
@note.save!
end.should change(@user.feed, :count).by(1)
end
end
我不知道有什么区别?
没有找到相关结果
已邀请:
2 个回复
淘圃跺枯替
羔磺