NoMethodError in Rails Tests — Fun With Fixtures

In case there’s this weird error message when running unit tests for a Rails app, chances are that your fixtures need some attention. Especially if the schema changed…

NoMethodError: undefined method ‘name’ for #

method method_missing in test_process.rb at line 511
method method_missing in test_case.rb at line 158
method rescue in run in setup_and_teardown.rb at line 26
method run in setup_and_teardown.rb at line 33
method block (2 levels) in run_test_suites in unit.rb at line 641
method each in unit.rb at line 635
method block in run_test_suites in unit.rb at line 635
method each in unit.rb at line 634
method run_test_suites in unit.rb at line 634
method run in unit.rb at line 594
method block in autorun in unit.rb at line 492

There’s no test method given, because, well the tests don’t even get that far: It’s likely that there’s a key (column name) given in the fixture, which is not in the DB schema (anymore).

Advertisement