Take the 2-minute tour ×

Here's my problem. If I run the test using the ruby command the tests all pass. However, if I use the rake test:functionals they all fail with the error below. I'm not sure what I have to do differently to get them to pass when using the rake task, but I'd greatly appreciate any guidance you might offer.


class TasksControllerTest < ActionController::TestCase
    set_fixture_class :Action => 'Task'
    fixtures :Action

    setup :initialize_test

    test "the truth" do
        assert true

    def initialize_test
        @user = users :one
        sign_in @user

        @task = Action :one    # Here's the line that is throwing the error.

1) Error:
        FixtureClassNotFound: No class attached to find.
        test/functional/tasks_controller_test.rb:20:in `initialize_test'
share|improve this question
If I understand correctly, you have a Task model whose table name is Action. This means you should have app/models/task.rb and test/fixtures/Action.yml (or csv). Did I get that right? –  Benoit Garret Sep 22 '11 at 14:39
add comment

3 Answers

This is a very strange way of handling the problem.

With rails, out of the box, if you have fixtures, they will load them before each test.

You don't need to explicity load them in the controller test.



share|improve this answer
That's only true if your models map directly to the tables. This is required because I am using a legacy database. So my problem still remains. :( –  Altonymous Sep 26 '11 at 0:44
add comment
up vote 0 down vote accepted

It looks like no one is able to solve this problem. So I'm simply closing it at this point. Perhaps I'll switch over to Factory_Girl or Machinist.

share|improve this answer
add comment

The error suggests that Rails can't figure out what fixture to load for the test.

I assume the fixture is named Action.yml. Does Rails accept fixture filenames that have uppercase letters?

Per the documentation at http://apidock.com/rails/ActiveRecord/TestFixtures/ClassMethods/set_fixture_class, the set_fixture_class is expecting a classname rather than a string.

So I would try:

set_fixture_class :myaction => Task

And I'd rename the fixture file to myaction.yml

share|improve this answer
add comment

Your Answer


