0
我有一個問題測試以下控制器代碼:黃瓜/ RSpec的測試
def publish
if @article.publish
flash[:notice] = "Article '#{@article.title}' was published."
else
# This is not tested
flash[:error] = "Error publishing article."
end
redirect_to :action => :index
end
凡功能發佈看起來像這樣:
def publish
self.toggle!(:is_published)
end
功能toggle!
是原子和理論只有在數據庫出現問題時纔會失敗(在實踐中,我可以找到許多應用程序檢測到錯誤的場景,因爲有人違反了發佈方法的實現)。我如何在黃瓜中測試錯誤時顯示正確的信息?