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 Viewing Todo Items: Part 1

Ron Chan
Ron Chan
10,987 Points

What was the point of adding the unlinked hyperlink to the index.html.erb file in the views folder?

I am referring to this line added and then removed before the end of the video.

a href="" List Items /a

I am thinking it was probably done to test for something, but I might have missed that out because I am not following the explanation well enough. Any ideas?

2 Answers

Brandon Keene
Brandon Keene
7,217 Points

So, he wants to make sure that he can click a link and get to the Todo Items page. He announces that around 3:09.

Around 4:29 he runs the first test to see the failure resulting from having no link to click.

He inserts the link you're referring to around 5:08 as a placeholder to change the test failure result. He does this to prove that there is a link that can be clicked, and the test then fails because the link doesn't actually go anywhere.

At this point he has hardcoded that hyperlink, but the rest of the video works through how to get rails to generate those links for us. @6:56 you'll watch him remove that test link, and what he replaces it with is the code to have rails generate equivalent links.

Hope this helps!

Ron Chan
Ron Chan
10,987 Points

Is it correct to say he inserted a broken hyperlink to attempt changing the failure message from rspec? Why didn't he try to find the link to the index.html.erb file directly using the rake routes command after around 4:29 when the failure message has identified that it was 'Unable to find link "List Items" '? I am a little confused because there just seems to be no actionable information gained from the new failure message after inserting the 'a href' line.

Brandon Keene
Brandon Keene
7,217 Points

"Is it correct to say he inserted a broken hyperlink to attempt changing the failure message from rspec?" To my understanding, the answer is "Yes," though I might suggest that the hyperlink is null rather than broken, and I'd make this distinction because, as I understand it, the goal is to test whether or not a link can be clicked, and the second rspec error results from the test not finding the destination link. That means to me that the link is a valid target for the test, even though its ineffectiveness means the test fails in a different way.

"Why didn't he try to find the link to the index.html.erb file directly using the rake routes command..." My grasp on this isn't particularly firm, but I think it's because hardcoding the path would result in the link being available in that one place, that one instance of the hyperlink, and the goal was to create more flexible code that could generate similar links in the future. I think we're supposed to be learning about the relationships between Views and Controllers, but as you're experiencing, that particular course doesn't do a great job of fleshing out the how/what/when/where/why of each piece of code that gets written.

And I think the actionable info from the second test is just "OK, clicking a link works, so now we can work on generating valid links." My impression is that the first two tests are as simple as "can the system find and click a link" and "can the system tell when it has or has not resolved properly on the subsequent page."

Ron Chan
Ron Chan
10,987 Points

Thanks Brandon, appreciate talking through this with you. I might have gone through the Rails part of this track too quickly and missed out 'whys' and 'hows' for all these tests. Gonna watch the videos again after completing the track.

Brandon Keene
Brandon Keene
7,217 Points

Frankly Ron, I'm tempted to rewatch them myself. It certainly doesn't seem like the worst idea.

Happy to help!

Brandon Keene
Brandon Keene
7,217 Points

PS, not to be completely self-serving, but if you genuinely found my answers helpful. I'd be grateful if you'd mark one as "Best Answer." The points will help further my advanement in the career program, and hopefully aid in getting me a job.

But if not, that's ok too!