更新:已解决,通过恢复到运动前条件并将用户规范更改为“确认”而不是“密码确认”
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
做过这些练习的人可以帮助我吗?
不幸的是,用户请求规范现在被破坏了,因为注册和编辑表单使用了旧版本的部分错误消息。为了修复它们,我们将使用更通用的版本更新它们,如代码清单 10.36 和代码清单 10.37 所示。(注意:如果您在第 9.6 节的练习中实现了清单 9.50 和清单 9.51,您的代码会有所不同。比照。)
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
这是清单中我当前的(错误)代码,因为练习已经改变了它们:
编辑.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>
新的.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