'Rails: uninitialized constant Class::MyModule

I am working on a Rails app, and my tests are throwing an error indicating that a class is undefined. The class in question is defined at lib/vegetable/yam.rb, which contains (in part):

class Vegetable::Yam
  def self.eat
    "tasty"
  end
end

I'm trying to use that eat method in a model app/models/user.rb:

class User < ApplicationRecord
  def phrase
    Vegetable::Yam.eat
  end
end

In the Rails console, if I call the .phrase method on a User instance, I get "tasty" as expected. However, my tests throw:

Failure/Error: Vegetable::Yam.eat
     
     NameError:
       uninitialized constant #<Class:0x000000012caaab90>::Vegetable

Does anyone know why that would be or how I can resolve it? Any pointers would be greatly appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source