Setting the environment variable RAILS_ENV to "production" on the require statement should work. I used conditional assignment here so that the default environment is "production" if the environment variable is not set in advance.
class CheckData < Thor ENV['RAILS_ENV'] ||= 'production' require File.expand_path('config/environment.rb') end
If you run it as a Thor task from the command line, you can set the environment variable before starting and thus override the default assignment:
export RAILS_ENV=test; thor check_data
See the Rails Application Settings section of the Rails Environment Settings from RailsGuides for additional environment variables.
Scott source share