无法找到Field Rails TDD

时间:2013-07-20 23:55:59

标签: html ruby-on-rails ruby erb guard

我正在关注本教程:http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/我遇到了问题。我在views / tasks / index.html.erb

下创建了这个表单
<%= form_for Task.new do |f| %>
    <%= f.label :task %>
    <%= f.text_field :task %>
    <%= f.submit %>
<% end %>

然后在spec / controllers / tasks_controller_spec.rb中我有

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

当我用Guard运行时,我发现了这个失败:

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)>'

怎么了?

1 个答案:

答案 0 :(得分:-1)

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