我正在開發用於shoulda和factory_girl的REST測試。下面用shoulda和factory_girl測試REST - destroy
context "on :delete to :destroy" do
setup do
@controller = NewsArticlesController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@news_article = Factory.create(:news_article)
end
should "destroy new NewsArticle" do
assert_difference('NewsArticle.count', -1) do
delete :destroy, :id => @news_article.id
end
end
should_redirect_to news_articles_path
end
結果代碼,我看到
1) Error:
test: on :delete to :destroy should redirect to index. (NewsArticlesControllerTest):
ArgumentError: block not supplied
c:/develop/ruby/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/action_controller/macros.rb:201:in `instance_eval'
c:/develop/ruby/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/action_controller/macros.rb:201:in `__bind_1248853182_16800
0'
c:/develop/ruby/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `call'
c:/develop/ruby/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `test: on :delete to :destroy should redirect to index. '
你能告訴我PLZ - 什麼是錯,以及如何我可以修改測試,以使他們的工作吧?
UPD:路線看起來很好
news_articles GET /news(.:format) {:controller=>"news_articles", :action=>"index"}
沒有,一個assert_difference正常工作的新手冊,但你可以在提供的日誌中看到 - 有問題should_redirect_to news_articles_path – 2009-07-29 09:38:53
你能告訴我你的控制器文件? – Lichtamberg 2009-07-29 10:56:16
我想,你刪除後不會被重定向到索引?或者你呢? – Lichtamberg 2009-07-29 10:56:48