Kevin T.
Kevin T.

Reputation: 758

Generating a test file from The Ruby on Rails Tutorial

Chapter 5 exercise "full_title" test. I tried the pattern from the previous file generation example...

$ rails generate integration_test site_layout

and when I try

$ rails generate helpers_test application_helper,

The path I'm supposed to get is test/helpers/application_helper_test.rb, but the error I get is "Could not find generator 'helpers' "

Below is the class that is supposed to be generated

require 'test_helper
class ApplicationHelperTest < ActionView::TestCase
  test 'full title helper' do
  ....
  ....
end
end

The question is what must I do to generate the correct file in the right location and to get the correct class .

I went to the rails docs, and I reviewed this other question Hartl Rail Tutorial: Chapter 5, exercise 3

Upvotes: 1

Views: 1409

Answers (2)

Sagar Pandya
Sagar Pandya

Reputation: 9508

Exercise snippet:

...by writing a direct test of the full_title helper, which involves creating a file to test the application helper and then filling in the code indicated with FILL_IN in...

Create the file using by the command touch followed by the directory and filename into the bash/command line (remember to cd into your rails app):

$ touch test/helpers/application_helper_test.rb

Then open it up manually and add the following:

class ApplicationHelperTest < ActionView::TestCase
  test "full title helper" do
    assert_equal full_title,         FILL_IN
    assert_equal full_title("Help"), FILL_IN
  end
end

Obviously where it says FILL_IN you have to write some code:)

Upvotes: 0

David
David

Reputation: 3610

I am not sure where you found reference to a helpers_test generator but it isn't core Rails.

It may depend on what version of Rails you have but you should be able to do:

rails g helper application

This will generate the following 2 files (assuming you are using Test::Unit)

app/helpers/application_helper.rb
test/helpers/application_helper_test.rb

This certainly works for Rails 4.x, but for my Rails 5.x setup this generator only created app/helpers/application_helper.rb leading me to suspect the tutorial was originally created for Rails 4 and has not been updated correctly for Rails 5.

You can find out what generators you have by simply invoking:

rails g --help

For further information on a particular generator simply expand upon that by:

rails g helper --help

Incidentally, there is nothing to stop you simply creating the file yourself in the correct location.

Upvotes: 1

Related Questions