8

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?

btelles
  • 5,390
  • 7
  • 46
  • 78
  • Could you maybe write the errors with which the tests fails? – khebbie Aug 12 '10 at 05:23
  • Does the route work if you run the same reload_routes function during application execution? That is, does it work if you just stick that line in while you're in dev mode? – jasonpgignac Aug 15 '10 at 16:57

1 Answers1

1

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
  • 578
  • 6
  • 13
  • Thanks Ed, but I'm looking at routes generated through plugins and plugin methods, not through the routes.rb file in an application. – btelles Oct 05 '10 at 15:40