public
Description: Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application
Homepage: http://www.pluginaweek.org
Clone URL: git://github.com/pluginaweek/plugin_test_helper.git
100644 195 lines (136 sloc) 7.11 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
= plugin_test_helper
 
+plugin_test_helper+ simplifies plugin testing by creating an isolated Rails
environment that simulates its usage in a real application.
 
== Resources
 
Wiki
 
* http://wiki.pluginaweek.org/Plugin_test_helper
 
API
 
* http://api.pluginaweek.org/plugin_test_helper
 
Development
 
* http://dev.pluginaweek.org/browser/trunk/plugin_test_helper
 
Source
 
* http://svn.pluginaweek.org/trunk/plugin_test_helper
 
== Description
 
Plugins often need to initialize a full Rails environment, whether it be for
accessing a database or simulating controller access. Traditionally, this has
been done by just loading the application that the plugin was added to.
However, this can cause all sorts of environment variables to change, making it
seem as though the plugin is having problems when it may be something else. It
also means that the plugin cannot be tested individually.
 
+plugin_test_helper+ helps solve this problem by allowing plugins to create their
own basic Rails environment with the ability to override any part of it, be it
the database configuration, environment configuration, or adding models,
controllers, helpers, etc. The following testing structure is assumed:
 
  your_plugin/
  your_plugin/test
  your_plugin/test/app_root
  your_plugin/test/app_root/app
  your_plugin/test/app_root/config
  your_plugin/test/app_root/db
  etc.
 
The +app_root+ directory is just like your run-of-the-mill Rails application. It
can contain the same directories as your full application.
 
To help generate the various parts of your test application, the following
generators are available:
* plugin_test_helper
* plugin_test_structure
* plugin_test_model
* plugin_test_controller
* plugin_test_migration
 
*NOTE* that you <b>DO NOT</b> need to generate the entire application structure. All
that is required is that your test helper load plugin_test_helper. If you do
not define a part of the test application (such as the environment
configurations or the database configuration), then it will use the existing
implementation in <tt>plugin_test_helper/generators/plugin_test_structure/templates</tt>.
*However*, you can override any of these files by simply defining them in your
plugin, using the same directory structure.
 
== Usage
 
=== plugin_test_helper
 
Generates a test helper file that should be required by all unit/functional/integration
tests in your plugin.
 
Example:
 
  $ ruby script/generate plugin_test_helper acts_as_most_popular
        create vendor/plugins/acts_as_most_popular/test/test_helper.rb
  Loaded suite script/generate
  Started
  
  Finished in 0.000439 seconds.
  
  0 tests, 0 assertions, 0 failures, 0 errors
 
=== plugin_test_structure
 
Generates the entire test application structure. If you keep all files within
your plugin, then you will not need to depend on the +plugin_test_helper+ plugin
when testing it.
 
Example:
 
  $ ruby script/generate plugin_test_structure acts_as_most_popular
        create vendor/plugins/acts_as_most_popular/test/app_root
        create vendor/plugins/acts_as_most_popular/test/app_root/config
        create vendor/plugins/acts_as_most_popular/test/app_root/app
        create vendor/plugins/acts_as_most_popular/test/app_root/lib
        create vendor/plugins/acts_as_most_popular/test/app_root/config/environments
        create vendor/plugins/acts_as_most_popular/test/app_root/config/routes.rb
        create vendor/plugins/acts_as_most_popular/test/app_root/config/boot.rb
        create vendor/plugins/acts_as_most_popular/test/app_root/config/environment.rb
        create vendor/plugins/acts_as_most_popular/test/app_root/config/database.yml
        create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/sqlite.rb
        create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/sqlite3.rb
        create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/mysql.rb
        create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/in_memory.rb
        create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/postgresql.rb
        create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers
        create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/application.rb
  Loaded suite script/generate
  Started
  
  Finished in 0.000548 seconds.
  
  0 tests, 0 assertions, 0 failures, 0 errors
 
=== plugin_test_model
 
Generates a model within your plugin's test application. This uses a similar
syntax to that of the Rails model generator.
 
Example:
 
  $ ruby script/generate plugin_test_model acts_as_most_popular Person
        create vendor/plugins/acts_as_most_popular/test/app_root/app/models/
        create vendor/plugins/acts_as_most_popular/test/app_root/test/fixtures/
        create vendor/plugins/acts_as_most_popular/test/app_root/app/models/person.rb
        create vendor/plugins/acts_as_most_popular/test/app_root/test/fixtures/people.yml
        create vendor/plugins/acts_as_most_popular/test/app_root/db/migrate
        create vendor/plugins/acts_as_most_popular/test/app_root/db/migrate/001_create_people.rb
  Loaded suite script/generate
  Started
  
  Finished in 0.000435 seconds.
  
  0 tests, 0 assertions, 0 failures, 0 errors
 
=== plugin_test_controller
 
Generates a controller within your plugin's test application. This uses a similar
syntax to that of the Rails controller generator.
 
Example:
 
  $ ruby script/generate plugin_test_controller acts_as_most_popular Person
        create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/
        create vendor/plugins/acts_as_most_popular/test/app_root/app/views/person
        create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/person_controller.rb
  Loaded suite script/generate
  Started
  
  Finished in 0.000432 seconds.
  
  0 tests, 0 assertions, 0 failures, 0 errors
 
=== plugin_test_migration
 
Generates a migration within your plugin's test application. This uses a similar
syntax to that of the Rails migration generator.
 
Example:
 
  $ ruby script/generate plugin_test_migration acts_as_most_popular CreatePeople
        create vendor/plugins/acts_as_most_popular/test/app_root/db/migrate
        create vendor/plugins/acts_as_most_popular/test/app_root/db/migrate/001_create_people.rb
  Loaded suite script/generate
  Started
  
  Finished in 0.000443 seconds.
  
  0 tests, 0 assertions, 0 failures, 0 errors
 
=== plugin_test_console
 
Generates a script for running an interactive console with your plugin's test
application.
 
Example:
 
  $ ruby script/generate plugin_test_console acts_as_most_popular
        create vendor/plugins/acts_as_most_popular/test/app_root/../../script
        create vendor/plugins/acts_as_most_popular/test/app_root/../../script/console
  Loaded suite script/generate
  Started
  
  Finished in 0.000267 seconds.
  
  0 tests, 0 assertions, 0 failures, 0 errors
 
== Dependencies
 
Rails 2.1 or later
 
== References
 
* {Mark Meves}[http://rationalexuberance.org] for the initial implementation