Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 323
btelles Avatar asked Aug 08 '10 13:08

btelles


1 Answers

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?

like image 181
Ed Ruder Avatar answered Sep 29 '22 00:09

Ed Ruder