I’m working on testing my login page via rspec using this script
describe "Sessions" do
describe "GET /sessions/new" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
post "/session/new", { :username => "user", :password => "pass" }
response.should redirect_to("/dashboard")
end
end
end
When I try this, rspec says that:
ActionController::RoutingError:
No route matches [POST] "/session/new"
But I know for a fact that /session/new is a valid route. Also, if I just try what is generated as the default i.e get "sessions/new" instead of post or post_via_redirect without trying to test a username and password, it works fine. So basically, I’m just trying to test the login page where a user would post his username and password. Is there something I’m missing here?
if you are using restful route, ‘/sessions/new’ should only response GET request. This URL is used to give a form to user to submit.
You should POST to “/sessions” instead