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

Cannot make my test pass in Building a Todo List with Rails 4: Viewing Todo Items, part 2

Hey - my test fails and I get the following message:

Failure/Error: within("h1") do Capybara::Ambiguous Ambiguous match, found 2 elements matching css "h1"

I'm pretty sure it has something to do with how I'm routing the index_spec, but my code is the same as the treehouse content. Any ideas?

2 Answers

Someone else had the same problem recently, I simply recommended using the whole page as context, not the h1 selector.

You can also give a specific class to this h1 in the view and in the test, Capybara should no longer be confused if you do it (remember, it's generally a huge guinea pig, it's not super smart...).

Thanks - I'm sorry for the repeated question; I didn't see it when i searched the forum. A quick fix I did was adding an ID to the h1 selector, then referencing that in the test.

Thanks again.

No problem. I only mentioned that to tell you how I know the answer ;). It's sometimes hard to search for specific problems on forum.