我正在做Michael Hartl Rails 3教程,第8.4章316-320頁。我運行users_spec.rb測試和兩個測試不與下面的錯誤傳遞:找不到字段:「名稱」
Failures:
1) Users signup failure should not make a new user
Failure/Error: fill_in "Name", :with => ""
Webrat::NotFoundError:
Could not find field: "Name"
# ./spec/requests/users_spec.rb:12:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:10:in `block (4 levels) in <top (required)>'
2) Users signup success should make a new user
Failure/Error: fill_in "Name", :with => "Example User"
Webrat::NotFoundError:
Could not find field: "Name"
# ./spec/requests/users_spec.rb:28:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'
Finished in 3.97 seconds
2 examples, 2 failures**
MY USERS_SPEC.RB文件 -
require 'spec_helper'
describe "Users" do
describe "signup" do
describe "failure" do
it "should not make a new user" do
lambda do
visit signup_path
fill_in "Name", :with => ""
fill_in "Email", :with => ""
fill_in "Password", :with => ""
fill_in "Confirmation", :with => ""
click_button
response.should render_template('users/new')
response.should have_selector("div#error_explanation")
end.should_not change(User, :count)
end
end
describe "success" do
it "should make a new user" do
lambda do
visit signup_path
fill_in "Name", :with => "Example User"
fill_in "Email", :with => "[email protected]"
fill_in "Password", :with => "foobar"
fill_in "Confirmation", :with => "foobar"
click_button
response.should have_selector("div.flash.success",:content => "Welcome")
response.should render_template('users/show')
end.should change(User, :count).by(1)
end
end
end
end
誰能幫助我?
謝謝!