I've got a problem testing the following controller code:
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
Where the function publish looks like that:
def publish
self.toggle!(:is_published)
end
Function toggle!
is atomic and in theory will fail only when there is a problem with database (in practice I can find number of scenarios where the error should be detected because someone breaks the publish method implementation). How can I test in Cucumber that the correct message is shown in case of error?