Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Problem with Test Factories

Hi, I'm at the end of the Test Factories video and having a problem.

Here are the errors:

1) Failure: test: #index when logged in should display date information on an accepted friendship. (UserFriendshipsControllerTest) [test/functional/user_friendships_controller_test.rb:41]: Expected at least 1 element matching "#user_friendship_980190964", found 0.

2) Failure: test: #index when logged in should display pending information on a pending friendship. (UserFriendshipsControllerTest) [test/functional/user_friendships_controller_test.rb:36]: Expected at least 1 element matching "#user_friendship_980190963", found 0.

Here's the code from the user_friendships_controller_test.rb file:

context "when logged in" do setup do @friendship1 = create(:pending_user_friendship, user: users(:ben), friend: create(:user, first_name: 'Pending', last_name: 'Friend')) @friendship2 = create(:accepted_user_friendship, user: users(:ben), friend: create(:user, first_name: 'Active', last_name: 'Friend'))

  sign_in users(:ben)
  get :index
end

should "get the index page without error" do
  assert_response :success
end

should "assign user_friendships" do
  assert assigns(:user_friendships)
end

should "display friend's names" do
  assert_match /Pending/, response.body
  assert_match /Active/, response.body
end

should "display pending information on a pending friendship" do
  assert_select "#user_friendship_#{@friendship1.id}" do
    assert_select "em", "Friendship is pending."
  end
end
should "display date information on an accepted friendship" do
  assert_select "#user_friendship_#{@friendship2.id}" do
    assert_select "em", "Friendship started #{@friendship2.updated_at}."
  end
end

end end

And here's the index.html.erb code:

<div class = "page-header"> <h1>Friends</h1> </div>

<% @user_friendships.each do |friendship| %> <% friend = friendship.friend %> <div id="<% dom_id(friendship) %>" class="friend row"> <div class="span1"> <%= link_to image_tag(friend.gravatar_url), profile_path(friend) %> </div> <div class="span7"> <strong><%= friend.full_name %></strong> <% if friendship.pending? %> <em>Friendship is pending.</em><%= link_to "Delete request", edit_user_friendship_path(friendship) %>. <% end %> <% if friendship.requested? %> <em>Friendship requested.</em><%= link_to "Accept friendship", edit_user_friendship_path(friendship) %>. <% end %> <% if friendship.accepted? %> <em>Friendship started <%=friendship.updated_at %>.</em> <%= link_to "Update friendship", edit_user_friendship_path(friendship) %>. <% end %> </div> </div> <% end %>

1 Answer

Never mind, I found it. I forget the equals sign in the ERB tag in the index.html.erb at this point:

<%= dom_id(friendship) %>