genspec 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +122 -0
  3. data/Rakefile +55 -0
  4. data/VERSION +1 -0
  5. data/genspec.gemspec +83 -0
  6. data/lib/genspec.rb +14 -0
  7. data/lib/genspec/generation_matchers.rb +27 -0
  8. data/lib/genspec/generation_matchers/generation_matcher.rb +147 -0
  9. data/lib/genspec/generation_matchers/result_matcher.rb +42 -0
  10. data/lib/genspec/generator_example_group.rb +71 -0
  11. data/pkg/genspec-0.0.0.gem +0 -0
  12. data/pkg/genspec-0.1.0.gem +0 -0
  13. data/rdoc/classes/GenSpec.html +124 -0
  14. data/rdoc/classes/GenSpec/GenerationMatchers.html +197 -0
  15. data/rdoc/classes/GenSpec/GenerationMatchers/GenerationMatcher.html +363 -0
  16. data/rdoc/classes/GenSpec/GenerationMatchers/ResultMatcher.html +241 -0
  17. data/rdoc/classes/GenSpec/GeneratorExampleGroup.html +285 -0
  18. data/rdoc/created.rid +1 -0
  19. data/rdoc/files/README_rdoc.html +261 -0
  20. data/rdoc/files/lib/genspec/generation_matchers/generation_matcher_rb.html +101 -0
  21. data/rdoc/files/lib/genspec/generation_matchers/result_matcher_rb.html +101 -0
  22. data/rdoc/files/lib/genspec/generation_matchers_rb.html +109 -0
  23. data/rdoc/files/lib/genspec/generator_example_group_rb.html +101 -0
  24. data/rdoc/files/lib/genspec_rb.html +114 -0
  25. data/rdoc/fr_class_index.html +31 -0
  26. data/rdoc/fr_file_index.html +32 -0
  27. data/rdoc/fr_method_index.html +46 -0
  28. data/rdoc/index.html +26 -0
  29. data/rdoc/rdoc-style.css +208 -0
  30. data/spec/environment_spec.rb +18 -0
  31. data/spec/generators/test_spec.rb +96 -0
  32. data/spec/spec_helper.rb +4 -0
  33. data/spec/support/generators/test/templates/file +1 -0
  34. data/spec/support/generators/test/test_generator.rb +29 -0
  35. metadata +124 -0
data/rdoc/created.rid ADDED
@@ -0,0 +1 @@
1
+ Mon, 21 Jun 2010 11:00:58 -0400
@@ -0,0 +1,261 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: README.rdoc</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>README.rdoc</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>README.rdoc
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Mon Jun 21 11:00:57 -0400 2010</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+ <div id="description">
72
+ <h1>genspec</h1>
73
+ <p>
74
+ Simple, expressive Rails generator testing for RSpec.
75
+ </p>
76
+ <h2>Installation</h2>
77
+ <pre>
78
+ sudo gem install genspec
79
+ </pre>
80
+ <p>
81
+ &#8230;then, in your config/environments/test.rb&#8230;
82
+ </p>
83
+ <pre>
84
+ config.gem 'genspec'
85
+ </pre>
86
+ <h2>Usage</h2>
87
+ <p>
88
+ Just like rspec-rails uses the structure of your spec/ directory to infer
89
+ which test is being run (controllers, helpers, lib, etc.), you just need to
90
+ create a spec/generators directory and put your generator specs in there. A
91
+ basic generator spec might look something like this:
92
+ </p>
93
+ <pre>
94
+ # in spec/generators/custom_controller_spec.rb
95
+ require 'spec_helper'
96
+
97
+ describe :custom_controller do
98
+ context &quot;with no arguments or options&quot; do
99
+ it &quot;should generate a help message&quot; do
100
+ subject.should output(&quot;A Help Message&quot;)
101
+ end
102
+ end
103
+
104
+ context &quot;with a name argument&quot; do
105
+ with_args :users
106
+
107
+ it &quot;should generate a UsersController&quot; do
108
+ subject.should generate(&quot;app/controllers/users_controller.rb&quot;)
109
+ end
110
+ end
111
+ end
112
+ </pre>
113
+ <h3>Checking for Output</h3>
114
+ <p>
115
+ If you need to test the generator&#8216;s feedback rather than the
116
+ generator&#8216;s results, you can use the <em>output</em> matcher to
117
+ assert that your generator has produced some specific content in its output
118
+ (which would be either a logger of some sort or $stdout). This is helpful
119
+ for making sure your help message is accurate, for instance.
120
+ </p>
121
+ <pre>
122
+ # Ex 1: String
123
+ it &quot;should generate a help message&quot; do
124
+ subject.should output(&quot;A Help Message&quot;)
125
+ end
126
+
127
+ # Ex 2: Regular Expression
128
+ it &quot;should generate a help message&quot; do
129
+ subject.should output(/A [hH]elp Message/)
130
+ end
131
+ </pre>
132
+ <h3>Checking Generated Files</h3>
133
+ <p>
134
+ This is the preferred way to test which files were actually generated,
135
+ because this matcher checks your generator&#8216;s <b>behavior</b>. That
136
+ means it won&#8216;t care <em>how</em> a file is generated, as long as it
137
+ <em>is</em> generated. It&#8216;s as simple as passing the name of the file
138
+ you expected to be generated:
139
+ </p>
140
+ <pre>
141
+ it &quot;should generate a readme file&quot; do
142
+ subject.should generate(&quot;README&quot;)
143
+ end
144
+ </pre>
145
+ <p>
146
+ You can also check the generated file&#8216;s content by simply passing a
147
+ block. The argument in the block is the plaintext content of the file:
148
+ </p>
149
+ <pre>
150
+ it &quot;should generate a model called 'user'&quot; do
151
+ subject.should generate(&quot;app/models/user.rb&quot;) { |content|
152
+ content.should =~ /class User &lt; ActiveRecord\:\:Base/
153
+ }
154
+ end
155
+ </pre>
156
+ <h3>Checking Generation Methods</h3>
157
+ <p>
158
+ This is the most intrusive form of generation matching, and should be
159
+ avoided where possible. However, in some cases you just can&#8216;t check
160
+ behavior directly (migrations are a case in point, because the version
161
+ number is unpredictable). In that case, you can verify that a particular
162
+ method is called within the generator&#8216;s manifest like so:
163
+ </p>
164
+ <pre>
165
+ it &quot;should generate a user migration template&quot; do
166
+ subject.should generate(:migration_template, &quot;migration_template.erb&quot;, &quot;db/migrate&quot;, :migration_file =&gt; &quot;create_users&quot;)
167
+ end
168
+ </pre>
169
+ <p>
170
+ You can stop passing arguments at any time. This has the effect of widening
171
+ the range of acceptable parameters. For instance, the following example
172
+ does the same thing but will accept <em>any</em> migration file name in
173
+ <em>any</em> destination directory, as long as the
174
+ &quot;migration_template.erb&quot; file is used for the source:
175
+ </p>
176
+ <pre>
177
+ it &quot;should generate a migration template&quot; do
178
+ subject.should generate(:migration_template, &quot;migration_template.rb&quot;)
179
+ end
180
+ </pre>
181
+ <p>
182
+ Any method that is normally available to Rails generators can be tested in
183
+ this way:
184
+ </p>
185
+ <pre>
186
+ it &quot;should test one of each generation type&quot; do
187
+ subject.should generate(:directory, &quot;db/migrate&quot;)
188
+ subject.should generate(:file, &quot;input_file&quot;, &quot;output_file&quot;)
189
+ subject.should generate(:template, &quot;input_template&quot;, &quot;output_template&quot;)
190
+ subject.should generate(:class_collisions, 'ActionController::Base')
191
+ subject.should generate(:migration_template, &quot;file&quot;, &quot;directory&quot;, :migration_file_name =&gt; &quot;filename&quot;)
192
+ subject.should generate(:resource_routes, 'model_name')
193
+ subject.should generate(:readme, &quot;README&quot;)
194
+ end
195
+ </pre>
196
+ <p>
197
+ But again&#8230; Use these as last resorts, for the most part. Technically,
198
+ you will probably need this for :migration_template and :resource_routes,
199
+ but anything else should really be tested for <em>behavior</em>. Like any
200
+ other class, you should really only care about how the generator interacts
201
+ with other objects &#8212; in this case, your file system &#8212; and not
202
+ so much about what it&#8216;s doing on the inside.
203
+ </p>
204
+ <h2>Note on Patches/Pull Requests</h2>
205
+ <ul>
206
+ <li>Fork the project.
207
+
208
+ </li>
209
+ <li>Make your feature addition or bug fix.
210
+
211
+ </li>
212
+ <li>Add tests for it. This is important so I don&#8216;t break it in a future
213
+ version unintentionally.
214
+
215
+ </li>
216
+ <li>Commit, do not mess with rakefile, version, or history. (if you want to
217
+ have your own version, that is fine but bump version in a commit by itself
218
+ I can ignore when I pull)
219
+
220
+ </li>
221
+ <li>Send me a pull request. Bonus points for topic branches.
222
+
223
+ </li>
224
+ </ul>
225
+ <h2>Copyright</h2>
226
+ <p>
227
+ Copyright (c) 2010 Colin MacKenzie IV. See LICENSE for details.
228
+ </p>
229
+
230
+ </div>
231
+
232
+
233
+ </div>
234
+
235
+
236
+ </div>
237
+
238
+
239
+ <!-- if includes -->
240
+
241
+ <div id="section">
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+ <!-- if method_list -->
251
+
252
+
253
+ </div>
254
+
255
+
256
+ <div id="validator-badges">
257
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
258
+ </div>
259
+
260
+ </body>
261
+ </html>
@@ -0,0 +1,101 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: generation_matcher.rb</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>generation_matcher.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>lib/genspec/generation_matchers/generation_matcher.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Mon Jun 21 06:55:45 -0400 2010</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+
72
+
73
+ </div>
74
+
75
+
76
+ </div>
77
+
78
+
79
+ <!-- if includes -->
80
+
81
+ <div id="section">
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ <!-- if method_list -->
91
+
92
+
93
+ </div>
94
+
95
+
96
+ <div id="validator-badges">
97
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
98
+ </div>
99
+
100
+ </body>
101
+ </html>
@@ -0,0 +1,101 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: result_matcher.rb</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>result_matcher.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>lib/genspec/generation_matchers/result_matcher.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Fri Jun 11 19:09:34 -0400 2010</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+
72
+
73
+ </div>
74
+
75
+
76
+ </div>
77
+
78
+
79
+ <!-- if includes -->
80
+
81
+ <div id="section">
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ <!-- if method_list -->
91
+
92
+
93
+ </div>
94
+
95
+
96
+ <div id="validator-badges">
97
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
98
+ </div>
99
+
100
+ </body>
101
+ </html>