如何使用Zeus在测试环境中运行Rails控制台?

时间:2021-05-16 23:04:56

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

我想做的是运行rails控制台测试,但是使用Zeus gem,比如:Zeus控制台测试

Thanks a lot in advance!

非常感谢!

1 个解决方案

#1


20  

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.

解决方法是修改你的宙斯。json文件包含一个新的控制台命令,该命令将在测试环境中运行,我将其命名为test_console。

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

这是我的整个宙斯。json文件,唯一相关的部分是由“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:

要启用test_console,您将需要在custom_plan中创建一个自定义计划。rb文件如下:

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.

注意,default_bundle_with_test_env是必需的,test_console方法也是需要的,它是在前面的zeus中定义的。json文件。

Finally, run: zeus test_console or zeus tc

最后,运行:zeus test_console或zeus tc

#1


20  

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.

解决方法是修改你的宙斯。json文件包含一个新的控制台命令,该命令将在测试环境中运行,我将其命名为test_console。

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

这是我的整个宙斯。json文件,唯一相关的部分是由“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:

要启用test_console,您将需要在custom_plan中创建一个自定义计划。rb文件如下:

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.

注意,default_bundle_with_test_env是必需的,test_console方法也是需要的,它是在前面的zeus中定义的。json文件。

Finally, run: zeus test_console or zeus tc

最后,运行:zeus test_console或zeus tc