简体   繁体   中英

zeus test_helper with rails engine

How can I modify my zeus.json file to run rspec tests in an engine I am developing alongside my application?

My Rails app looks something like this:

/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

Normally, I cd into engines/engine and run rspec to run the engine tests (it has a dummy app it runs against).

Running zeus init in the top directory creates zeus.json and custom_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

Then when I run zeus start the test_helper start-up fails with

cannot load such file -- test_helper (LoadError)

My guess is because my specs are currently in engines/engine/spec and there is no "spec" folder in the parent app. I'd like to be able to update my custom_plan to run those tests instead. In lieu of that, I'd like to be able to create a separate plan and zeus.json inside the engine, but when I cd into engines/engine and run zeus init, it still creates the config files at the root of the application, so I'm not sure how to get zeus "into" my engine.

Help appreciated.

You can set the path for test_helper. It is a method in the zeus gem: https://github.com/burke/zeus/blob/master/rubygem/lib/zeus/rails.rb#L185

I just had the same error for upgrading to rspec 3 and couldnt find any documentation for using zeus with rspec 3, so I set 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"]}
        }
      }
    }
  }
}

and 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

So you could try setting ENV['RAILS_TEST_HELPER'] to the path to your test_helper file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM