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 Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Writing Test Helpers

Jacob Horn
Jacob Horn
9,255 Points

application.html.erb edits case 2 failures when running bin/rake

I have created the following div on the application.html.erb file:

<div class="nav">
    <h1><%= link_to "Odot", root_path %> </h1>
    <ul>
    <li><%= link_to "Todo Lists", todo_lists_path %></li>

    </ul>
    <br class="clear" />
    </div>

1) Adding todo items displays the title of the todo list Failure/Error: within ("h1") do Capybara::Ambiguous: Ambiguous match, found 2 elements matching css "h1" # ./spec/features/todo_items/create_spec.rb:10:in `block (2 levels) in <top (required)>'

2) Viewing todo items displays the title of the todo list Failure/Error: within ("h1") do Capybara::Ambiguous: Ambiguous match, found 2 elements matching css "h1" # ./spec/features/todo_items/index_spec.rb:11:in `block (2 levels) in <top (required)>'

The application is running fine but I don't want to move forward with these errors

2 Answers

It's because we added an h1 in the nav bar. What I did was wrap my yield tag in a div with the class "container" and then change the first spec in index_spec.rb to from within("h1") to within(".container h1")

Here is the whole spec:

it "displays the title of the todo list" do
    visit_todo_list(todo_list)
    within(".container h1") do
      expect(page).to have_content(todo_list.title)
    end
  end
Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

The test seems to be confused whether to check the h1 in your application layout view or one in the 'app/views/todo_items/index.html.erb' and 'app/views/todo_items/new.html.erb' respectively.

Can you maybe post the it block with the line that causes the error from either the index or create spec? Also can you post the div where you yield in the application layout?