I have a fairly simple Rails 3 project where I've defined a custom route:
get 'factions/:name' => 'factions#show', :as => :factions
get 'factions' => 'factions#index'
... which when running rails s
gives me the expected page (http://localhost:3000/factions/xyz
is HTTP 200 with the app/views/factions/show.html.haml
being displayed). However I've tried multiple different ways of expressing a spec that will work, below is my latest incarnation:
require 'spec_helper'
describe FactionsController do
render_views
describe "GET 'show'" do
before { get '/xyz' }
subject { controller }
it { should respond_with(:success) }
it { should render_template(:show) }
end
describe "GET 'index'" do
it "should be successful" do
get 'index'
response.should be_success
end
end
end
The GET 'index'
spec passes without complaint but no matter what I do the GET 'show'
specs cannot pass - even if they do succeed when I am browsing to them locally.
1) FactionsController GET 'show'
Failure/Error: before { get '/xyz' }
ActionController::RoutingError:
No route ma开发者_Python百科tches {:controller=>"factions", :action=>"/xyz"}
# ./spec/controllers/factions_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
The action really should be show
but my routes.rb
configuration must be incorrect or something. What gives?
(Additional context: I am using bundle exec spork
for speeding up my specs and I have restarted the spork
server multiple times just to make sure I'm not completely insane.)
Change:
before { get '/xyz' }
To:
before { get :show, :name => 'xyz' }
精彩评论