[英]Rails engine test/dummy with Spork, Guard, RSpec?
I have a Rails gem that I am testing with RSpec. 我有一个Rails宝石,我正在用RSpec测试。 My gem's code is in lib/my_gem, and there is a test application that Rails generated for me when I created the gem, in the folder test/dummy.
我的gem的代码在lib / my_gem中,当我创建gem时,Rails为我生成了一个测试应用程序,在test / dummy文件夹中。 I have my specs in test/dummy/spec/models/task_spec.rb.
我在test / dummy / spec / models / task_spec.rb中有我的规格。 I can run these specs fine with the rspec command.
我可以使用rspec命令运行这些规范。
Now I wanted to use Spork and Guard for my testing. 现在我想用Spork和Guard进行测试。 I followed RailsCasts http://railscasts.com/episodes/285-spork to install spork in my test/dummy app.
我按照RailsCasts http://railscasts.com/episodes/285-spork在我的测试/虚拟应用程序中安装spork。 It does work but I have 2 issues:
它确实有效,但我有两个问题:
Usually in the development environment config.cache_classes
is set to true
. 通常在开发环境中,
config.cache_classes
设置为true
。 When you're using spork you should disable this options, for more details see: ./config/environments/test.rb
file. 当您使用spork时,应禁用此选项,有关详细信息,请参阅:
./config/environments/test.rb
文件。
Instead config.filter_run :focus => true
try use RSpec's tags: https://www.relishapp.com/rspec/rspec-core/v/2-4/docs/command-line/tag-option 而不是
config.filter_run :focus => true
尝试使用RSpec的标签: https : config.filter_run :focus => true
I finally was able to solve the problem. 我终于能够解决问题了。 The key is running the tests from the root directory and not from test/dummy.
关键是从根目录运行测试而不是从test / dummy运行。 You can see my setup if you clone my gem https://github.com/mrbrdo/has_moderated I think the key was in the Guardfile (note the paths to test/dummy), Rakefile (the spec task) and in both spec_helper.rb files (one in spec/ and one in test/dummy/spec).
如果克隆我的gem,你可以看到我的设置https://github.com/mrbrdo/has_moderated我认为密钥在Guardfile中(注意测试/虚拟的路径),Rakefile(规范任务)和spec_helper。 rb文件(一个在spec /中,一个在test / dummy / spec中)。 Feel free to comment if you find something else was required.
如果您发现其他需要,请随时发表评论。
Spring now has documentation on how to use when developing a Rails Engine. Spring现在有关于开发Rails引擎时如何使用的文档。 https://github.com/rails/spring#application-root
https://github.com/rails/spring#application-root
Simply specify where to find the root of the test app: 只需指定在哪里找到测试应用的根目录:
Spring.application_root = './test/dummy'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.