我正在使用 shoulda 和 factory_girl 开发 REST 测试。下面的代码
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. '
你能告诉我 - 有什么问题吗?我如何修改测试以使它们正常工作?
UPD:路线看起来不错
news_articles GET /news(.:format) {:controller=>"news_articles", :action=>"index"}