That's strange °_° In my app it fails:
====================================================================
.F.
Failures:
1) SessionsController POST to 'login' returns http success
Failure/Error: post '/login'
ActionController::RoutingError:
No route matches {:controller=>"sessions", :action=>"/login"}
# ./spec/controllers/sessions_controller_spec.rb:15:in `block (3
levels) in <top (required)>'
====================================================================
That's rake routes:
====================================================================
login POST /login(.:format) sessions#login_create
GET /login(.:format) sessions#login
logout GET /logout(.:format) sessions#logout
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/registrati(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
====================================================================
And this is the failing spec:
====================================================================
require 'spec_helper'
describe SessionsController do
describe "GET 'login'" do
before { get 'login' }
it "returns http success" do
response.should be_success
end
end
describe "POST 'login'" do
it "returns http success" do
post '/login'
response.should be_success
response.should render_template 'sessions/login_create'
end
end
describe "GET 'logout'" do
it "returns http success" do
get 'logout'
response.should be_success
end
end
end
====================================================================
If I change `post '/login'` with `post 'login'` it fails with:
====================================================================
F..
Failures:
1) SessionsController POST to 'login' returns http success
Failure/Error: response.should render_template
'sessions/login_create'
expecting <"sessions/login_create"> but rendering with
<"sessions/login, layouts/application">
# ./spec/controllers/sessions_controller_spec.rb:17:in `block (3
levels) in <top (required)>'
====================================================================
By this error, it seems to me that post actually perform a get, really
strange @_@
7stud, which versions of rails & rspec do you have? Mine:
* rails (3.2.6)
* railties (3.2.6)
* rspec (2.11.0)
* rspec-core (2.11.0)
* rspec-expectations (2.11.1)
* rspec-mocks (2.11.1)
* rspec-rails (2.11.0)
One thing I've noted in your spec is that in the outermost describe you
pass a string. If I do that, rspec complains about uninitialized
`@controller`; if I move the spec in `spec/` dir (actually it's in
`spec/controllers/`), the `post` method isn't found @_@
What's wrong with me? ._.