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

bte*_*les 8 ruby rspec ruby-on-rails ruby-on-rails-plugins

我尝试使用推荐的方式(来自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
Run Code Online (Sandbox Code Playgroud)

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

Ed *_*der 1

唔。http://github.com/rspec/rspec-rails上的 rspec-rails-2 for Rails-3 的自述文件有一个“路由规范”部分。before :all也许不需要最新的 RSpec?