Deal with error: Expected foo_trait.rb to define FooTrait

Posted . Visible to the public.

Lately, I came across a nasty error. I had a class Article that included FooTrait and BarTrait. In BarTrait, I then accidentally called a non-existent method:

has_defaults :dummy => Dummy.non_existent_method

From that moment, no page would load anymore but always display an exception: Expected foo_trait.rb to define FooTrait. That trait had nothing to do with BarTrait.

Since it doesn't tell you what's wrong, you either remember where you were working last or you need to check all traits Show archive.org snapshot for mistakes.

This behavior is likely to be caused by Rails' autoloading.

Dominik Schöler
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2012-06-28 07:56)