Ask A Question

Notifications

You’re not receiving notifications from this thread.

Testing Controllers that call an activejob

Paul C asked in Rails

Hi,

My integration tests hit a create method in my API that calls an activejob. This works fine in the actual app, but when I run any tests I get:

NameError: uninitialized constant Api::V1::ControllerName::JobName

Do I need to mock out the ActiveJob API or do load ActiveJob inside my ActionDispatch::IntegrationTest?
Thanks!

Reply

Maybe you just forgot to change uninitialized constant Api::V1::ControllerName::JobName to match your class name?

Reply

Thanks - I'm just calling

JobName.perform_later @content_for_job

Which raises the NameError. If I run it from the application UI it works fine, it's only when running from the test suite that it throws the NameError

Reply

Yeah, which is why my guess is that your test suite is referencing the wrong thing somewhere when it's trying to replicate the same thing.

Reply

Thanks. I made no changes to my codebase, but updated my mac which forced a restart of everything and now the tests pass without issue. I can only think that it was related to this Sidekiq issue:

https://github.com/mperham/sidekiq/issues/2207

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,038+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.