加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何在Rails 3插件中测试路由?

发布时间:2020-12-17 04:37:01 所属栏目:百科 来源:网络整理
导读:我尝试使用推荐的方式(来自Rails指南)来测试插件中生成的路由,但测试仍然失败. 奇怪的是,如果我在创建路线后重新加载路线(或者我认为),测试失败,但如果我让测试通过一次(例如使用自动测试),那么路线会在后续尝试中被识别. 这是代码: describe "named route
我尝试使用推荐的方式(来自Rails指南)来测试插件中生成的路由,但测试仍然失败.

奇怪的是,如果我在创建路线后重新加载路线(或者我认为),测试失败,但如果我让测试通过一次(例如使用自动测试),那么路线会在后续尝试中被识别.

这是代码:

describe "named route report_with_last_name_smith_path" do
  before :all do
    Reports::Application.routes.draw do
        match "/report_some_report_for_us" => "report#report_some_report_for_us",:as => :report_some_report_for_us
    end
    Rails.application.reload_routes! # If I leave this out,then the test
                                     # passes the second time that autotest/autospec
                                     # go through.
  end
  it "route for every record" do
    {:get => '/report_some_report_for_us'}.should route_to(:controller => 'report',:action => 'report_some_report_for_us')
  end
end

知道如何让它一直通过吗?

解决方法

嗯.在 http://github.com/rspec/rspec-rails上用于rails-3的rspec-rails-2自述文件有一个“路由规范”部分.以前没有必要:也许是最新的RSpec?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读