0

如何修改我的 zeus.json 文件以在与我的应用程序一起开发的引擎中运行 rspec 测试?

我的 Rails 应用程序看起来像这样:

/config
/engines
  /engine <-- this is the engine I'm developing inside the parent app
    /spec <-- here are the rspec tests
/custom_plan.rb
/zeus.json

通常,我cd进入引擎/引擎并运行rspec引擎测试(它有一个运行的虚拟应用程序)。

zeus init在顶层目录中运行会创建zeus.jsoncustom_plan.rb

{
  "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": {
          "test_helper": {"test": ["rspec", "testrb"]}
        }
      }
    }
  }
}

require 'zeus/rails'

class CustomPlan < Zeus::Rails

  # def my_custom_command
  #  # see https://github.com/burke/zeus/blob/master/docs/ruby/modifying.md
  # end

end

Zeus.plan = CustomPlan.new

然后当我运行zeus starttest_helper 启动失败时

cannot load such file -- test_helper (LoadError)

我的猜测是因为我的规格当前位于引擎/引擎/规格中,并且父应用程序中没有“规格”文件夹。我希望能够更新我的 custom_plan 来运行这些测试。取而代之的是,我希望能够在引擎中创建一个单独的计划和 zeus.json,但是当我cd进入引擎/引擎并运行 zeus init 时,它仍然会在应用程序的根目录下创建配置文件,所以我不确定如何让宙斯“进入”我的引擎。

帮助表示赞赏。

4

1 回答 1

1

您可以设置 test_helper 的路径。这是 zeus gem 中的一种方法:https ://github.com/burke/zeus/blob/master/rubygem/lib/zeus/rails.rb#L185

我在升级到 rspec 3 时遇到了同样的错误,并且找不到任何将 zeus 与 rspec 3 一起使用的文档,所以我设置了 zeus.json:

{
  "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": {
          "test_helper": {"spec": ["rspec"]}
        }
      }
    }
  }
}

和 custom_plan.rb

require 'zeus/rails'

class CustomPlan < Zeus::Rails

  def spec(argv=ARGV)
    RSpec::Core::Runner.disable_autorun!
    exit RSpec::Core::Runner.run(argv)
  end
end

# set rails_helper for rspec 3
ENV['RAILS_TEST_HELPER'] = 'rails_helper'
Zeus.plan = CustomPlan.new

因此,您可以尝试设置ENV['RAILS_TEST_HELPER']test_helper 文件的路径。

于 2014-08-18T09:12:12.987 回答