SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simply Rails2:chapter 6. Problems with test

    Hi everyone!

    I'm been searching in the old posts but i couldn't find any error like this one:

    When i try rake test:units i always got the same output. I've modified stories.yml, but couldn't fix the problem:

    Started
    EEEEEE
    Finished in...

    1) Error
    test_should_not_be_valid_without_link(StoryTest):
    Fixture::FormatError:Bad data for story fixture named #o nil
    .....



    Any ideas?
    Thanks!!

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First thing always to check with test errors and fixtures is that you haven't accidentally introduced tabs into the fixture yml file. In YAML spaces have different meanings to tabs. This is why YAML is evil (IMO). Make sure your editor isn't replacing double spaces with tabs (many YAML unaware editors will 'help' in this way and thereby cause unusual errors.

    CSV fixture files can be easier to manage.

    Have a look at this reference for more information on fixtures.
    http://ar.rubyonrails.org/classes/Fixtures.html

  3. #3
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi and thanks for your reply!

    I'm using the code from the Code Archive, I've checked the spaces and everything looks right, but got the same output :-(

    I'm gonna try with a CSV fixture file reading the link you comment.

    Thanks!

  4. #4
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried with csv fixture file but got the same error...

    I'll keep on trying!

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It might be worth posting your fixture and test code. Use Code tags (# symbol on message tool bar) around the code so that it is easy to read and doesn't get reformated.

  6. #6
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, here you are!


    Fixture: stories.yml

    #######################
    one:
    name: story1
    link: link1
    two:
    name: story2
    link: link2
    ######################





    Test: stroy_test.rb

    ######################
    require File.dirname(__FILE__) + '/../test_helper'

    class StoryTest < ActiveSupport::TestCase

    def test_should_not_be_valid_without_name

    s = Story.createname => nil, :link => 'wwwtestsubmissioncom')

    assert s.errors.onname)

    end


    def test_should_be_valid_without_link

    s = Story.createname => 'My test submission', :link => nil)

    assert s.errors.onlink)

    end


    def test_should_create_story

    s = Story.create(
    :name => 'My test submission',
    :link => 'wwwtestsubmissioncom/')

    assert s.valid?

    end
    ###############################


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
  •