Skip to content

Instantly share code, notes, and snippets.

@HoyaBoya
Created June 26, 2013 15:14
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 HoyaBoya/5868282 to your computer and use it in GitHub Desktop.
Save HoyaBoya/5868282 to your computer and use it in GitHub Desktop.
Remembering functional testing in Rails....
<h1>Welcome#index</h1>
<p>Find me in app/views/welcome/index.html.erb</p>
<p>Hello <%= @first_name %> <%= @last_name %></p>
class WelcomeController < ApplicationController
def index
@first_name = params[:first_name]
@last_name = params[:last_name]
end
end
require 'test_helper'
require 'hpricot'
class WelcomeControllerTest < ActionController::TestCase
test "should get index" do
# pass a first name and last name
get :index, {first_name: 'Chris', last_name: 'S'}
# expect HTTP OK
assert_response :success, 'Expected HTTP 200'
# expect instance variable assignment
assert_not_nil assigns(:first_name), 'Expected first name to be set'
assert_not_nil assigns(:last_name), 'Expected last name to be set'
# parse the response with hpricot and insure the markup was ok
doc = Hpricot.parse(@response.body)
assert_equal 'Hello Chris S', (doc/:p).last.to_plain_text.strip, 'Expected Hello Chris S'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment