I’m working on this tutorial(time is 33:55): http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/
While what is shown at localhost:3000 is correct and functions properly, I’m still getting an rspec error. Thanks for any suggestions!
Ruby 1.9.2p290
Rails 3.2.3
RSpec 2.11.0
Error:
Running: spec/requests/tasks_spec.rb spec/controllers/tasks_controller_spec.rb
..F.
Failures:
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:
require ‘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
end
end
I believe that by doing this assignment…
…you created a new variable called ‘current_path’ which overwrote capybara’s.
The moral of the story is don’t assign to ‘current_path’