My program does not work after adding helpler

60 views
Skip to first unread message

James Harold

unread,
Nov 1, 2015, 9:15:53 PM11/1/15
to Ruby on Rails: Talk
I have just gotten to Chapter Four of Michael Hartl's Ruby on Rails Tutorial, and I can't seem to get the program to work after adding a helper to the program. Here is the code from the files. 

static_pages_controller_test.rb
require 'test_helper'

class StaticPagesControllerTest < ActionController::TestCase
  test "should get home" do
    get :home
    assert_response :success
    assert_select "title", "Ruby on Rails Tutorial Sample App"
  end

  test "should get help" do
    get :help
    assert_response :success
    assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
  end

  test "should get about" do
    get :about
    assert_response :success
    assert_select "title", "About | Ruby on Rails Tutorial Sample App"
  end

  test "should get contact" do
    get :contact
    assert_response :success
    assert_select "title", "Contact | Ruby on Rails Tutorial Sample App"
  end
end


application.html.erb

<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag    'application', media: 'all',
                                              'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>
  </head>
  <body>
    <%= yield %>
  </body>
</html>


routes.rb
Rails.application.routes.draw do
  root 'static_pages#home'

  get 'static_pages/help'

  get 'static_pages/about'

  get 'static_pages/contact'

How do I get past this problem? Is there a way to fix this? 

Colin Law

unread,
Nov 2, 2015, 3:17:31 AM11/2/15
to Ruby on Rails: Talk
On 2 November 2015 at 02:15, James Harold <jharo...@gmail.com> wrote:
> I have just gotten to Chapter Four of Michael Hartl's Ruby on Rails
> Tutorial, and I can't seem to get the program to work after adding a helper

You have not shown us the error. Copy/paste the output showing the
error from the server window, including the stack trace and from the
start of the failing request. First though look carefully at that and
try and work out what the error means. I know it is often difficult
for newcomers but have a go.

Colin

James Harold

unread,
Nov 2, 2015, 11:01:44 AM11/2/15
to Ruby on Rails: Talk
BTW, the error is listed here: 

1) Failure:
StaticPagesControllerTest#test_should_get_about [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:19]:
<About | Ruby on Rails Tutorial Sample App> expected but was
<About | Ruby on Rails Tutorial Sample App.>.
Expected 0 to be >= 1.


  2) Failure:
StaticPagesControllerTest#test_should_get_contact [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:25]:
<Contact | Ruby on Rails Tutorial Sample App> expected but was
<Contact | Ruby on Rails Tutorial Sample App.>.
Expected 0 to be >= 1.


  3) Failure:
StaticPagesControllerTest#test_should_get_help [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:13]:
<Help | Ruby on Rails Tutorial Sample App> expected but was
<Help | Ruby on Rails Tutorial Sample App.>.
Expected 0 to be >= 1.


  4) Failure:
StaticPagesControllerTest#test_should_get_home [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:7]:
<Ruby on Rails Tutorial Sample App> expected but was
<Home | Ruby on Rails Tutorial Sample App.>.
Expected 0 to be >= 1.

 

Colin Law

unread,
Nov 2, 2015, 11:18:01 AM11/2/15
to Ruby on Rails: Talk
On 2 November 2015 at 16:01, James Harold <jharo...@gmail.com> wrote:
>
> BTW, the error is listed here:
>
> 1) Failure:
> StaticPagesControllerTest#test_should_get_about
> [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:19]:
> <About | Ruby on Rails Tutorial Sample App> expected but was
> <About | Ruby on Rails Tutorial Sample App.>.

The test producing that is
test "should get about" do
get :about
assert_response :success
assert_select "title", "About | Ruby on Rails Tutorial Sample App"
end

What do you think that error is trying to tell you?

Colin

James Harold

unread,
Nov 2, 2015, 11:33:32 AM11/2/15
to Ruby on Rails: Talk
It tells the program to perform the GET function for the HTML page, keep running the page when success is returned upon matching, and then select the page desired by the programmer and display it on the screen. I have also worked on the program, and have narrowed it down to two failure errors. They are listed here: 

1) Failure:
StaticPagesControllerTest#test_should_get_about [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:19]:
<About | Ruby on Rails Tutorial Sample App> expected but was
<Ruby on Rails Tutorial Sample App.>.
Expected 0 to be >= 1.


  2) Failure:
StaticPagesControllerTest#test_should_get_help [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:13]:
<Help | Ruby on Rails Tutorial Sample App> expected but was
<Ruby on Rails Tutorial Sample App.>.
Expected 0 to be >= 1.

 What should I do next? How do I fix this?

James Harold

unread,
Nov 2, 2015, 11:37:08 AM11/2/15
to Ruby on Rails: Talk
Also, here is the new test file: 
 
class StaticPagesControllerTest < ActionController::TestCase
  test "should get home" do
    get :home
    assert_response :success
    assert_select "title", "Ruby on Rails Tutorial Sample App."
  end

  test "should get help" do
    get :help
    assert_response :success
    assert_select "title", "Help | Ruby on Rails Tutorial Sample App."
  end

  test "should get about" do
    get :about
    assert_response :success
    assert_select "title", "About | Ruby on Rails Tutorial Sample App."
  end

  test "should get contact" do
    get :contact
    assert_response :success
    assert_select "title", "Contact | Ruby on Rails Tutorial Sample App."
  end
end



Colin Law

unread,
Nov 2, 2015, 12:02:32 PM11/2/15
to Ruby on Rails: Talk
As I have asked previously, what do you think is meant by
<About | Ruby on Rails Tutorial Sample App> expected but was
<Ruby on Rails Tutorial Sample App.>.

Colin
Reply all
Reply to author
Forward
0 new messages