SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Chapter 7, Page 171 Build your own ROR web app

    I've got up to this point all fine and dandy, but I'm getting an error with the unit testing. I've copied and pasted all of the code from the examples and I'm still getting the same error. I'm on Mac OS X 10.5 btw.

    Code:
    Hermes:shovell graham$ rake test:units
    (in /Users/graham/shovell)
    rake aborted!
    You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.[]
    
    (See full trace by running task with --trace)
    Hermes:shovell graham$
    And my story_test.rb:
    Code:
    require File.dirname(__FILE__) + '/../test_helper'
    
    class StoryTest < Test::Unit::TestCase
      fixtures :stories
    
      def test_should_require_name
        s = Story.create(:name => nil)
        assert s.errors.on(:name)
      end
      
      def test_should_require_link
        s = Story.create(:link => nil)
        assert s.errors.on(:link)
      end
      
      def test_should_create_story
        s = Story.create(
          :name => 'My test submission',
          :link => 'http://www.testsubmission.com/')
        assert s.valid?
      end
    end
    Thanks a lot in advance!

  2. #2
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After much head scratching, I found where the problem was - my db/database.yml wasn't indented properly. Only my development db had the proper indentation.

    I didn't realise it would be so picky about these things - lesson learnt!

  3. #3
    l 0 l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by grahamgilbert View Post
    After much head scratching, I found where the problem was - my db/database.yml wasn't indented properly. Only my development db had the proper indentation.

    I didn't realise it would be so picky about these things - lesson learnt!
    Yeah, it's one of the fun parts about YAML. It's pretty cool, actually, but I remember getting burnt by aspects like that when I first started using it. It's really quite simple, though, so you should have your brain wrapped around it in no time.


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
  •