为什么我的测试:
feature "Manage todos" do
scenario "create a new todo" do
visit root_path
fill_in 'Email address', with: 'junk@snap2web.com'
click_button 'Sign in'
click_link('Add a new todo')
fill_in 'Description', with: 'Buy some milk'
click_button 'Create todo'
expect(page).to have_css 'li.todo', text: 'Buy some Milk'
end
end
错误:
1) Manage todos create a new todo
Failure/Error: click_button 'Create todo'
ActionController::RoutingError:
No route matches [POST] "/todos/new"
当我的路线有:
Todos::Application.routes.draw do
root 'high_voltage/pages#show', id: 'homepage'
resource :session, only: [:create]
resources :todos
end
和耙路线显示:
Prefix Verb URI Pattern Controller#Action
root GET / high_voltage/pages#show {:id=>"homepage"}
session POST /session(.:format) sessions#create
todos GET /todos(.:format) todos#index
POST /todos(.:format) todos#create
new_todo GET /todos/new(.:format) todos#new
edit_todo GET /todos/:id/edit(.:format) todos#edit
todo GET /todos/:id(.:format) todos#show
PATCH /todos/:id(.:format) todos#update
PUT /todos/:id(.:format) todos#update
DELETE /todos/:id(.:format) todos#destroy
page GET /pages/*id high_voltage/pages#show
我的控制器有:
$ cat app/controllers/todos_controller.rb
class TodosController < ApplicationController
def index
end
def new
end
end
表格有:
$ cat app/views/todos/new.html.erb
Add a new todo
<%= form_for :todo do |f| %>
<%= f.label :description %>
<%= f.text_field :description %>
<%= f.submit 'Create todo' %>
<% end %>