0
UPDATE:解決了,通過恢復到運動前的條件和不斷變化的用戶規範的「確認密碼」Ruby on Rails的教程第10章清單10.36測試失敗,因爲它是不同的,由於行使9.6.5
爲「確認」,而不是describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
做過這些練習的人能幫助我嗎?
不幸的是,用戶請求規範現在已被破壞,因爲註冊和編輯表單使用舊版本的部分錯誤消息。爲了解決這些問題,我們用更通用的版本來更新它們,如代碼清單10.36和代碼清單10.37所示。 (注:如果您執行清單9.50和清單從練習9.51第9.6節你的代碼會有所不同比照。)
Failures:
1) User pages signup with valid information should create a user
Failure/Error: fill_in "Name", with: "Example User"
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:104:in `block (4 levels) in <top (required)>'
2) User pages signup with valid information after saving the user
Failure/Error: fill_in "Name", with: "Example User"
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:104:in `block (4 levels) in <top (required)>'
3) User pages signup with valid information after saving the user
Failure/Error: fill_in "Name", with: "Example User"
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:104:in `block (4 levels) in <top (required)>'
4) User pages signup with valid information after saving the user
Failure/Error: fill_in "Name", with: "Example User"
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:104:in `block (4 levels) in <top (required)>'
5) User pages edit with valid information
Failure/Error: fill_in "Name", with: new_name
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:150:in `block (4 levels) in <top (required)>'
6) User pages edit with valid information
Failure/Error: fill_in "Name", with: new_name
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:150:in `block (4 levels) in <top (required)>'
7) User pages edit with valid information
Failure/Error: fill_in "Name", with: new_name
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:150:in `block (4 levels) in <top (required)>'
8) User pages edit with valid information
Failure/Error: fill_in "Name", with: new_name
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:150:in `block (4 levels) in <top (required)>'
9) User pages edit with valid information
Failure/Error: fill_in "Name", with: new_name
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:150:in `block (4 levels) in <top (required)>'
Finished in 5.78 seconds
112 examples, 9 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:119 # User pages signup with valid information should create a user
rspec ./spec/requests/user_pages_spec.rb:116 # User pages signup with valid information after saving the user
rspec ./spec/requests/user_pages_spec.rb:115 # User pages signup with valid information after saving the user
rspec ./spec/requests/user_pages_spec.rb:114 # User pages signup with valid information after saving the user
rspec ./spec/requests/user_pages_spec.rb:158 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:159 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:157 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:160 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:161 # User pages edit with valid information
這是從上市就是我目前(錯誤的)代碼,因爲演習已經改變了他們:
edit.html.erb
<% provide(:title, 'Edit user') %>
<h1>Update your profile</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
<% end %>
<%= gravatar_for @user %>
<a target="_blank" href="http://gravatar.com/emails">change</a>
</div>
</div>
new.html.erb
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
清單9.50。新的和編輯表單字段的一部分。
應用程序/視圖/用戶/ _fields.html.erb
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirm Password" %>
<%= f.password_field :password_confirmation %>
清單9.51。新的部分用戶視圖。
/users/new.html.erb
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'fields', f: f %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
app/views
爲 「確認」,而不是很高興看到你解決了它!給它一個接受,它會從未答覆的列表中出來:) – Evolve 2013-04-23 07:15:49