我跟随本教程:http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/,我遇到问题。我在规格/控制器/ tasks_controller_spec.rb下创建的意见/任务/ index.html.erb这种形式无法找到现场导轨TDD
<%= form_for Task.new do |f| %>
<%= f.label :task %>
<%= f.text_field :task %>
<%= f.submit %>
<% end %>
然后,我有
require 'spec_helper'
describe TasksController do
describe "GET 'index'" do
it "returns http success" do
@task = Task.create :task => 'go to bed'
get 'index'
response.should be_success
end
it "creates a new task" do
visit tasks_path
fill_in 'Task', :with => 'go to work'
click_button 'Create Task'
current_path.should == tasks_path
page.should have_content 'go to work'
save_and_open_page
end
end
end
当我运行与保护,我得到这个故障:
Failures:
1) TasksController GET 'index' creates a new task
Failure/Error: fill_in 'Task', :with => 'go to work'
Capybara::ElementNotFound:
Unable to find field "Task"
# ./spec/controllers/tasks_controller_spec.rb:15:in `block (3 levels) in <top (required)>'
怎么了?
我认为,你是在一个文件中创建视图和控制器代码。 –
你是什么意思?正如我所说,他们在单独的文件中。 – Phil
不知道为什么这不起作用,但与教程源相比,您应该使用控制器实例变量'@ task'而不是'Task.new'来表示这种形式 –