所以我正在开发一个简单的Ruby on Rails应用程序。它实际上基于您可以在http://guides.rubyonrails.org/getting_started.html找到的官方教程。我正在将测试扩展到本教程的范围之外。使用的测试框架是SimpleCov。
3) Error:
CommentsControllerTest#test_Rcomment_-_Create_(S):
ActionController::UrlGenerationError: No route matches {:action=>"/articles/201799169/:create", :comment=>{:alias=>"Somebody", :text=>"Some plain text"}, :controller=>"comments"}
test/controllers/comments_controller_test.rb:13:in `block (2 levels) in <class:CommentsControllerTest>'
test/controllers/comments_controller_test.rb:12:in `block in <class:CommentsControllerTest>'
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
root GET / welcome#index
article_comments GET /articles/:article_id/comments(.:format) comments#index
POST /articles/:article_id/comments(.:format) comments#create
new_article_comment GET /articles/:article_id/comments/new(.:format) comments#new
edit_article_comment GET /articles/:article_id/comments/:id/edit(.:format) comments#edit
article_comment GET /articles/:article_id/comments/:id(.:format) comments#show
PATCH /articles/:article_id/comments/:id(.:format) comments#update
PUT /articles/:article_id/comments/:id(.:format) comments#update
DELETE /articles/:article_id/comments/:id(.:format) comments#destroy
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
test "Rcomment - Create (S)" do
article = articles(:valid)
article.save
assert_difference('Comment.count') do
post '/articles/' + article.id.to_s + '/:create', comment: { alias: 'Somebody', text: 'Some plain text' }
end
assert_response :redirect
assert_redirected_to article_path(assigns(:article))
end
答案 0 :(得分:0)
您尝试发布的方法不存在。您需要发布到:create
:
post :create, article_id: article.id,
comment: { alias: 'Somebody', text: 'Some plain text' }