Created
December 10, 2008 18:51
-
-
Save rks/34437 to your computer and use it in GitHub Desktop.
RSpec routing trouble
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using Rails 2.2.2 and RSpec + RSpec-Rails 1.1.11, | |
# | |
# The specs below all pass when I run: | |
# $ ./script/spec spec/controllers/admin/status_controller_spec.rb | |
# | |
# But when I run: | |
# $ rake spec | |
# all three fail with: | |
# | |
# 1) | |
# ActionController::RoutingError in 'Admin::StatusController routing should route /admin/status to the index action' | |
# No route matches "/admin/status" with {:method=>:get} | |
# ./spec/controllers/admin/status_controller_spec.rb:18: | |
# | |
# 2) | |
# ActionController::RoutingError in 'Admin::StatusController should render the text OK' | |
# No route matches {:controller=>"admin/status", :action=>"index"} | |
# ./spec/controllers/admin/status_controller_spec.rb:11: | |
# | |
# 3) | |
# ActionController::RoutingError in 'Admin::StatusController should return a 200 response code' | |
# No route matches {:controller=>"admin/status", :action=>"index"} | |
# ./spec/controllers/admin/status_controller_spec.rb:6: | |
# | |
# Removing the namespace did not change anything | |
# config/routes.rb | |
ActionController::Routing::Routes.draw do |map| | |
map.namespace :admin do |admin_map| | |
admin_map.status 'status', :controller => 'status' | |
end | |
end | |
# app/controllers/admin/status_controller.rb | |
module Admin | |
class StatusController < ApplicationController | |
def index | |
render :text => 'OK' | |
end | |
end | |
end | |
# spec/controllers/admin/status_controller_spec.rb | |
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') | |
module Admin | |
describe StatusController do | |
it 'should return a 200 response code' do | |
get :index | |
response.should be_success | |
end | |
it 'should render the text OK' do | |
get :index | |
response.body.should eql('OK') | |
end | |
end | |
describe StatusController, 'routing' do | |
it 'should route /admin/status to the index action' do | |
params_from(:get, '/admin/status').should eql({:controller => 'admin/status', :action => 'index'}) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment