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.rbspec/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)>
       '

tasks_controller.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

この任務を遂行することで...

current_path = edit_task_path(@タスク)

...カピバラを上書きする「current_path」という新しい変数を作成しました。

ストーリーの教訓は、「current_path」に割り当てないことです

于 2012-07-18T11:19:27.387 に答える