Tan*_*ilo 6 ruby rspec ruby-on-rails railstutorial.org
我现在正在关注迈克尔哈特尔的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
Run Code Online (Sandbox Code Playgroud)
我按照教程的指示将以下内容添加到我的用户控制器页面:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
end
Run Code Online (Sandbox Code Playgroud)
但它似乎仍然没有奏效.我已经尝试添加一个创建方法,但这只会丢失一个丢失的模板错误...
如果它有帮助,这里是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
Run Code Online (Sandbox Code Playgroud)
在回复评论时,失败的测试是:
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
Run Code Online (Sandbox Code Playgroud)
提前感谢任何建议!
| 归档时间: |
|
| 查看次数: |
4028 次 |
| 最近记录: |