public
Description: Rails plugin providing Test::Unit macros for controller and model testing
Clone URL: git://github.com/vigetlabs/tester_xtreme.git
commit  8c155f6ad013191b7402e8474af87c330f1b3ab4
tree    69bc07cd6e1ca2aa9efa29f7d9a75c3d7c5262f7
parent  439b33448adddabc95c0126a93a80cbc56b1049a
tester_xtreme / README
100644 131 lines (78 sloc) 3.388 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
= TesterXtreme
 
The Tester Xtreme plugin is a way to distill common testing patterns into easy-to-use macros that
are added as class methods to your test cases. There are currently macros for both unit (ActiveRecord
model) and functional (ActionController controllers) tests.
 
== Unit Test Macros
 
=== Validation Tests
 
Each of the validation testing macros checks to make sure there is an appropriate validation method
defined in the model for each attribute specified.
 
*should_require*
 
Ensures that +validates_presence_of+ was used.
 
*should_require_numeric*
 
Ensures that +validates_numericality_of+ was used.
 
*should_require_unique*
 
Ensures that +validates_uniqueness_of+ was used.
 
*should_protect*
 
Ensures that +attr_protected+ was used for this attribute.
 
*Usage*:
 
  class UserTest < ActiveSupport::TestCase
    should_require :first_name, :last_name
    should_require_unique :username
    should_require_numeric :friends_count
    should_protect :hashed_password
  end
 
=== Association Tests
 
Each of the association testing macros checks to make sure the correct associations were defined on
this model. The names map directly to the association definitions:
 
*should_have_many*
 
Ensures that +has_many+ was used.
 
*should_belong_to*
 
Ensures that +belongs_to+ was used.
 
*should_have_one*
 
Ensures that +has_one+ was used.
 
*should_have_and_belong_to_many*
 
Ensures that +has_and_belongs_to_many+ was used.
 
*Usage*:
 
  class UserTest < ActiveSupport::TestCase
    should_have_many :friends
    should_belong_to :organization
    should_have_one :credit_card
    should_have_and_belong_to_many :categories
  end
 
== Functional Test Macros
 
Each of the functional testing macros require that you first request an action on the controller. To
accomplish this, the 4 standard actions are implemented as class methods for the test:
 
* get
* post
* put
* delete
 
In addition to simple requests, you can also specify parameters and initial states:
 
  get(:show){ User.expects(:find).returns(mocked_user) }.with(:id => 1)
  post(:create).with(:username => 'foobar')
 
From here, you can use the macros to define certain expectations on the controller:
 
*should_assign*
 
Asserts that the specified variable is set as an instance variable.
 
*should_not_assign*
 
Asserts that the specified variable is *not* set as an instance variable.
 
*should_use_filter*
 
Asserts that the designated filter method is run.
 
*should_not_use_filter*
 
Asserts that the designated filter method is *not* run.
 
*should_render*
 
Asserts that the response for the action is successful and that the specified template is rendered.
 
*should_set_flash*
 
Asserts that the specified key and value was set in the flash collection.
 
*should_set_session*
 
Asserts that the specified variable was set in session.
 
*should_redirect_to*
 
Asserts that the response was a redirect and that the action redirects to the specified route.
 
*Usage*:
 
  class UsersController < ActionController::TestCase
    get(:new).should_render(:new)
    post(:create).with(:username => 'foo').should_redirect_to(:new_user_url)
    delete(:destroy).should_set_flash(:notice, 'You must log in')
    get(:show).with(:id => 1).should_use_filter(:check_for_current_user)
    get(:show).with({:id => 1}, {:user_id => 3}).should_assign(:current_user)
  end
 
= Credits
 
Copyright (c) 2007 Ben Scofield, released under the MIT license