Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test routes with Rspec 2 in Rails 3?

I can't find anything explaining how to test routes in Rails 3. Even in the Rspec book, it doesn't explain well.

Thanks

like image 525
donald Avatar asked May 20 '11 00:05

donald


1 Answers

There is a brief example on the rspec-rails Github site. You can also use the scaffold generator to produce some canned examples. For instance,

rails g scaffold Article

should produce something like this:

require "spec_helper"

describe ArticlesController do
  describe "routing" do

    it "routes to #index" do
      get("/articles").should route_to("articles#index")
    end

    it "routes to #new" do
      get("/articles/new").should route_to("articles#new")
    end

    it "routes to #show" do
      get("/articles/1").should route_to("articles#show", :id => "1")
    end

    it "routes to #edit" do
      get("/articles/1/edit").should route_to("articles#edit", :id => "1")
    end

    it "routes to #create" do
      post("/articles").should route_to("articles#create")
    end

    it "routes to #update" do
      put("/articles/1").should route_to("articles#update", :id => "1")
    end

    it "routes to #destroy" do
      delete("/articles/1").should route_to("articles#destroy", :id => "1")
    end

  end
end
like image 157
zetetic Avatar answered Nov 08 '22 19:11

zetetic