Kim Kim - 1 year ago 107
Ruby Question

RoR Tutorial - A direct test the full_title helper

I am working on the RoR Tutorial chapter 5 exercises and I can't seem to figure out what text to use in place of the "FILL_IN" I've tried reading the error messages by trying to match the actual with the expected. What am I doing wrong? Also, can someone explain how the

work in this test since I don't see the words "expected" or "actual" anywhere.

Instructions from the RoR Tutorial

Image of code from RoR Tutorial

My code with error message

Error message resulting from changes suggested

require 'test_helper'

class ApplicationHelperTest < ActionView::TestCase
test "full title helper" do
assert_equal full_title, "Kim's Cool Rails Site"
assert_equal full_title("Help"), "Kim's Cool Rails Site | Help"

Answer Source

can someone explain how the <expected> and <actual> work

Often a term between angle brackets, like <expected> and <actual> indicates a value that needs to be replaced. In this case, it mentions:

assert_equal <expected>, <actual>

which gives a description of the parameters taken by the assert_equal method. We're meant to replace them with our real-life values. For example,

result = 1 + 1
assert_equal 2, result

Here we've replaced <expected> with 2, and <actual> with result, to test that 1 + 1 = 2, as we expect it to.

I can't seem to figure out what text to use in place of the "FILL_IN"

So the relevant lines in your code are:

assert_equal full_title, FILL_IN
assert_equal full_title('help'), FILL_IN

In both lines, you should replace FILL_IN with whatever the result of the previous parameter is - in this case, full_title, and full_title('help')

So, if full_title gives "Kim's Cool Rails Site", then the first line should be:

assert_equal full_title, "Kim's Cool Rails Site"

And if full_title('Help') gives "Kim's Cool Rails Site | Help", then the second line should be:

assert_equal full_title('Help'), "Kim's Cool Rails Site | Help"


So the error you're getting basically says: We expected to see "Ruby on Rails Tutorial Sample App" and instead we say "Kim's Cool Rails Site".

In the example I gave, I just used "Kim's Cool Rails Site" as an example because I didn't know the actual title of your site. You needed to replace "Kim's Cool Rails Site" with whatever the actual title of your site is (ie, whatever full_path returns). So, judging from the error message, the exact code you need for the first line will be:

assert_equal full_title, "Ruby on Rails Tutorial Sample App"

You'll need to figure out the exact text you need for the second line yourself, but you'll basically just have to replace "Kim's Cool Rails Site | Help" with whatever you expect full_title('Help') to return.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download