0

我正在编写本教程(时间是 33:55): http: //net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/

虽然 localhost:3000 显示的内容正确且功能正常,但我仍然收到 rspec 错误。感谢您的任何建议!

Ruby 1.9.2p290 Rails 3.2.3 RSpec 2.11.0

错误:运行:spec/requests/tasks_spec.rb spec/controllers/tasks_controller_spec.rb ..F。

失败:

   1) Tasks PUT/tasks edits a task
       Failure/Error: current_path.should == tasks_path
        expected: "/tasks"
           got: "/tasks/1/edit" (using ==)
       # ./spec/requests/tasks_spec.rb:40:in `block (3 levels) in <top (required)>
       '

任务控制器.rb:

     class TasksController < ApplicationController
        def index
         @task = Task.new
         @tasks = Task.all
        end

        def create
          Task.create params[:task]
          redirect_to :back
        end

        def edit
          @task = Task.find params[:id]
        end

        def update
          task = Task.find params[:id]
            if task.update_attributes params[:task]
              redirect_to tasks_path
            else
              redirect_to :back
            end
        end

       end

tasks_spec.rb:

需要'spec_helper'

 describe "Tasks" do
    before do
    @task = Task.create :task => 'go to bed'
end

describe "GET /tasks" do
    it "display some tasks" do

       visit tasks_path
       page.should have_content 'go to bed'
    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  

describe "PUT/tasks" do
    it "edits a task" do
        visit tasks_path
        click_link 'Edit'

        current_path = edit_task_path(@task)

        #page.should have_content 'go to bed'
        find_field('Task').value.should == 'go to bed'

        fill_in 'Task', :with => 'updated task'
        click_button 'Update Task'

        current_path.should == tasks_path

        page.should have_content 'updated task'
    end

结束结束

4

1 回答 1

0

我相信通过完成这个任务...

当前路径 = 编辑任务路径(@task)

...您创建了一个名为“current_path”的新变量,它覆盖了水豚的。

故事的寓意是不要分配给'current_path'

于 2012-07-18T11:19:27.387 回答