Search code examples
ruby-on-railsrubyrubygemszeus

How to run Rails console in test environment with Zeus?


What I want to do is to run rails console test but with Zeus gem, something like: zeus console test

Thanks a lot in advance!


Solution

  • The solution is achieved by modifying your zeus.json file to include a new console command that will run in the test environment which I have called test_console.

    Here is my entire zeus.json file, the only relevant bit being the part starting with "test_console":

    {
      "command": "ruby -rubygems -r./custom_plan -eZeus.go",
    
      "plan": {
        "boot": {
          "default_bundle": {
            "development_environment": {
              "prerake": {"rake": []},
              "runner": ["r"],
              "console": ["c"],
              "server": ["s"],
              "generate": ["g"],
              "destroy": ["d"],
              "dbconsole": []
            },
            "test_environment": {
              "cucumber_environment": {"cucumber": []},
              "test_helper": {"test": ["rspec", "testrb"]},
              "test_console": ["tc"]
            }
          }
        }
      }
    }
    

    To enable test_console however, you will need to create a custom plan in your custom_plan.rb file as follows:

    require 'zeus/rails'
    
    class CustomPlan < Zeus::Rails
      def default_bundle_with_test_env
        ::Rails.env = 'test'
        ENV['RAILS_ENV'] = 'test'
        default_bundle
      end
    
      def test_console
        console
      end
    end
    
    Zeus.plan = CustomPlan.new
    

    Note the default_bundle_with_test_env is needed, as is the test_console method which was defined above in your zeus.json file.

    Finally, run: zeus test_console or zeus tc