简体   繁体   English

如何在Rails 3插件中测试路由?

[英]How do i test routes in Rails 3 plugins?

I've tried to use the recommended way (from the Rails Guides) to test routes generated in plugins, but the test keeps failing. 我尝试使用推荐的方法(来自Rails指南)来测试插件中生成的路由,但是测试一直失败。

What's odd is that if I reload the routes AFTER creating the route (or so I think), the test fails, but if I let the test go through once (eg using autotest), then the route gets recognized on subsequent attempts. 奇怪的是,如果我在创建路由后重新加载路由(或者我认为如此),则测试将失败,但是如果我让测试通过一次(例如,使用自动测试),则该路由将在后续尝试中被识别。

Here's the code: 这是代码:

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

Any idea how to make it pass all the time? 知道如何使其始终通过吗?

Hmm. The README for rspec-rails-2 for rails-3 at http://github.com/rspec/rspec-rails has a "Routing specs" section. http://github.com/rspec/rspec-rails上的rails-3的rspec-rails-2的README具有“路由规格”部分。 There's no need for the before :all with the latest RSpec, perhaps? before :all没有必要before :all也许before :all带有最新的RSpec?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM