简体   繁体   English

使用测试/虚拟应用程序测试Rails gem,/ tmp文件夹会崩溃……以某种方式

[英]Testing a Rails gem with test/dummy app, /tmp folder gets clobbered…somehow

I'm writing a gem that has to select which version of a XYZ.js file to make available to sprockets //= require "XYZ" statements based on configuration at app startup. 我正在编写一个gem,必须根据应用程序启动时的配置来选择要供链轮使用的XYZ.js文件的版本//= require "XYZ"语句。 My solution is to copy the XYZ.variant.js or XYZ.variant2.js to /tmp/cache/<gemname>/XYZ.js in the Rails app. 我的解决方案是将XYZ.variant.jsXYZ.variant2.js复制到Rails应用程序中的/tmp/cache/<gemname>/XYZ.js中。 This seems to work if I manually test; 如果我手动测试,这似乎可行; if I go to the test/dummy folder and test the functionality via rackup the XYZ.js is properly found. 如果我去test/dummy文件夹,并通过测试功能rackupXYZ.js正确找到。 If I test the gem via another rails app, it works (via path: in Gemfile). 如果我通过另一个Rails应用程序测试了gem,它就可以工作(通过path: Gemfile中)。

But, when I run the test suite for this gem, it fails, because at some point after the initial copy to /tmp/cache/<gemname>/XYZ.js , the whole tmp folder gets cleared, and the only thing in it by the time the test actually gets run is /tmp/cache/assets . 但是,当我为该gem运行测试套件时,它失败了,因为在将初始副本复制到/tmp/cache/<gemname>/XYZ.js之后的某个时刻,整个tmp文件夹都被清除了,其中唯一的东西到测试实际开始运行的时间是/tmp/cache/assets I don't understand how this could be behaving different b/w the test suite and the other 2 working methods. 我不明白这可能与测试套件和其他2种工作方法的行为有所不同。 It's as if the initialization order is different or something. 好像初始化顺序不同。 Is there something special that running via rackup would do that would change the initialization order? 通过rackup会改变初始化顺序吗?

Note that the test suite worked fine before this particularly addition to the code that did the tmp copying. 请注意,在进行tmp复制的代码之前,特别是在此之前,测试套件可以正常工作。 It's just the normal enginex code that would have been generated. 只是生成的普通enginex代码。

这与初始化程序无关,而与另一个测试案例(对于生成器)无关,后者破坏了tmp文件夹。

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

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