1

我正在关注本教程: 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)>'

怎么了?

4

1 回答 1

-1

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

于 2013-07-21T01:35:45.250 回答