Yaron Naveh
Yaron Naveh

Reputation: 24406

rails unit test error: "Test is not a module"

I use this command to run a unit test in rails:

$ ruby -Itest test/unit/post_test.rb

I get an error "Test is not a module (TypeError)" and no tests are run.

Could it be related to the fact that I have a model class named "Test"? If there is no way to make that work, what would be the fastest way to refactor and change the class name?

Upvotes: 2

Views: 2306

Answers (1)

hmallett
hmallett

Reputation: 1557

I believe you're right that it's because you've created a model using a name you shouldn't use (Test in this case).

All you should need to do is:

Create a migration to rename the database table: (rename_table :oldname, :newname)

  • Rename the model.
  • Edit any associations in other models.
  • Rename the controller (if required)
  • Modify routes.rb
  • Modify any links in views.
  • Rename views.
  • Rename the model in controllers and views.
  • Rename and modify any tests.

Upvotes: 5

Related Questions