Posted about 10 years ago. Visible to the public.

Deal with error: Expected foo_trait.rb to define FooTrait

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:

Copy
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 Archive for mistakes.

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

Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Avatar
Dominik Schöler
Last edit:
about 10 years ago
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more