mardi 29 décembre 2020

Rails /lib use in fixtures

I have some common code that I have abstracted to a module in my /lib directory:

module ExampleModule
  
  def self.do_something
    # return a value
  end
end

I need to use this method in my test fixtures, however I am getting the following error when I run tests:

Error:

SomeTest#test_that_something:

NoMethodError: undefined method `do_something' for ExampleModule:Module test/fixtures/model_name.yml:4:in `get_binding'

How can I access this method in the test fixtures? I can fix the error by requiring the module in other parts of the app that are loaded during test, but how would I require this module if it was needed specifically in the fixture file here? Would I need to require it in any test using the fixture?

Aucun commentaire:

Enregistrer un commentaire