views:

240

answers:

2

I've tried to use the recommended way (from the Rails Guides) to test routes generated in plugins, but the test keeps failing.

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 (e.g. 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?

+1  A: 

I found this to be helpful.. Perhaps you will too.

http://snipplr.com/view/37067/inspect-and-test-routes-in-console-rails-3/

Chris Amini
Thanks Chris. That syntax appears to be the standard way of checking up on routes, whereas I'm using rspec to test them. I think the problem lies somewhere in that the application doesn't correctly reload the routes, or that I'm loading the routes in the wrong place.
btelles
+1  A: 

Hmm. The README for rspec-rails-2 for rails-3 at http://github.com/rspec/rspec-rails has a "Routing specs" section. There's no need for the before :all with the latest RSpec, perhaps?

Ed Ruder
Thanks Ed, but I'm looking at routes generated through plugins and plugin methods, not through the routes.rb file in an application.
btelles