2
votes

I'm trying to make sense of the last exercise in Chapter 5 of Hartl's Rails Tutorial but don't really understand it nor what it strives to do. My rationale:

It speaks of "full_title helper", which refers to the code we placed in app/controllers/helpers/application_helper.rb:

  def full_title(page_title = '')
    base_title = "Ruby on Rails Tutorial Sample App"
    if page_title.empty?
      base_title
    else
      "#{page_title} | #{base_title}"
    end
  end

The exercise is: 1) Include the above application_helper.rb file in the test_helper by adding the line "include ApplicationHelper" to /test/test_helper.rb

2) We can then extend test/integration/site_layout_test.rb with:

get signup_path
assert_select "title", full_title("Sign up")

which uses the full_title method with "Sign up" as page_title.

However, this test would not test for for example typos in the base_title within the full_title method.

3) Assignment: Solve this limitation by creating a test helper "test/helpers/application_helper_test.rb" that tests this. Solution code for test/helpers/application_helper_test.rb:

  require 'test_helper'
  class ApplicationHelperTest < ActionView::TestCase
    test "full title helper" do
      assert_equal full_title,         "Ruby on Rails Tutorial Sample App"
      assert_equal full_title("Help"), "Help | Ruby on Rails Tutorial Sample App"
    end
  end

The result at least in my case is that the above full title helper test is only executed when running "bundle exec rake test" and not when running "bundle exec rake test:integration". But for running "bundle exec rake test" we already had a fine working test that checks each page title; we made that previously. What I though this exercise wanted to achieve that we also test for the page title when running "bundle exec rake test:integration".

What am I missing?

3

3 Answers

0
votes

I think you miss nothing
because from what I get in http://guides.rubyonrails.org/testing.html section 6
rake test:integration just Runs all the integration tests from test/integration

application_helper_test.rb is different test from the integration test
application_helper_test.rb is just for testing the full title helper method

0
votes

As far as I understand it: Integration tests "simulate the actions of a user interacting with our application using a web browser". This exercise is not an integration test, it tests something that has nothing to do with users interacting, so I suppose that is why it is not called in a rake test:integration. Furthermore, if you compare this file with the test/controllers/static_pages_controller_test.rb you will see that they inherit from different classes: the application helper test from ActionView and the static_pages-controller_test from ActionController. But... I am a Ruby Nuby, so let's see if someone can confirm this?

0
votes

If you saved the test file under test/helpers, then use:

    rails test:helpers

This will run all tests in that directory.