Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Error with erb specs

When I run "rake" in console, I get 2 errors. They both read the same but they're on different files. One is on my edit.html.erb_spec.rb file and the other error is on new.html.erb_spec.rb file. The errors say:

Failure/Error: assert_select "input#user_password_digest[name=?]", "user[password_digest]" Mini::Test Assertion: Expected at least 1 element matching "input#user_password_digest[name='user[password_digest]']", found 0.. Expected 0 to be >= 1.

Does anyone know what this error is? It sounds to me like the password digest isn't being passed in when a user is being created, but I'm not even sure where to fix it if that is the case. I can't tell if it's a spec issue or an issue with a view.

3 Answers

Just found the problem. Jason must have done some editing off screen. Change "edit.html.erb_spec.rb" to:

require 'spec_helper'

describe "users/edit" do before(:each) do @user = assign(:user, stub_model(User, :first_name => "MyString", :last_name => "MyString", :email => "MyString", :password_digest => "MyString" )) end

  it "renders the edit user form" do
  render

   # Run the generator again with the --webrat flag if you want to use webrat matchers
   assert_select "form[action=?][method=?]", user_path(@user), "post" do
   assert_select "input#user_first_name[name=?]", "user[first_name]"
   assert_select "input#user_last_name[name=?]", "user[last_name]"
   assert_select "input#user_email[name=?]", "user[email]"
   assert_select "input#user_password[name=?]", "user[password]"
   assert_select "input#user_password_confirmation[name=?]", "user[password_confirmation]"
  end
  end
  end

And change "new.html.erb_spec.rb" to:

require 'spec_helper'

 describe "users/new" do
  before(:each) do
   assign(:user, stub_model(User,
    :first_name => "MyString",
    :last_name => "MyString",
    :email => "MyString",
    :password => "MyString",
    :password_confirmation => "MyString"
     ).as_new_record)
    end

   it "renders new user form" do
    render

   # Run the generator again with the --webrat flag if you want to use webrat matchers
   assert_select "form[action=?][method=?]", users_path, "post" do
   assert_select "input#user_first_name[name=?]", "user[first_name]"
   assert_select "input#user_last_name[name=?]", "user[last_name]"
   assert_select "input#user_email[name=?]", "user[email]"
   assert_select "input#user_password[name=?]", "user[password]"
   assert_select "input#user_password_confirmation[name=?]", "user[password_confirmation]"
   end
  end
 end

That was it, that worked. Thanks a million. I haven't had anytime to work on this since I'm finishing my last semester in school and you just saved me a ton of time trying to figure out what is wrong lol.

Have you checked for typos? It sounds as if rspec/capybara can't find the input element (based on "Expected at least 1 element matching"). Perhaps there is a typo in an ID or something.

I've tried going through some of the views and specs looking for typos. I didn't see anything, but it could be that I'm just completely missing it or just not looking in the right file. I even downloaded the files from the video and compared my edit.html.erb_spec.rb file and new.html.erb_spec.rb file to their versions and they were the same.

Thanks so much for posting this!

shakes fist at off screen changes