Skip to content

Instantly share code, notes, and snippets.

@nickdenardis
Last active October 13, 2015 11:48
Show Gist options
  • Save nickdenardis/4191366 to your computer and use it in GitHub Desktop.
Save nickdenardis/4191366 to your computer and use it in GitHub Desktop.
rspec tasks example
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 /tasts" 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 == tasks_path
page.should have_content 'Updated Task'
end
it "should not update an empty task" do
visit tasks_path
click_link 'Edit'
fill_in 'Task', :with => ''
click_button 'Update Task'
current_path.should == edit_task_path(@task)
page.should have_content 'There was an error updating your task.'
end
end
describe "DELETE /tasks" do
it "should delete a task" do
visit tasks_path
find("#task_#{@task.id}").click_link 'Delete'
page.should have_content 'Task has been deleted'
page.should have_no_content 'go to bed'
end
end
end
http://robots.thoughtbot.com/post/33771089985/rspec-integration-tests-with-capybara
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment