简体   繁体   English

从rake文件执行另一个应用程序的测试

[英]Execute tests for another app from a rake file

I'm trying to execute cucumber tests for a project within a rake file in another project. 我正在尝试为另一个项目中的rake文件中的项目执行黄瓜测试。

Currently I am trying this: 目前我正在尝试这个:

system "cd /path/to/project;rvm use --create 1.9.2-p290@test; cucumber features/test.feature"

This works for the cd, and the rvm seems to work if I run which ruby after the rvm use... but the problem is that the cucumber gem seems to be called from the current folder (not the app to test folder). 这适用于cd,如果我在rvm使用后运行哪个ruby,rvm似乎有效......但问题是黄瓜宝石好像是从当前文件夹调用的(不是app到test文件夹)。

The error I get is: 我得到的错误是:

cucumber is not part of the bundle. Add it to Gemfile. (Gem::LoadError)

It seems to be using the local gemset version of cucumber rather than the @test gemset. 它似乎使用黄瓜的本地gemset版本而不是@test gemset。

Any thoughts on this? 有什么想法吗?

Or is there a better way to run cucumber tests for another project that relies on rvm & a different bundle? 或者,是否有更好的方法为另一个依赖rvm和不同捆绑的项目运行黄瓜测试?

I've also been trying to do exactly the same thing; 我也一直试图做同样的事情; run an application's tests (or any rake task) from inside another 'control' application. 从另一个“控制”应用程序内部运行应用程序的测试(或任何rake任务)。

Reason: (just so I don't get served with a "why on earth?") 原因:(就这样,我没有得到“为什么在地球上?”)

I am trying to build an application (rather like cruisecontrol.rb ) which can monitor, schedule and review the specs for a set of apps. 我正在尝试构建一个应用程序(比如cruisecontrol.rb),它可以监视,安排和查看一组应用程序的规范。

After some digging around in cruisecontrol's source I found that Bundler provides a solution; 在巡航控制源的一些挖掘后,我发现Bundler提供了一个解决方案;

Bundler.with_clean_env do 
  system "rake spec"
end

see line56 of https://github.com/thoughtworks/cruisecontrol.rb/blob/master/lib/platform.rb 参见https://github.com/thoughtworks/cruisecontrol.rb/blob/master/lib/platform.rb的第 56行

That steps out of the bundle and the command is run without the control app's gems. 跳出捆绑包,命令在没有控制应用程序的宝石的情况下运行。

BUT as is most likely, the command uses bundle exec then this stops working. 最有可能的是,该命令使用bundle exec然后停止工作。

Bundler.with_clean_env { system "bundle exec rake spec" }

And you are right back to the exact same problem. 你回到了完全相同的问题。 This is caused by some bundler variables still existing and being inherited by the sub-shell. 这是由一些仍然存在并由子shell继承的bundle变量引起的。 Full (very good) explanation here . 满(非常好)的解释在这里

The solution is to change the with_clean_env method on bundler like this; 解决方案是在with_clean_env上更改with_clean_env方法,就像这样;

BUNDLER_VARS = %w(BUNDLE_GEMFILE RUBYOPT BUNDLE_BIN_PATH)
module Bundler
  def self.with_clean_env &blk
    bundled_env = ENV.to_hash
    BUNDLER_VARS.each{ |var| ENV.delete(var) }
    yield
  ensure
    ENV.replace(bundled_env.to_hash)     
  end
end

above code from here 以上代码来自这里

I put that in the environment.rb of my control application (it should probably be in a initializer?) and now I can run the specs of another app from within the control app. 我把它放在我的控制应用程序的environment.rb中(它可能应该在初始化程序中?)现在我可以在控制应用程序中运行另一个应用程序的规范。

#in control app
result = nil
Dir.chdir(test_app_path) #move into test app
Bundler.with_clean_env { result = `bundle exec rake spec` } #run test apps specs
puts result #display result inside control app

Changing the ; 改变; in your script to && seems to work. 在您的脚本中, &&似乎有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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