使用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
我不知道有什么区别?     
已邀请:
RSpec不支持此匹配器的do / end语法。请参阅此页面底部的警告... http://apidock.com/rspec/Spec/Matchers/change     
为了使用lambda并测试更改,您需要使用大括号{}-不支持do / end语法(尚未)。     

要回复问题请先登录注册