Forum: Ruby on Rails Tests: StandardError: No fixture with name 'first'...?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2007-03-22 20:48
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:in
`countries'
    ./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:in
`setup'
    /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:in
`countries'
    ./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:in
`setup'
    /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:in
`countries'
    ./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:in
`setup'
    /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:in
`countries'
    ./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:in
`setup'
    /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:in
`countries'
    ./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:in
`setup'
    /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:in
`countries'
    ./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:in
`setup'
    /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:in
`countries'
    ./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:in
`setup'
    /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:in
`countries'
    ./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:in
`setup'
    /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:in `call'
/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:in `sh'
/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:in `ruby'
/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:in `ruby'
/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:in
`verbose'
/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:in
`call'
/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:in `each'
/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:in `invoke'
/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:in `invoke'
/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:in
`call'
/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:in `each'
/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:in `invoke'
/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:in `invoke'
/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:in `each'
/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:in `load'
/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
7db798c17fea871c27402138b4497912?d=identicon&s=25 Shawn Roske (Guest)
on 2007-03-22 22:02
(Received via mailing list)
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
7db798c17fea871c27402138b4497912?d=identicon&s=25 Shawn Roske (Guest)
on 2007-03-22 22:05
(Received via mailing list)
Err, my mistake, should have been "test.log" :)

-Shawn
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2007-03-22 22:09
All the points mentioned should not be the problem.

My test.log looks like this:

  SQL (0.000278)   SET SQL_AUTO_IS_NULL=0
  SQL (0.000311)   BEGIN
  Country Columns (0.003781)   SHOW FIELDS FROM
countries
  SQL (0.004286)   ROLLBACK
  SQL (0.000231)   BEGIN
  SQL (0.000231)   ROLLBACK
  SQL (0.000220)   BEGIN
  SQL (0.000221)   ROLLBACK
  SQL (0.000247)   BEGIN
  SQL (0.000233)   ROLLBACK
  SQL (0.000284)   SET SQL_AUTO_IS_NULL=0
  SQL (0.000203)   BEGIN
  SQL (0.000227)   ROLLBACK
  SQL (0.000161)   BEGIN
  SQL (0.000218)   ROLLBACK
  SQL (0.000262)   BEGIN
  SQL (0.002820)   ROLLBACK
  SQL (0.000221)   BEGIN
  SQL (0.000233)   ROLLBACK
  SQL (0.000266)   BEGIN
  SQL (0.000232)   ROLLBACK
  SQL (0.000195)   BEGIN
  SQL (0.000204)   ROLLBACK
  SQL (0.000182)   BEGIN
  SQL (0.000245)   ROLLBACK
  SQL (0.000230)   BEGIN
  SQL (0.000222)   ROLLBACK

Not really helpful, is it...?
5d07490f2d72cfd391289581976c8f1f?d=identicon&s=25 Dave Dumaresq (daved)
on 2007-05-18 01:23
(Received via mailing list)
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 Muheim <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.