Unit tests and fixtures

Hello

I’m experiencing some problems using rails fixtures with unit tests.

With my version of Ruby I have to define test with the following syntax:

test ‘some test’ do
assert…
end

instead of

def test_some_test
assert…
end

If I try to include/load the fixtures by using:
fixtures :stories, :votes

after the class definition, I get the following errors:

StandardError: No fixture with name…

What am I doing wrong?
Is this the latest Ruby test code or am I using some outdated version?
Is there any place that I could check that (I tried with some googling
without relevant results)?

Thanks in advance!

Aljaz F. wrote:

With my version of Ruby I have to define test with the following syntax:

test ‘some test’ do
assert…
end

What do you mean by this? I don’t think the Ruby version should have
anything to do with this. What testing framework are you using
(Test::Unit, Soulda, etc)?

This might affect how you use fixtures, I’m not sure. I use rSpec
myself. I also tend to avoid fixtures altogether in favor of factories
(factory_girl, machinist, etc.).

Robert W. wrote:

Aljaz F. wrote:

With my version of Ruby I have to define test with the following syntax:

test ‘some test’ do
assert…
end

What do you mean by this? I don’t think the Ruby version should have
anything to do with this. What testing framework are you using
(Test::Unit, Soulda, etc)?

This might affect how you use fixtures, I’m not sure. I use rSpec
myself. I also tend to avoid fixtures altogether in favor of factories
(factory_girl, machinist, etc.).

I’m using the default one and I’m not yet familiar with all the
concepts.

On Aug 13, 4:14 pm, Aljaz F. [email protected]
wrote:

instead of

def test_some_test
assert…
end

Either syntax works.

If I try to include/load the fixtures by using:
fixtures :stories, :votes

you don’t need that any more - The default test_helper.rb is set to
load all fixtures.

Fred

Frederick C. wrote:

On Aug 13, 4:14�pm, Aljaz F. [email protected]
wrote:

instead of

def test_some_test
� assert…
end

Either syntax works.

If I try to include/load the fixtures by using:
� fixtures :stories, :votes

you don’t need that any more - The default test_helper.rb is set to
load all fixtures.

Fred

If I remove the line for including specific fixtures, I still get the
errors (although the fixtures exist):

  1. Error:
    test_should_return_3_latest_votes(StoryTest):
    StandardError: No fixture with name ‘first’ found for table ‘stories’

Any idea what could be wrong?

2009/8/14 Aljaz F. [email protected]:

Either syntax works.
errors (although the fixtures exist):

 1) Error:
test_should_return_3_latest_votes(StoryTest):
StandardError: No fixture with name ‘first’ found for table ‘stories’

Have you got a record ‘first:’ in stories.yml? If so check the syntax
carefully.

Colin

You should write
fixtures :stories, :votes, :first

2009/8/14 Colin L. [email protected]