0

I am writing some integration tests for a Rails application. The application has a set of background tasks which are normally scheduled via cron/whenever. Since the cron jobs only run every few hours, I want to run them directly from the integration tests rather than wait for the cron jobs.

Each task is invoked by whenever using:

runner "<module>.<task>"

i.e. using the rails runner.

My integration tests live in the API wrapper around the application, which is in a different directory to the Rails application.

The question therefore is, can I invoke rails runner on a different directory from the current one, or invoke code in the Rails environment from within an rspec example outside of the Rails project?

Just running rails runner xxx doesn't seem to work (just prints the usage banner) from anywhere other than the top level of the Rails app.

Stefan
  • 8,819
  • 10
  • 42
  • 68

1 Answers1

0

You could do:

<your-app-root>/script/rails runner <arguments>

where <your-app-root> is the root path of your application and <arguments> are the arguments you would give to the runner anyway.

Agis
  • 32,639
  • 3
  • 73
  • 81