Rails:如何测试 lib/目录中的代码? [英] Rails: How to test code in the lib/ directory?

查看:31
本文介绍了Rails:如何测试 lib/目录中的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从解析器对象获取数据的模型.我认为解析器类应该存在于 lib/目录中(尽管我可以被说服它应该存在于其他地方).问题是:解析器类的单元测试应该在哪里?我如何确保每次运行 rake 测试时它们都运行?

I have a model which gets its data from a parser object. I'm thinking that the parser class should live in the lib/ directory (although I could be persuaded that it should live soewhere else). The question is: Where should my unit tests for the parser class be? And how do I ensure that they are run each time I run rake test?

推荐答案

在我正在处理的 Rails 应用程序中,我决定将测试放在 test\unit 目录中.我也会按模块/目录嵌套它们,例如:

In the Rails application I'm working on, I decided to just place the tests in the test\unit directory. I will also nest them by module/directory as well, for example:

lib/a.rb   => test/unit/a_test.rb
lib/b/c.rb => test/unit/b/c_test.rb

对我来说,这是最后阻力的路径,因为这些测试无需进行任何其他更改即可运行.

For me, this was the path of last resistance, as these tests ran without having to make any other changes.

这篇关于Rails:如何测试 lib/目录中的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆