繁体   English   中英

如何在另一个应用程序的测试套件中的一个应用程序中执行RSpec测试套件?

[英]How can I execute an RSpec test suite in one app from another app's test suite?

我正在编写一个与测试过程集成的Ruby Gem,我想编写集成测试以表明它可以按预期的端到端方式工作。 我包括一个使用Gem的简单应用程序(TestApp)。

我的gem包含一个spec文件夹,其根中包含测试应用程序。 测试应用程序将其测试包含在features文件夹中。 (当然还有其他东西)。

my_gem
  |
  - spec
  - test_app
      |
      - features

在添加新测试之前,如果我位于my_gem目录中并执行bundle exec rspec ,则对my_gem测试my_gem预期执行。 如果我执行:

cd test_app
bundle exec features

我对test_app测试按预期执行。 现在,如果我将my_gem测试添加到测试中:

describe "Test test suite"
    it "executes as expected"
        `bundle exec test_app/features`
    end
end

并在my_gem执行测试,我得到以下信息:

C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.2/lib/tzinfo/data_source.rb:182:in `rescue in create_default_data_source': No source of timezone data could be found. (TZInfo::DataSourceNotFound)
Please refer to http://tzinfo.github.io/datasourcenotfound for help resolving this error.
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.2/lib/tzinfo/data_source.rb:179:in `create_default_data_source'
...

按照建议的URL上的说明进行操作会使我陷入困境,即向我的gem添加依赖项,否则我将不需要这些依赖项,也不想强迫该gem的最终用户依赖。

除了上述内容,我还尝试了:

exec('bundle exec rspec test_app/features')

Dir.chdir('test_app') do
    `bundle exec rspec features`
end

但是每次我得到相同的错误。 有趣的是,当我从控制台中的my_gem目录执行bundle exec rspec test_app/features时,如果没有额外的测试,我会遇到相同的错误,但是当我执行不my_gem bundle exec的命令时,我不会得到相同的错误。 在测试中删除bundle exec没什么区别。

是什么原因造成这些错误,并在那里,我可以执行我的方式test_app从我内测试套件my_gem测试,以便它们不会导致错误?

我在这里找到了解决方案: http : //makandracards.com/makandra/15649-how-to-discard-a-surrounding-bundler-environment

事实证明,这些测试是在我当前的环境下执行的(其他人也许可以更好地解释这一点)。 解决方案是使用Bundler.with_clean_env

Bundler.with_clean_env do
    Dir.chdir('test_app') do
        `bundle exec rspec features`
    end
end

暂无
暂无

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

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