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!
是原子和理论只有在数据库出现问题时才会失败(在实践中,我可以找到许多应用程序检测到错误的场景,因为有人违反了发布方法的实现)。我如何在黄瓜中测试错误时显示正确的信息?