0
votes

UPDATE: SOLVED, by reverting to pre-exercise conditions and changing user spec to "Confirmation" instead of "Password Confirmation"

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

Can anyone who has done those exercises help me out?

Unfortunately, the User request spec is now broken because the signup and edit forms use the old version of the error messages partial. To fix them, we’ll update them with the more general version, as shown in Listing 10.36 and Listing 10.37. (Note: Your code will differ if you implemented Listing 9.50 and Listing 9.51 from the exercises in Section 9.6. Mutatis mutandis.)

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

This is my current (wrong) code from the listings because the exercises have changed them:

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>

Listing 9.50. A partial for the new and edit form fields.

app/views/users/_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 %>

Listing 9.51. The new user view with partial.

/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
1
Great to see you solved it! Give it an accept and it will come out of the unanswered list :) - Evolve

1 Answers

0
votes

UPDATE: SOLVED, by reverting to pre-exercise conditions and changing user spec to "Confirmation" instead of "Password Confirmation"

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