在红宝石上测试路线的位置 [英] Where to test routes in ruby on rails

查看:106
本文介绍了在红宝石上测试路线的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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并不负责测试是否在您的路线中定义了 http://yoursite.com/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 http://yoursite.com/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.

这篇关于在红宝石上测试路线的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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