2013-07-20 36 views
1

我跟随本教程: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)>' 

怎么了?

+0

我认为,你是在一个文件中创建视图和控制器代码。 –

+0

你是什么意思?正如我所说,他们在单独的文件中。 – Phil

+0

不知道为什么这不起作用,但与教程源相比,您应该使用控制器实例变量'@ task'而不是'Task.new'来表示这种形式 –

回答

-1

我不确定,但那些应该是你的控制器中的“if”语句吗?因为你把它们写成“它”。

+0

更改为“if”似乎使情况变得更糟。根据教程,它应该是“它”。 – Phil

+1

这是一个规范,而不是控制器,所以它使用rspec风格的“描述”语法 –

+0

Doh!对不起,匆忙。应该给予更多的关注。我很抱歉! –