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!
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
Ron Chan10,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?
Brandon Keene7,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!
Brandon Keene7,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."