![](/img/trans.png)
[英]in my rspec test suite, how can I populate a static table with config data my app uses?
[英]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.