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

Could someone check and see why my test is failing (ruby, capybara)?

Hey folks,

I'm getting this error message when I try to run my tests:

Failures:

  1) 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:10:in `block (2 levels) in <top (required)>'

Finished in 0.29792 seconds
3 examples, 1 failure

Failed examples:

rspec ./spec/features/todo_items/index_spec.rb:8 # Viewing todo items displays the title of the todo list

Now, in Jason's code he has it looking within("div.content" h1) instead. This didn't work either (though it threw a different error). I even tried playing around with the code in the index but for some reason I simply keep getting one error or another.

I pushed my code up to my github, here. The related video, iroinically, is Fixing Our Tests.

Any ideas? Thanks in advance! :grinning:

It would help if you could tell people which file you are trying to pass rspec and which rspec file you are testing it against.

haunguyen : it's all listed there in the code--included it from the start. :smile:

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I think you have two h1 tags - one from the layout file and one from the yielded page. I had the same problem, so I simply removed the whole "within" thing and its ending and left the expectation by itself. It worked fine.

Thanks! That makes sense...I'm still not sure what the other h1 is that it's having an issue with but ah well! :-)

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Go to localhost 3000 and inspect the page that we are talking about, find all h1 elements. I think one of them comes from the app/views/layouts/application.html.erb where ODOT is written as h1, but I'm not entirely sure.

YES! Your comment about localhost:3000 was what I needed. I ended up changing the application.html.erb file in order to get shizz to work, and the test passed!

For anyone else who is having this issue, here's what the deal was. Thanks Maciej! :thumbsup:

the mysterious h1 elements