我尝试使用推荐的方式(来自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?