0

我工作的這個教程(時間爲33:55):http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/規格故障/錯誤:current_path.should == tasks_path

雖然什麼是本地主機顯示:3000是正確的和功能正常,我m仍然收到rspec錯誤。感謝您的任何建議!

紅寶石1.9.2p290 的Rails 3.2.3 RSpec的2.11.0

錯誤: 運行:規格/請求/ tasks_spec.rb規格/控制器/ 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 

端 端

回答

0

我相信,通過這樣的作業...

current_path = edit_task_path(@task)

...你創建了一個名爲「的current_path」,這改寫水豚的新變量。

這個故事的寓意是不分配給「的current_path」

+0

的感謝!我在「編輯任務」塊中註釋了這一行,它修復了我正在收到的測試失敗。非常感激! – stevenaq 2012-07-18 16:49:20