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 Write Our First Tests

Edward Poon
Edward Poon
9,313 Points

Can someone explain this magic of this Rspec test?

It just seems like complete magic that click_link takes in a string "New Todo list" and somehow knows that it is referring to the button that has "New Todo list" in it. What if there are two buttons with this exact same string on the same page? How would click_link differentiate the two?

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I assume it is looking for the < a > (anchor) elements in the DOM and then checks the string between the opening and closing tags, comparing it with your argument in the click_link method. If it finds this very string, it clicks the link. If not, it reports an error. If it finds more than one, I assume it will give you an error saying that it's "ambiguous" because there's more than one anchor element with this string.