genspec 0.1.1 → 0.2.0.prerails3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/README.rdoc +79 -31
  2. data/Rakefile +69 -22
  3. data/VERSION +1 -1
  4. data/genspec.gemspec +31 -40
  5. data/lib/gen_spec.rb +1 -0
  6. data/lib/genspec.rb +23 -8
  7. data/lib/genspec/generator_example_group.rb +47 -52
  8. data/lib/genspec/matchers.rb +59 -0
  9. data/lib/genspec/matchers/base.rb +148 -0
  10. data/lib/genspec/matchers/generation_method_matcher.rb +88 -0
  11. data/lib/genspec/matchers/output_matcher.rb +34 -0
  12. data/lib/genspec/matchers/result_matcher.rb +28 -0
  13. data/lib/genspec/shell.rb +99 -0
  14. data/pkg/genspec-0.1.1.gem +0 -0
  15. data/pkg/genspec-0.2.0.pre1.gem +0 -0
  16. data/pkg/genspec-0.2.0.prerails3.1.gem +0 -0
  17. data/spec/generators/test_rails3_spec.rb +74 -0
  18. data/spec/rcov.opts +2 -0
  19. data/spec/rspec.opts +2 -0
  20. data/spec/spec_helper.rb +10 -3
  21. data/spec/support/generators/test_rails3/USAGE +8 -0
  22. data/spec/support/generators/{test → test_rails3}/templates/file +0 -0
  23. data/spec/support/generators/test_rails3/test_rails3_generator.rb +23 -0
  24. metadata +48 -40
  25. data/lib/genspec/generation_matchers.rb +0 -27
  26. data/lib/genspec/generation_matchers/generation_matcher.rb +0 -147
  27. data/lib/genspec/generation_matchers/result_matcher.rb +0 -42
  28. data/pkg/genspec-0.0.0.gem +0 -0
  29. data/pkg/genspec-0.1.0.gem +0 -0
  30. data/rdoc/classes/GenSpec.html +0 -124
  31. data/rdoc/classes/GenSpec/GenerationMatchers.html +0 -197
  32. data/rdoc/classes/GenSpec/GenerationMatchers/GenerationMatcher.html +0 -363
  33. data/rdoc/classes/GenSpec/GenerationMatchers/ResultMatcher.html +0 -241
  34. data/rdoc/classes/GenSpec/GeneratorExampleGroup.html +0 -285
  35. data/rdoc/created.rid +0 -1
  36. data/rdoc/files/README_rdoc.html +0 -261
  37. data/rdoc/files/lib/genspec/generation_matchers/generation_matcher_rb.html +0 -101
  38. data/rdoc/files/lib/genspec/generation_matchers/result_matcher_rb.html +0 -101
  39. data/rdoc/files/lib/genspec/generation_matchers_rb.html +0 -109
  40. data/rdoc/files/lib/genspec/generator_example_group_rb.html +0 -101
  41. data/rdoc/files/lib/genspec_rb.html +0 -114
  42. data/rdoc/fr_class_index.html +0 -31
  43. data/rdoc/fr_file_index.html +0 -32
  44. data/rdoc/fr_method_index.html +0 -46
  45. data/rdoc/index.html +0 -26
  46. data/rdoc/rdoc-style.css +0 -208
  47. data/spec/generators/test_spec.rb +0 -96
  48. data/spec/support/generators/test/test_generator.rb +0 -29
data/rdoc/created.rid DELETED
@@ -1 +0,0 @@
1
- Mon, 21 Jun 2010 11:00:58 -0400
@@ -1,261 +0,0 @@
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>
@@ -1,101 +0,0 @@
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>
@@ -1,101 +0,0 @@
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>