【问题标题】:zeus test_helper with rails enginezeus test_helper 与 rails 引擎
【发布时间】:2014-08-18 17:12:12
【问题描述】:

如何修改我的 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 进入 engines/engine 并运行 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 start 时,test_helper 启动失败并显示

cannot load such file -- test_helper (LoadError)

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

帮助表示赞赏。

【问题讨论】:

    标签: ruby-on-rails ruby rspec zeus


    【解决方案1】:

    您可以设置 test_helper 的路径。它是宙斯 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 文件的路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多