RoR、RSpec:想要验证页面上的每个链接是否都可以提供服务
我正在我的 RoR 应用程序上加强 RSpec 测试。我想要一种简单的方法来验证单击页面上的每个链接是否得到正确处理,即生成到控制器的可识别路由,并在控制器中有一个方法来为其提供服务。
我可以为每个页面编写特定的测试,但最好让 RSpec 辅助函数自动查找页面上的所有链接并验证每个链接。 FWIW,可以安全地假设所有链接都在我的域中(没有指向外部站点的链接)。
我不会通过列举我尝试过的所有方法来扩大这个问题,而是会问:你会怎么做?看起来是一个常见且有用的功能。
- FF
I'm beefing up RSpec tests on my RoR app. I'd like a simple way to verify that clicking on each link on a page is properly handled, i.e. generates a recognized route to a controller, and has a method in the controller to service it.
I can write specific tests for each page, but it would be preferable to have an RSpec helper function find all the links on a page automagically and verify each one. FWIW, it's safe to assume that all links are in my domain (there are no links to external sites).
Rather than bloat this question by enumerating all the things I've tried, I'll just ask: how would you do it? Seems like a common and useful function.
- ff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会用水豚问题...
I'd use Capybara prob...
这种事情属于集成测试,您可以用 RSpec 或 Cucumber 编写。单独测试链接的价值有限 - 它会告诉您链接是否已损坏,但不会告诉您链接是否指向错误的位置。
在 Cucumber 中,你可以这样写:
This kind of thing belongs in an integration test, which you could write either in RSpec or Cucumber. Testing a link on it's own is of limited value - it will tell you if the link is broken, but it won't tell you if the link is pointing to the wrong place.
In Cucumber, you could write something like: