SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot basicwebus's Avatar
    Join Date
    Jul 2003
    Location
    Missouri
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simply Rails 2 Stuck on page 192

    I am working through the pdf version of the book since I haven't received my book yet of Simply Rails 2. Everything has worked fine until I got to page 192 and ran the rake test code. All test work until it gets to the test_should_add_story section of the test. The error it gives says, "NameError: undefined local variable or method 'assert_redirected_to_stories_path' for (etc). I double checked all my other files and compared them against the code archive. They are all identical. Not sure how to fix this problem.

    Here is my code from my stories_controller_test.rb
    Code Ruby:
    require 'test_helper'
    class StoriesControllerTest < ActionController::TestCase
      def test_should_show_index
        get :index
        assert_response :success
        assert_template 'index'
        assert_not_nil assigns(:story)
      end
      def test_should_show_new
        get :new
        assert_response :success
        assert_template 'new'
        assert_not_nil assigns(:story)
      end
      def test_should_show_new_form
        get :new
        assert_select 'form p', :count => 3
      end
      def test_should_add_story
        post :create, :story => {
          :name => 'test story', :link => 'http://www.test.com/'
          }
        assert ! assigns(:story).new_record?
        assert_redirected_to_stories_path
        assert_not_nil flash[:notice]
      end
      def test_should_reject_missing_story_attribute
        post :create, :story => { :name => 'story without a link' }
        assert assigns(:story).errors.on(:link)
      end
    end
    After the third time of reading the instructions,
    it finally soaks in to my thick skull.



  2. #2
    SitePoint Zealot basicwebus's Avatar
    Join Date
    Jul 2003
    Location
    Missouri
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, not sure if I did this correctly, but I finally got my test to run without errors.
    I changed the code:
    assert_redirected_to_stories_path
    to:
    assert_redirected_to :action => 'index'

    Apparently the assert_redirected_to_stories_path is deprecated with the newer version of rails. Here are the versions of software I am using:

    Ruby version1.8.6 (i386-mswin32)RubyGems version1.3.5Rack version1.0Rails version2.3.5Active Record version2.3.5Active Resource version2.3.5Action Mailer version2.3.5Active Support version2.3.5Ruby version1.8.6 (i386-mswin32)RubyGems version1.3.5Rack version1.0Rails version2.3.5Active Record version2.3.5Active Resource version2.3.5Action Mailer version2.3.5Active Support version2.3.5Ruby 1.8.6 (i386-mswin32)
    Ruby Gems 1.3.5
    Rack 1.0
    Rails 2.3.5
    Active Record 2.3.5
    Active Resource 2.3.5
    Action Mailer 2.3.5
    Active Support 2.3.5

    Hopefully this will help someone else
    After the third time of reading the instructions,
    it finally soaks in to my thick skull.




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •