Ok, problem was that Thor runs in development
mode by default, not test
. To solve my problem I just needed to set this ENV variable:
RAILS_ENV=test bundle exec thor ...
This helped me. Second hint: make sure in your task, that you are in Test ENV, otherwise you'll lose all your development data. You can check out my article about this task.