【发布时间】:2015-03-09 18:10:14
【问题描述】:
我正在编写一个与测试过程集成的 Ruby Gem,我想编写一个集成测试来证明它可以像我期望的那样端到端地工作。我包括一个使用 Gem 的简单应用程序 (TestApp)。
我的 gem 包含一个 spec 文件夹,以及它的根目录中的测试应用程序。测试应用程序将其测试包含在 features 文件夹中。 (当然还有其他东西)。
my_gem
|
- spec
- test_app
|
- features
在添加新测试之前,如果我在my_gem 目录中并执行bundle exec rspec,我对my_gem 的测试将按预期执行。如果我执行:
cd test_app
bundle exec features
我对@987654328@ 的测试按预期执行。现在,如果我在 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 时,我在没有额外测试的情况下得到相同的错误,但当我在没有bundle exec 的情况下执行命令时却没有。在测试中删除bundle exec 没有任何区别。
是什么导致了这些错误,有没有办法可以在我的 my_gem 测试中执行我的 test_app 测试套件,这样它们就不会导致错误?
【问题讨论】:
标签: ruby-on-rails testing rspec