Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created December 25, 2010 09:12
Show Gist options
  • Save rummelonp/754783 to your computer and use it in GitHub Desktop.
Save rummelonp/754783 to your computer and use it in GitHub Desktop.
Ruby on Rails3でRSpecを使ったルーティングのテストのコード
RspecRailsSample::Application.routes.draw do
get "/" => "index#index", as: :index
get "/user/:id(/max_id/:max_id)" => "index#user", as: :user
post "/find" => "index#find", as: :find
end
require 'spec_helper'
describe :routes do
describe 'GET "index"' do
subject { {get: '/'} }
it { should route_to(controller: 'index', action: 'index') }
end
describe 'GET "user/1"' do
context 'without max id' do
subject { {get: '/user/1'} }
it { should route_to(controller: 'index', action: 'user', id: '1') }
end
context 'with max id "1"' do
subject { {get: '/user/1/max_id/10'} }
it { should route_to(controller: 'index', action: 'user', id: '1', max_id: '10') }
end
end
describe 'POST "find"' do
subject { {post: '/find', url: ''} }
it { should route_to(controller: 'index', action: 'find') }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment