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.
- data/README.rdoc +79 -31
- data/Rakefile +69 -22
- data/VERSION +1 -1
- data/genspec.gemspec +31 -40
- data/lib/gen_spec.rb +1 -0
- data/lib/genspec.rb +23 -8
- data/lib/genspec/generator_example_group.rb +47 -52
- data/lib/genspec/matchers.rb +59 -0
- data/lib/genspec/matchers/base.rb +148 -0
- data/lib/genspec/matchers/generation_method_matcher.rb +88 -0
- data/lib/genspec/matchers/output_matcher.rb +34 -0
- data/lib/genspec/matchers/result_matcher.rb +28 -0
- data/lib/genspec/shell.rb +99 -0
- data/pkg/genspec-0.1.1.gem +0 -0
- data/pkg/genspec-0.2.0.pre1.gem +0 -0
- data/pkg/genspec-0.2.0.prerails3.1.gem +0 -0
- data/spec/generators/test_rails3_spec.rb +74 -0
- data/spec/rcov.opts +2 -0
- data/spec/rspec.opts +2 -0
- data/spec/spec_helper.rb +10 -3
- data/spec/support/generators/test_rails3/USAGE +8 -0
- data/spec/support/generators/{test → test_rails3}/templates/file +0 -0
- data/spec/support/generators/test_rails3/test_rails3_generator.rb +23 -0
- metadata +48 -40
- data/lib/genspec/generation_matchers.rb +0 -27
- data/lib/genspec/generation_matchers/generation_matcher.rb +0 -147
- data/lib/genspec/generation_matchers/result_matcher.rb +0 -42
- data/pkg/genspec-0.0.0.gem +0 -0
- data/pkg/genspec-0.1.0.gem +0 -0
- data/rdoc/classes/GenSpec.html +0 -124
- data/rdoc/classes/GenSpec/GenerationMatchers.html +0 -197
- data/rdoc/classes/GenSpec/GenerationMatchers/GenerationMatcher.html +0 -363
- data/rdoc/classes/GenSpec/GenerationMatchers/ResultMatcher.html +0 -241
- data/rdoc/classes/GenSpec/GeneratorExampleGroup.html +0 -285
- data/rdoc/created.rid +0 -1
- data/rdoc/files/README_rdoc.html +0 -261
- data/rdoc/files/lib/genspec/generation_matchers/generation_matcher_rb.html +0 -101
- data/rdoc/files/lib/genspec/generation_matchers/result_matcher_rb.html +0 -101
- data/rdoc/files/lib/genspec/generation_matchers_rb.html +0 -109
- data/rdoc/files/lib/genspec/generator_example_group_rb.html +0 -101
- data/rdoc/files/lib/genspec_rb.html +0 -114
- data/rdoc/fr_class_index.html +0 -31
- data/rdoc/fr_file_index.html +0 -32
- data/rdoc/fr_method_index.html +0 -46
- data/rdoc/index.html +0 -26
- data/rdoc/rdoc-style.css +0 -208
- data/spec/generators/test_spec.rb +0 -96
- 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
|
data/rdoc/files/README_rdoc.html
DELETED
@@ -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
|
-
…then, in your config/environments/test.rb…
|
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 "with no arguments or options" do
|
99
|
-
it "should generate a help message" do
|
100
|
-
subject.should output("A Help Message")
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "with a name argument" do
|
105
|
-
with_args :users
|
106
|
-
|
107
|
-
it "should generate a UsersController" do
|
108
|
-
subject.should generate("app/controllers/users_controller.rb")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
</pre>
|
113
|
-
<h3>Checking for Output</h3>
|
114
|
-
<p>
|
115
|
-
If you need to test the generator‘s feedback rather than the
|
116
|
-
generator‘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 "should generate a help message" do
|
124
|
-
subject.should output("A Help Message")
|
125
|
-
end
|
126
|
-
|
127
|
-
# Ex 2: Regular Expression
|
128
|
-
it "should generate a help message" 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‘s <b>behavior</b>. That
|
136
|
-
means it won‘t care <em>how</em> a file is generated, as long as it
|
137
|
-
<em>is</em> generated. It‘s as simple as passing the name of the file
|
138
|
-
you expected to be generated:
|
139
|
-
</p>
|
140
|
-
<pre>
|
141
|
-
it "should generate a readme file" do
|
142
|
-
subject.should generate("README")
|
143
|
-
end
|
144
|
-
</pre>
|
145
|
-
<p>
|
146
|
-
You can also check the generated file‘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 "should generate a model called 'user'" do
|
151
|
-
subject.should generate("app/models/user.rb") { |content|
|
152
|
-
content.should =~ /class User < 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‘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‘s manifest like so:
|
163
|
-
</p>
|
164
|
-
<pre>
|
165
|
-
it "should generate a user migration template" do
|
166
|
-
subject.should generate(:migration_template, "migration_template.erb", "db/migrate", :migration_file => "create_users")
|
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
|
-
"migration_template.erb" file is used for the source:
|
175
|
-
</p>
|
176
|
-
<pre>
|
177
|
-
it "should generate a migration template" do
|
178
|
-
subject.should generate(:migration_template, "migration_template.rb")
|
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 "should test one of each generation type" do
|
187
|
-
subject.should generate(:directory, "db/migrate")
|
188
|
-
subject.should generate(:file, "input_file", "output_file")
|
189
|
-
subject.should generate(:template, "input_template", "output_template")
|
190
|
-
subject.should generate(:class_collisions, 'ActionController::Base')
|
191
|
-
subject.should generate(:migration_template, "file", "directory", :migration_file_name => "filename")
|
192
|
-
subject.should generate(:resource_routes, 'model_name')
|
193
|
-
subject.should generate(:readme, "README")
|
194
|
-
end
|
195
|
-
</pre>
|
196
|
-
<p>
|
197
|
-
But again… 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 — in this case, your file system — and not
|
202
|
-
so much about what it‘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‘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>
|