自定义 Shoula 宏的初始化
我编写了一个自定义 Shoulda 宏并将其放置在 *test/shoulda_macros* 目录下。为了在测试用例文件中使用自定义宏,我还应该做什么?我应该重新打开 TestCase 类吗?还要别的吗?我可能错过了一些简单的事情。谢谢。
I've written a custom Shoulda macro and placed it under *test/shoulda_macros* directory. What else should I do in order to use my custom macro in my test case file? Should I reopen TestCase class? Anything else? I am probably missing something simple. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 shoulda 3.x 中,该术语从“宏”变为“匹配器”。您可以确切地看到 shoulda-matchers gem 如何与 TestUnit 此处。
您可以将匹配器提取到新的 gem 中,如果该 gem 足够通用,对其他人有用,则可以发布该 gem。否则,您可以在 test_helper.rb 文件中扩展 TestCase,或者将该代码放入它自己的文件中并从 test_helper 中需要它。像这样的事情:
In shoulda 3.x, the term went from "macros," to "matchers." You can see exactly how the shoulda-matchers gem works with TestUnit here.
You can either extract your matchers into a new gem and perhaps publish the gem if it's general enough to be of use to others. Otherwise, you can extend TestCase in your test_helper.rb file, or put that code in it's own file and require it from test_helper. Something like this: