构建 rspec 模块的推荐方法?
我有一个 Rails 应用程序,以及 lib
中的代码。我在 RAILS_ROOT
下有 spec
目录。
我应该如何将测试放入 spec
中?
目前,我正在考虑以下内容:
spec/lib
spec/controllers
spec/models
此外,我做了一些常见的设置/使用常见步骤(例如,生成无效用户)在许多测试中。您建议我将在 rspec 测试中执行常见设置/步骤的模块放在哪里?
I have a rails app, plus code in lib
. I have the spec
directory under RAILS_ROOT
.
How should I put my tests in spec
?
Currently, I am thinking of the following:
spec/lib
spec/controllers
spec/models
Further, I do some common setup / use common steps (e.g., generate an invalid user) in many tests. Where do you recommend I put the modules that do the common setup /steps in my rspec tests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您建议的目录结构很好。
至于辅助模块,常见的习惯用法是将它们放在 spec/support 目录中。您可以通过将以下代码放入您的 spec_helper.rb 文件中来自动包含它们:
您可以将代码直接放入 spec_helper.rb 本身,但这可能会变得混乱,并且它们可能会被清除重新生成帮助文件。
Your proposed directory structure is fine.
As for your helper modules, a common idiom is for these to go in the spec/support directory. You can include them all automatically by placing the following code into your spec_helper.rb file:
You could just place the code directly in spec_helper.rb itself, but that can get messy and they could be wiped out by regenerating the helper file.