SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 90 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

They??™re usually written
at a higher level than unit tests, because the functionality of models is a part of the functioning
of the controllers. The best way to see how to write simple functional tests is to generate a scaffold
controller and read the code for the generated functional test. As you can see in Listing 3-1,
the language is high level, and looks more like a DSL for testing than regular Ruby code.
CHAPTER 3 ?–  INTRODUCTION TO RAILS 33
Listing 3-1. Parts of Functional Test Code for a User Controller
class UsersControllerTest < Test::Unit::TestCase
fixtures :users
def setup
@controller = UsersController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_index
get :index
assert_response :success
assert_template 'list'
end
def test_list
get :list
assert_response :success
assert_template 'list'
assert_not_nil assigns(:users)
end
def test_show
get :show, :id => 1
assert_response :success
assert_template 'show'
assert_not_nil assigns(:user)
assert assigns(:user).valid?
end
def test_new
get :new
assert_response :success
assert_template 'new'
assert_not_nil assigns(:user)
end
end
CHAPTER 3 ?–  INTRODUCTION TO RAILS 34
Integration tests, finally, are even higher than functional tests. The purpose is to test the
flow through an application. As such, this kind of testing uses operations that resemble the
actions that a user will execute while using the application, rather than going behind the
covers, on the bare metal, like functional and unit tests.


Pages:
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102