Created
June 26, 2013 15:14
-
-
Save HoyaBoya/5868282 to your computer and use it in GitHub Desktop.
Remembering functional testing in Rails....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Welcome#index</h1> | |
<p>Find me in app/views/welcome/index.html.erb</p> | |
<p>Hello <%= @first_name %> <%= @last_name %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WelcomeController < ApplicationController | |
def index | |
@first_name = params[:first_name] | |
@last_name = params[:last_name] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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