Tests: StandardError: No fixture with name 'first'...?


#1

Hi all

I have created a scaffold for the model Country. Without touching
anything of the test files after they have been created I ran the tests:

rake test

And that’s the horrible output:

chraftbuech:~/Webwork/pgbookings josh$ rake test
/usr/bin/rake:17:Warning: require_gem is obsolete. Use gem instead.
(in /Users/Josh/Webwork/pgbookings)
/usr/bin/ruby -Ilib:test
“/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader.rb”
“test/unit/country_test.rb”
Loaded suite
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader
Started
.
Finished in 0.029698 seconds.

1 tests, 1 assertions, 0 failures, 0 errors
/usr/bin/ruby -Ilib:test
“/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader.rb”
“test/functional/countries_controller_test.rb”
Loaded suite
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader
Started
EEEEEEEE
Finished in 0.069691 seconds.

  1. Error:
    test_create(CountriesControllerTest):
    StandardError: No fixture with name ‘first’ found for table ‘countries’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:503:in
    countries' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:incountries’
    ./test/functional/countries_controller_test.rb:15:in
    setup_without_fixtures' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:576:insetup’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:574:in
    `setup’

  2. Error:
    test_destroy(CountriesControllerTest):
    StandardError: No fixture with name ‘first’ found for table ‘countries’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:503:in
    countries' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:incountries’
    ./test/functional/countries_controller_test.rb:15:in
    setup_without_fixtures' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:576:insetup’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:574:in
    `setup’

  3. Error:
    test_edit(CountriesControllerTest):
    StandardError: No fixture with name ‘first’ found for table ‘countries’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:503:in
    countries' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:incountries’
    ./test/functional/countries_controller_test.rb:15:in
    setup_without_fixtures' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:576:insetup’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:574:in
    `setup’

  4. Error:
    test_index(CountriesControllerTest):
    StandardError: No fixture with name ‘first’ found for table ‘countries’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:503:in
    countries' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:incountries’
    ./test/functional/countries_controller_test.rb:15:in
    setup_without_fixtures' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:576:insetup’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:574:in
    `setup’

  5. Error:
    test_list(CountriesControllerTest):
    StandardError: No fixture with name ‘first’ found for table ‘countries’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:503:in
    countries' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:incountries’
    ./test/functional/countries_controller_test.rb:15:in
    setup_without_fixtures' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:576:insetup’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:574:in
    `setup’

  6. Error:
    test_new(CountriesControllerTest):
    StandardError: No fixture with name ‘first’ found for table ‘countries’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:503:in
    countries' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:incountries’
    ./test/functional/countries_controller_test.rb:15:in
    setup_without_fixtures' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:576:insetup’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:574:in
    `setup’

  7. Error:
    test_show(CountriesControllerTest):
    StandardError: No fixture with name ‘first’ found for table ‘countries’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:503:in
    countries' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:incountries’
    ./test/functional/countries_controller_test.rb:15:in
    setup_without_fixtures' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:576:insetup’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:574:in
    `setup’

  8. Error:
    test_update(CountriesControllerTest):
    StandardError: No fixture with name ‘first’ found for table ‘countries’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:503:in
    countries' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:incountries’
    ./test/functional/countries_controller_test.rb:15:in
    setup_without_fixtures' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:576:insetup’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:574:in
    `setup’

8 tests, 0 assertions, 0 failures, 8 errors
/usr/bin/ruby -Ilib:test
“/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader.rb”
Command failed with status (1): [/usr/bin/ruby -Ilib:test
"/usr/lib/ruby/ge…]
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:730:in sh' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:729:incall’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:737:in sh' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:816:insh’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:811:in sh' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:751:inruby’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:816:in ruby' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:811:inruby’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/testtask.rb:117:in
define' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/testtask.rb:102:inverbose’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/testtask.rb:102:in
define' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/testtask.rb:100:incall’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:399:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:399:ineach’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:399:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:369:ininvoke’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:362:in synchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:362:ininvoke’
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/testing.rake:45
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/testing.rake:43:in
collect' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/testing.rake:43 /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/testing.rake:42:incall’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:399:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:399:ineach’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:399:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:369:ininvoke’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:362:in synchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:362:ininvoke’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:1935:in run' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:1935:ineach’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:1935:in run' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/bin/rake:7 /usr/bin/rake:18:inload’
/usr/bin/rake:18
rake aborted!
Test failures

(See full trace by running task with --trace)

So what went wrong here? What about these errors, is this a bug in
Rails?

Thanks so much for help,
Josh


#2

I am not sure what the issue is, but here are a couple ideas:

  1. Did you create your test database?
  2. Did the countries.yml file get accidentally deleted?
  3. Did you run rake migrate before testing?

Also, when encountering issues with tests, I find it helpful to tail
development.log. This way you can see exactly what statements are
being executed before the exception/failure.

-Shawn


#3

Err, my mistake, should have been “test.log” :slight_smile:

-Shawn


#4

All the points mentioned should not be the problem.

My test.log looks like this:

e[4;36;1mSQL (0.000278)e[0m e[0;1mSET SQL_AUTO_IS_NULL=0e[0m
e[4;35;1mSQL (0.000311)e[0m e[0mBEGINe[0m
e[4;36;1mCountry Columns (0.003781)e[0m e[0;1mSHOW FIELDS FROM
countriese[0m
e[4;35;1mSQL (0.004286)e[0m e[0mROLLBACKe[0m
e[4;36;1mSQL (0.000231)e[0m e[0;1mBEGINe[0m
e[4;35;1mSQL (0.000231)e[0m e[0mROLLBACKe[0m
e[4;36;1mSQL (0.000220)e[0m e[0;1mBEGINe[0m
e[4;35;1mSQL (0.000221)e[0m e[0mROLLBACKe[0m
e[4;36;1mSQL (0.000247)e[0m e[0;1mBEGINe[0m
e[4;35;1mSQL (0.000233)e[0m e[0mROLLBACKe[0m
e[4;36;1mSQL (0.000284)e[0m e[0;1mSET SQL_AUTO_IS_NULL=0e[0m
e[4;35;1mSQL (0.000203)e[0m e[0mBEGINe[0m
e[4;36;1mSQL (0.000227)e[0m e[0;1mROLLBACKe[0m
e[4;35;1mSQL (0.000161)e[0m e[0mBEGINe[0m
e[4;36;1mSQL (0.000218)e[0m e[0;1mROLLBACKe[0m
e[4;35;1mSQL (0.000262)e[0m e[0mBEGINe[0m
e[4;36;1mSQL (0.002820)e[0m e[0;1mROLLBACKe[0m
e[4;35;1mSQL (0.000221)e[0m e[0mBEGINe[0m
e[4;36;1mSQL (0.000233)e[0m e[0;1mROLLBACKe[0m
e[4;35;1mSQL (0.000266)e[0m e[0mBEGINe[0m
e[4;36;1mSQL (0.000232)e[0m e[0;1mROLLBACKe[0m
e[4;35;1mSQL (0.000195)e[0m e[0mBEGINe[0m
e[4;36;1mSQL (0.000204)e[0m e[0;1mROLLBACKe[0m
e[4;35;1mSQL (0.000182)e[0m e[0mBEGINe[0m
e[4;36;1mSQL (0.000245)e[0m e[0;1mROLLBACKe[0m
e[4;35;1mSQL (0.000230)e[0m e[0mBEGINe[0m
e[4;36;1mSQL (0.000222)e[0m e[0;1mROLLBACKe[0m

Not really helpful, is it…?


#5

This happened to me too. It looks like there’s a bug here.
What I noticed is that when my functional test controller is made, the
setup method expects a fixture entry called :first to be available.
def setup
@controller = WhereisController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

@first_id = whereis(:first).id

end

However, fixtures only as

Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
id: 1
two:
id: 2

This is new (to me anyway) in Rails 1.2. Traditionally, fixture
contained entries called :first, and :second.

You can get around your problem by changing your test controller to
use :one in the setup method.

-dave

On Mar 22, 12:48 pm, Joshua M. removed_email_address@domain.invalid