ruby-on-rails – Michael Hartl Rails教程第7章错误在UsersController中找不到操作

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Michael Hartl Rails教程第7章错误在UsersController中找不到操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我现在正在关注迈克尔哈特尔的Rails教程,我已经设法达到7.22而没有任何重大障碍.但是我对测试的结果感到困惑,他说:
Failures:

  1) UserPages signup with invalid information should not create a user
     Failure/Error: expect{click_button submit }.not_to change(User,:count)
     AbstractController::ActionNotFound:
       The action 'create' could not be found for UsersController
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:29:in `block (5 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:29:in `block (4 levels) in <top (required)>'

  2) UserPages signup with valid information should create a user
     Failure/Error: expect{click_button submit}.to change(User,:count).by(1)
     AbstractController::ActionNotFound:
       The action 'create' could not be found for UsersController
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:42:in `block (5 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:42:in `block (4 levels) in <top (required)>'

Finished in 0.7718 seconds
6 examples,2 failures

我按照教程的指示将以下内容添加到我的用户控制器页面

class UsersController < ApplicationController
  def show
    @user = User.find(params[:id])
  end

  def new
    @user = User.new
  end

end

但它似乎仍然没有奏效.我已经尝试添加一个创建方法,但这只会丢失一个丢失的模板错误

如果它有帮助,这里是rake routes命令的输出

~/dev/rails/sample_app$rake routes
    users GET    /users(.:format)          users#index
          POST   /users(.:format)          users#create
 new_user GET    /users/new(.:format)      users#new
edit_user GET    /users/:id/edit(.:format) users#edit
     user GET    /users/:id(.:format)      users#show
          PUT    /users/:id(.:format)      users#update
          DELETE /users/:id(.:format)      users#destroy
     root        /                         static_pages#home
   signup        /signup(.:format)         users#new
     help        /help(.:format)           static_pages#help
    about        /about(.:format)          static_pages#about
  contact        /contact(.:format)        static_pages#contact

回复评论时,失败的测试是:

describe "signup" do

      before{ visit signup_path }
      let(:submit) {"Create my account"}

      describe "with invalid information" do
        it "should not create a user" do
          expect{click_button submit }.not_to change(User,:count)
        end
      end

      describe "with valid information" do
        before do
          fill_in "Name",with: "Example User"
          fill_in "Email",with: "user@example.com"
          fill_in "Password",with: "foobar"
          fill_in "Confirmation",with: "foobar"
        end

        it "should create a user" do
          expect{click_button submit}.to change(User,:count).by(1)
        end
      end
    end

提前感谢任何建议!

解决方法

测试不应该在那时通过.继续关注本教程,您将看到它是如何工作的.
原文链接:https://www.f2er.com/ruby/267506.html

猜你在找的Ruby相关文章