在红宝石上测试路线的位置

编程入门 行业动态 更新时间:2024-10-27 15:24:46
本文介绍了在红宝石上测试路线的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在哪里测试红宝石上的路线?

Where to test routes in ruby on rails?

  • 单元测试?
  • 功能测试?
  • 集成测试?

添加项:

确切地说,在何处应用断言描述 和在api上?

To be exact, where to apply assertions described on guides and on api?

推荐答案

路由应作为集成测试的一部分进行。集成测试是您测试应用程序重要工作流程的地方-更具体地说,是否定义URL似乎是重要的工作流程。

Routes should be done as part of integration tests. Integration tests are where you test the important work flows of your application - more specifically whether a URL is defined or not seems to be an important workflow.

您的集成测试看起来像任何正常集成测试:

Your integration test would look like any normal integration test:

# /tests/integration/routes_test.rb require 'test_helper' class RoutesTest < ActionController::IntegrationTest test "route test" do assert_generates "/photos/1", { :controller => "photos", :action => "show", :id => "1" } assert_generates "/about", :controller => "pages", :action => "about" end end

关于 @jemminger 对未测试路线的响应-虽然是Rail的测试可验证route.rb是否有效,而Rails并不负责测试是否在您的路线中定义了 yoursite/users 。需要注意的是,大多数路由测试都可以在现有的集成测试中完成,因此路由的特定测试可能是多余的。

As to @jemminger's response of not testing routes - While it is Rail's tests that verify that routes.rb works, it's not Rail's responsibility to test whether yoursite/users is defined in your routes. The caveat is that most route testing could be done in existing integration tests, so specific tests for routes could be redundant.

我能想到的特定用例就是已经或将要从Rails 2升级到Rails 3的人员。定义路由的代码已发生很大变化,与从用户报告404错误时相比,从测试中找出路由已正确升级的用户要好得多。

The specific use case I can think of are all the people that have already, or are going to upgrade from Rails 2 to Rails 3. The code to define routes has changed significantly, and it's better to find out from tests that the routes were upgraded correctly, than from users when they report 404 errors.

更多推荐

在红宝石上测试路线的位置

本文发布于:2023-10-26 20:40:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:红宝石   路线   位置   测试

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!