Skip to content

Instantly share code, notes, and snippets.

@uhlenbrock
Created September 23, 2008 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhlenbrock/12403 to your computer and use it in GitHub Desktop.
Save uhlenbrock/12403 to your computer and use it in GitHub Desktop.
Sample Functional Tests
class UsersController < ActionController::Base
before_filter :login_required
def show
@user = User.find(params[:id])
end
end
context "The User profile page (logged out)", ActionController::TestCase do
tests UsersController
setup do
@quentin = users(:quentin)
get :show, { :id => @quentin.id }
end
# Redirect specification
specify "should require login" do
response.should.be.redirected
response.should.redirect_to login_url
end
end
context "The User profile page (logged in)", ActionController::TestCase do
tests UsersController
setup do
@quentin = users(:quentin)
login_as @quentin
get :show, { :id => @quentin.id }
end
# Success specification
specify "displays details about the user" do
status.should.be :success
template.should.be 'users/show'
layout.should.be 'application'
url.should.be "/users/#{@quentin.id}"
assigns(:user).should.not.be.blank
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment