quicktest 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +75 -0
- data/bin/quickspec +3 -0
- data/doc/created.rid +1 -0
- data/doc/fr_class_index.html +26 -0
- data/doc/fr_file_index.html +27 -0
- data/doc/fr_method_index.html +26 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/quicktest.rb +154 -0
- data/pkg/quicktest-0.0.1.gem +0 -0
- data/pkg/quicktest-0.0.2.gem +0 -0
- data/pkg/quicktest-0.0.3.gem +0 -0
- data/pkg/quicktest-0.0.4.gem +0 -0
- data/pkg/quicktest-0.0.5.gem +0 -0
- data/pkg/quicktest-0.0.6.gem +0 -0
- data/pkg/quicktest-0.0.7.gem +0 -0
- data/pkg/quicktest-0.0.8.gem +0 -0
- data/rakefile +43 -0
- data/test/test.rb +87 -0
- data/test/test_result.txt +69 -0
- metadata +73 -0
data/README
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
== Author and License
|
3
|
+
Copyright (c) 2008 Greg Weber, http://gregweber.info
|
4
|
+
Licensed under the MIT license
|
5
|
+
|
6
|
+
== ABOUT
|
7
|
+
Quicktest - A utility for inlining ruby unit tests with the ruby code under test
|
8
|
+
|
9
|
+
The typical test driven development workflow requires constant switching between the file containg the source code and the the file containg the tests. When creating code, it is much faster to be able to place tests immediately after the code you are writing. After the code has been written, it may be a good idea to move it to another file.
|
10
|
+
|
11
|
+
Quicktest is designed to support quick tests in a framework agnostic way. Currently, only an rspec testrunner is available, but it is trivial to write one for another testing framework.
|
12
|
+
|
13
|
+
== FEATURES
|
14
|
+
Quicktest uses method tracing to know the method you are testing. By default the output of a failed test will show the object and method name.
|
15
|
+
|
16
|
+
== USAGE
|
17
|
+
To test a method, place another method called 'quicktest' immediately after it
|
18
|
+
the quicktest method has two OPTIONAL arguments
|
19
|
+
- the test runner object
|
20
|
+
- a reference to self
|
21
|
+
- a method object for the method under test
|
22
|
+
|
23
|
+
run with spec -r quicktest file_to_test
|
24
|
+
|
25
|
+
There is a convenience script so that you can just run
|
26
|
+
|
27
|
+
quickspec file_to_test
|
28
|
+
|
29
|
+
== NOTES
|
30
|
+
- leaving test code in with your production code is not necessarily a good idea, but there is almost no runtime overhead to doing so since ruby will not evaluate code in a method until the method is invoked
|
31
|
+
- quicktest instance methods not working properly? if the class (or one of its ancestors) is overriding method tracing than including QuickTest::Tracer will fix it.
|
32
|
+
|
33
|
+
|
34
|
+
example: run with bin/quickspec
|
35
|
+
=end rdoc
|
36
|
+
|
37
|
+
class Foo
|
38
|
+
attr_reader :bar
|
39
|
+
|
40
|
+
def initialize
|
41
|
+
@bar = true
|
42
|
+
end
|
43
|
+
def quicktest t, s
|
44
|
+
t.it "bar should be initialized to true" do
|
45
|
+
s.bar.should == true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.hello arg
|
50
|
+
"hello" + arg
|
51
|
+
end
|
52
|
+
def self.quicktest t, s, meth
|
53
|
+
t.it "should prepend 'hello' to its argument" do
|
54
|
+
meth["world"].should == 'hello world' # error - no space 'helloworld'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
=begin
|
60
|
+
|
61
|
+
Running quicktest on the sourc of this README file outputs the following:
|
62
|
+
.F
|
63
|
+
|
64
|
+
1)
|
65
|
+
'Foo hello should prepend 'hello' to its argument' FAILED
|
66
|
+
expected: "hello world",
|
67
|
+
got: "helloworld" (using ==)
|
68
|
+
./README:22:in `quicktest'
|
69
|
+
/home/greg/quicktest/lib/quicktest.rb:65:in `instance_eval'
|
70
|
+
/home/greg/quicktest/lib/quicktest.rb:65:in `run_tests'
|
71
|
+
|
72
|
+
Finished in 0.008338 seconds
|
73
|
+
|
74
|
+
2 examples, 1 failure
|
75
|
+
=end
|
data/bin/quickspec
ADDED
data/doc/created.rid
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Sun, 24 Feb 2008 23:21:27 -0600
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
3
|
+
<!DOCTYPE html
|
4
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
5
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Classes
|
10
|
+
|
11
|
+
-->
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
|
+
<head>
|
14
|
+
<title>Classes</title>
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
16
|
+
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
17
|
+
<base target="docwin" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="index">
|
21
|
+
<h1 class="section-bar">Classes</h1>
|
22
|
+
<div id="index-entries">
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
3
|
+
<!DOCTYPE html
|
4
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
5
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Files
|
10
|
+
|
11
|
+
-->
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
|
+
<head>
|
14
|
+
<title>Files</title>
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
16
|
+
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
17
|
+
<base target="docwin" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="index">
|
21
|
+
<h1 class="section-bar">Files</h1>
|
22
|
+
<div id="index-entries">
|
23
|
+
<a href="files/README.html">README</a><br />
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
</body>
|
27
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
3
|
+
<!DOCTYPE html
|
4
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
5
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Methods
|
10
|
+
|
11
|
+
-->
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
|
+
<head>
|
14
|
+
<title>Methods</title>
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
16
|
+
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
17
|
+
<base target="docwin" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="index">
|
21
|
+
<h1 class="section-bar">Methods</h1>
|
22
|
+
<div id="index-entries">
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
data/doc/index.html
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
|
5
|
+
|
6
|
+
<!--
|
7
|
+
|
8
|
+
RDoc Documentation
|
9
|
+
|
10
|
+
-->
|
11
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
12
|
+
<head>
|
13
|
+
<title>RDoc Documentation</title>
|
14
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
15
|
+
</head>
|
16
|
+
<frameset rows="20%, 80%">
|
17
|
+
<frameset cols="25%,35%,45%">
|
18
|
+
<frame src="fr_file_index.html" title="Files" name="Files" />
|
19
|
+
<frame src="fr_class_index.html" name="Classes" />
|
20
|
+
<frame src="fr_method_index.html" name="Methods" />
|
21
|
+
</frameset>
|
22
|
+
<frame src="files/README.html" name="docwin" />
|
23
|
+
</frameset>
|
24
|
+
</html>
|
data/doc/rdoc-style.css
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
|
2
|
+
body {
|
3
|
+
font-family: Verdana,Arial,Helvetica,sans-serif;
|
4
|
+
font-size: 90%;
|
5
|
+
margin: 0;
|
6
|
+
margin-left: 40px;
|
7
|
+
padding: 0;
|
8
|
+
background: white;
|
9
|
+
}
|
10
|
+
|
11
|
+
h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
|
12
|
+
h1 { font-size: 150%; }
|
13
|
+
h2,h3,h4 { margin-top: 1em; }
|
14
|
+
|
15
|
+
a { background: #eef; color: #039; text-decoration: none; }
|
16
|
+
a:hover { background: #039; color: #eef; }
|
17
|
+
|
18
|
+
/* Override the base stylesheet's Anchor inside a table cell */
|
19
|
+
td > a {
|
20
|
+
background: transparent;
|
21
|
+
color: #039;
|
22
|
+
text-decoration: none;
|
23
|
+
}
|
24
|
+
|
25
|
+
/* and inside a section title */
|
26
|
+
.section-title > a {
|
27
|
+
background: transparent;
|
28
|
+
color: #eee;
|
29
|
+
text-decoration: none;
|
30
|
+
}
|
31
|
+
|
32
|
+
/* === Structural elements =================================== */
|
33
|
+
|
34
|
+
div#index {
|
35
|
+
margin: 0;
|
36
|
+
margin-left: -40px;
|
37
|
+
padding: 0;
|
38
|
+
font-size: 90%;
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
div#index a {
|
43
|
+
margin-left: 0.7em;
|
44
|
+
}
|
45
|
+
|
46
|
+
div#index .section-bar {
|
47
|
+
margin-left: 0px;
|
48
|
+
padding-left: 0.7em;
|
49
|
+
background: #ccc;
|
50
|
+
font-size: small;
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
div#classHeader, div#fileHeader {
|
55
|
+
width: auto;
|
56
|
+
color: white;
|
57
|
+
padding: 0.5em 1.5em 0.5em 1.5em;
|
58
|
+
margin: 0;
|
59
|
+
margin-left: -40px;
|
60
|
+
border-bottom: 3px solid #006;
|
61
|
+
}
|
62
|
+
|
63
|
+
div#classHeader a, div#fileHeader a {
|
64
|
+
background: inherit;
|
65
|
+
color: white;
|
66
|
+
}
|
67
|
+
|
68
|
+
div#classHeader td, div#fileHeader td {
|
69
|
+
background: inherit;
|
70
|
+
color: white;
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
div#fileHeader {
|
75
|
+
background: #057;
|
76
|
+
}
|
77
|
+
|
78
|
+
div#classHeader {
|
79
|
+
background: #048;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
.class-name-in-header {
|
84
|
+
font-size: 180%;
|
85
|
+
font-weight: bold;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
div#bodyContent {
|
90
|
+
padding: 0 1.5em 0 1.5em;
|
91
|
+
}
|
92
|
+
|
93
|
+
div#description {
|
94
|
+
padding: 0.5em 1.5em;
|
95
|
+
background: #efefef;
|
96
|
+
border: 1px dotted #999;
|
97
|
+
}
|
98
|
+
|
99
|
+
div#description h1,h2,h3,h4,h5,h6 {
|
100
|
+
color: #125;;
|
101
|
+
background: transparent;
|
102
|
+
}
|
103
|
+
|
104
|
+
div#validator-badges {
|
105
|
+
text-align: center;
|
106
|
+
}
|
107
|
+
div#validator-badges img { border: 0; }
|
108
|
+
|
109
|
+
div#copyright {
|
110
|
+
color: #333;
|
111
|
+
background: #efefef;
|
112
|
+
font: 0.75em sans-serif;
|
113
|
+
margin-top: 5em;
|
114
|
+
margin-bottom: 0;
|
115
|
+
padding: 0.5em 2em;
|
116
|
+
}
|
117
|
+
|
118
|
+
|
119
|
+
/* === Classes =================================== */
|
120
|
+
|
121
|
+
table.header-table {
|
122
|
+
color: white;
|
123
|
+
font-size: small;
|
124
|
+
}
|
125
|
+
|
126
|
+
.type-note {
|
127
|
+
font-size: small;
|
128
|
+
color: #DEDEDE;
|
129
|
+
}
|
130
|
+
|
131
|
+
.xxsection-bar {
|
132
|
+
background: #eee;
|
133
|
+
color: #333;
|
134
|
+
padding: 3px;
|
135
|
+
}
|
136
|
+
|
137
|
+
.section-bar {
|
138
|
+
color: #333;
|
139
|
+
border-bottom: 1px solid #999;
|
140
|
+
margin-left: -20px;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
.section-title {
|
145
|
+
background: #79a;
|
146
|
+
color: #eee;
|
147
|
+
padding: 3px;
|
148
|
+
margin-top: 2em;
|
149
|
+
margin-left: -30px;
|
150
|
+
border: 1px solid #999;
|
151
|
+
}
|
152
|
+
|
153
|
+
.top-aligned-row { vertical-align: top }
|
154
|
+
.bottom-aligned-row { vertical-align: bottom }
|
155
|
+
|
156
|
+
/* --- Context section classes ----------------------- */
|
157
|
+
|
158
|
+
.context-row { }
|
159
|
+
.context-item-name { font-family: monospace; font-weight: bold; color: black; }
|
160
|
+
.context-item-value { font-size: small; color: #448; }
|
161
|
+
.context-item-desc { color: #333; padding-left: 2em; }
|
162
|
+
|
163
|
+
/* --- Method classes -------------------------- */
|
164
|
+
.method-detail {
|
165
|
+
background: #efefef;
|
166
|
+
padding: 0;
|
167
|
+
margin-top: 0.5em;
|
168
|
+
margin-bottom: 1em;
|
169
|
+
border: 1px dotted #ccc;
|
170
|
+
}
|
171
|
+
.method-heading {
|
172
|
+
color: black;
|
173
|
+
background: #ccc;
|
174
|
+
border-bottom: 1px solid #666;
|
175
|
+
padding: 0.2em 0.5em 0 0.5em;
|
176
|
+
}
|
177
|
+
.method-signature { color: black; background: inherit; }
|
178
|
+
.method-name { font-weight: bold; }
|
179
|
+
.method-args { font-style: italic; }
|
180
|
+
.method-description { padding: 0 0.5em 0 0.5em; }
|
181
|
+
|
182
|
+
/* --- Source code sections -------------------- */
|
183
|
+
|
184
|
+
a.source-toggle { font-size: 90%; }
|
185
|
+
div.method-source-code {
|
186
|
+
background: #262626;
|
187
|
+
color: #ffdead;
|
188
|
+
margin: 1em;
|
189
|
+
padding: 0.5em;
|
190
|
+
border: 1px dashed #999;
|
191
|
+
overflow: hidden;
|
192
|
+
}
|
193
|
+
|
194
|
+
div.method-source-code pre { color: #ffdead; overflow: hidden; }
|
195
|
+
|
196
|
+
/* --- Ruby keyword styles --------------------- */
|
197
|
+
|
198
|
+
.standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
|
199
|
+
|
200
|
+
.ruby-constant { color: #7fffd4; background: transparent; }
|
201
|
+
.ruby-keyword { color: #00ffff; background: transparent; }
|
202
|
+
.ruby-ivar { color: #eedd82; background: transparent; }
|
203
|
+
.ruby-operator { color: #00ffee; background: transparent; }
|
204
|
+
.ruby-identifier { color: #ffdead; background: transparent; }
|
205
|
+
.ruby-node { color: #ffa07a; background: transparent; }
|
206
|
+
.ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
|
207
|
+
.ruby-regexp { color: #ffa07a; background: transparent; }
|
208
|
+
.ruby-value { color: #7fffd4; background: transparent; }
|
data/lib/quicktest.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
# :main: README
|
2
|
+
module QuickTest
|
3
|
+
# set which class will run the tests
|
4
|
+
def self.runner= runner;
|
5
|
+
@@runner = runner
|
6
|
+
end
|
7
|
+
def self.runner; @@runner end
|
8
|
+
|
9
|
+
# don't record the fact that we add Module.method_added
|
10
|
+
def self.ignore_first_method_added= bool # :nodoc:
|
11
|
+
@@ignore_first_method_added = bool
|
12
|
+
end
|
13
|
+
def self.ignore_first_method_added; # :nodoc:
|
14
|
+
@@ignore_first_method_added
|
15
|
+
end
|
16
|
+
|
17
|
+
# a test runner reusing this implementation should
|
18
|
+
# - inherit from the TestRunnerClass
|
19
|
+
# - call super in its own initialize method
|
20
|
+
# - implement any methods to be publicly available in the quicktest method
|
21
|
+
# - add testing classes to IgnoreMethodAddedClasses
|
22
|
+
# it is possible to write a test runner without re-using this code.
|
23
|
+
# The test runner class to be used is set at the bottom of this file
|
24
|
+
# and can be changed with command line switches
|
25
|
+
class TestRunner
|
26
|
+
IgnoreMethodAddedClasses = []
|
27
|
+
|
28
|
+
@@methods = []
|
29
|
+
def self.methods
|
30
|
+
@@methods
|
31
|
+
end
|
32
|
+
def self.add_method( meth )
|
33
|
+
@@methods.push meth
|
34
|
+
end
|
35
|
+
def self.add_singleton_method( meth )
|
36
|
+
@@methods.push meth
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize tested
|
40
|
+
q = tested.method(:quicktest)
|
41
|
+
case q.arity
|
42
|
+
when 0 then q.call
|
43
|
+
when 1 then q.call self
|
44
|
+
when 2 then q.call self, tested
|
45
|
+
when 3 then q.call self, tested, tested.method(@@methods[-1])
|
46
|
+
else raise ArgumentError, "to many arguments for quicktest method"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# all public instance methods are RSpec method wrappers
|
52
|
+
class RSpecTestRunner < TestRunner
|
53
|
+
IgnoreMethodAddedClasses = [/^Spec/]
|
54
|
+
def initialize tested
|
55
|
+
@tests = Hash.new
|
56
|
+
@tested_self = tested
|
57
|
+
|
58
|
+
super tested
|
59
|
+
run_tests
|
60
|
+
end
|
61
|
+
|
62
|
+
def before( &block ); @before_block = block end
|
63
|
+
def after( &block ); @after_block = block end
|
64
|
+
def it(specification, &block )
|
65
|
+
@tests[(@@methods.pop.to_s << ' ' << specification)] = block
|
66
|
+
@@methods.clear
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def run_tests
|
71
|
+
before_block, after_block = @before_block, @after_block
|
72
|
+
tests = @tests
|
73
|
+
|
74
|
+
describe( @tested_self.to_s ) do
|
75
|
+
before { instance_eval &before_block } if before_block
|
76
|
+
after { instance_eval &after_block } if after_block
|
77
|
+
|
78
|
+
tests.each_pair do |spec, test_block|
|
79
|
+
it( spec ) { instance_eval &test_block}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# if the class under test (or one of its ancestors)
|
86
|
+
# is overriding method tracing then it must include QuickTest::Tracer
|
87
|
+
module Tracer
|
88
|
+
def self.included(into)
|
89
|
+
if into == Class or into == Module # default include in in Module
|
90
|
+
self.tracer_include(into)
|
91
|
+
else
|
92
|
+
self.tracer_include((class<<into;self;end))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# auto-printing of the method name is accomplished by using ruby's tracing hooks
|
97
|
+
def self.tracer_include(meta)
|
98
|
+
meta.module_eval do
|
99
|
+
|
100
|
+
# monkeypatch the two hook methods called on method creation
|
101
|
+
# so they will still be called for any method other than _quicktest_
|
102
|
+
alias_method :__quicktest_singleton_method_added__, :singleton_method_added
|
103
|
+
alias_method :__quicktest_method_added__, :method_added
|
104
|
+
|
105
|
+
def singleton_method_added(traced)
|
106
|
+
# avoid infinite recursion if module is included into a class by a user
|
107
|
+
return if traced == QuickTest.runner.methods.last
|
108
|
+
|
109
|
+
if traced == :quicktest
|
110
|
+
QuickTest.runner.new self
|
111
|
+
else
|
112
|
+
QuickTest.runner.add_singleton_method traced
|
113
|
+
__quicktest_singleton_method_added__ traced
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
QuickTest.ignore_first_method_added = true
|
118
|
+
|
119
|
+
def method_added(traced)
|
120
|
+
# avoid infinite recursion if module is included into a class by a user
|
121
|
+
return if traced == QuickTest.runner.methods.last
|
122
|
+
|
123
|
+
if traced == :quicktest
|
124
|
+
if self.class == Module
|
125
|
+
fail "to test module instance methods, include them in a class"
|
126
|
+
end
|
127
|
+
QuickTest.runner.new self.new
|
128
|
+
|
129
|
+
else
|
130
|
+
unless QuickTest.ignore_first_method_added or
|
131
|
+
QuickTest.runner::IgnoreMethodAddedClasses.detect {|m| self.to_s =~ m}
|
132
|
+
QuickTest.runner.add_method traced
|
133
|
+
end
|
134
|
+
|
135
|
+
QuickTest.ignore_first_method_added = false
|
136
|
+
__quicktest_method_added__ traced
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
# add cases for different test handlers here
|
146
|
+
QuickTest.runner =
|
147
|
+
case ARGV[0]
|
148
|
+
when '--rspec' then ARGV.shift; QuickTest::RSpecTestRunner
|
149
|
+
else # assume rspec
|
150
|
+
QuickTest::RSpecTestRunner
|
151
|
+
end
|
152
|
+
|
153
|
+
class Module; include QuickTest::Tracer end
|
154
|
+
#class Class; include QuickTest::Tracer end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
def test_dir; Dir.chdir('test') {|dir| yield dir } end
|
2
|
+
|
3
|
+
desc "test"
|
4
|
+
task :test do
|
5
|
+
run = 'spec -r ../lib/quicktest test.rb'
|
6
|
+
test_dir {puts `#{run} >| test_result.txt || #{run}`}
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :test do
|
10
|
+
run = '../bin/quickspec test.rb'
|
11
|
+
|
12
|
+
task :generate do
|
13
|
+
test_dir {`#{run} >| test_result.txt`}
|
14
|
+
end
|
15
|
+
desc "test quickspec executable"
|
16
|
+
task :quickspec => :generate do
|
17
|
+
test_dir {puts `#{run}`}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'rake/gempackagetask'
|
24
|
+
|
25
|
+
spec = Gem::Specification.new do |s|
|
26
|
+
s.name = "quicktest"
|
27
|
+
s.rubyforge_project = "quicktest"
|
28
|
+
s.version = "0.1.0"
|
29
|
+
s.author = "Greg Weber"
|
30
|
+
s.email = "greg@gregweber.info"
|
31
|
+
s.homepage = "http://quicktest.rubyfore.org/"
|
32
|
+
s.platform = Gem::Platform::RUBY
|
33
|
+
s.summary = "utility for inlining tests with the code tested"
|
34
|
+
s.executables = ['quickspec']
|
35
|
+
s.files = Dir['./**'] + Dir['*/**']
|
36
|
+
s.require_path = "lib"
|
37
|
+
s.has_rdoc = true
|
38
|
+
s.extra_rdoc_files = ["README"]
|
39
|
+
end
|
40
|
+
|
41
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
42
|
+
pkg.need_tar = false
|
43
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# regenerate test_result.txt with
|
2
|
+
# spec -r ../lib/quicktest test.rb >| test_result.txt
|
3
|
+
# run tests with
|
4
|
+
# spec -r ../lib/quicktest test.rb
|
5
|
+
# regenerate and run
|
6
|
+
# spec -r ../lib/quicktest test.rb >| test_result.txt || spec -r ../lib/quicktest test.rb
|
7
|
+
$r = File.readlines('test_result.txt')
|
8
|
+
3.times {$r.shift}
|
9
|
+
|
10
|
+
def quicktest t,s
|
11
|
+
msg = "should show class name in output"
|
12
|
+
t.it msg do
|
13
|
+
$r.shift.should =~ /^'#<#{s.class}:0x[^>]+> #{msg}' FAILED$/
|
14
|
+
7.times {$r.shift}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@@new_meth = :new_method_added
|
18
|
+
eval"def #@@new_meth; end"
|
19
|
+
|
20
|
+
def quicktest t,s
|
21
|
+
msg = "should show name of added method"
|
22
|
+
t.it msg do
|
23
|
+
$r.shift.should =~ /^'#<#{s.class}:0x[^>]+> #{@@new_meth} #{msg}' FAILED$/
|
24
|
+
7.times {$r.shift}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module TestModule
|
29
|
+
@@klass = self
|
30
|
+
def self.quicktest t
|
31
|
+
msg = "should show class name in output"
|
32
|
+
t.it msg do
|
33
|
+
$r.shift.should =~ /^'#{@@klass} #{msg}' FAILED$/
|
34
|
+
7.times {$r.shift}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@@new_singleton_meth = 'new_singleton_method_added'
|
39
|
+
eval"def self.#@@new_singleton_meth;end"
|
40
|
+
|
41
|
+
def self.quicktest t
|
42
|
+
msg = "should show class name in output"
|
43
|
+
t.it msg do
|
44
|
+
$r.shift.should =~ /^'#{@@klass} #@@new_singleton_meth #{msg}' FAILED$/
|
45
|
+
7.times {$r.shift}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class TestClass
|
51
|
+
@@klass = self
|
52
|
+
def self.quicktest t
|
53
|
+
msg = "should show class name in output"
|
54
|
+
t.it msg do
|
55
|
+
$r.shift.should =~ /^'#{@@klass} #{msg}' FAILED$/
|
56
|
+
7.times {$r.shift}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
def quicktest t,s
|
60
|
+
msg = "should show class name in output"
|
61
|
+
t.it msg do
|
62
|
+
$r.shift.should =~ /^'#<#{s.class}:0x[^>]+> #{msg}' FAILED$/
|
63
|
+
7.times {$r.shift}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
@@new_meth = :new_method_added
|
67
|
+
define_method @@new_meth do end
|
68
|
+
|
69
|
+
def quicktest t,s
|
70
|
+
msg = "should show name of added method"
|
71
|
+
t.it msg do
|
72
|
+
$r.shift.should =~ /^'#<#{s.class}:0x[^>]+> #{@@new_meth} #{msg}' FAILED$/
|
73
|
+
7.times {$r.shift}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
@@new_singleton_meth = 'new_singleton_method_added'
|
78
|
+
eval"def self.#@@new_singleton_meth;end"
|
79
|
+
|
80
|
+
def self.quicktest t
|
81
|
+
msg = "should show class name in output"
|
82
|
+
t.it msg do
|
83
|
+
$r.shift.should =~ /^'#{@@klass} #@@new_singleton_meth #{msg}' FAILED$/
|
84
|
+
7.times {$r.shift}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
FFFFFFFF
|
2
|
+
|
3
|
+
1)
|
4
|
+
'#<Object:0xb789c5bc> should show class name in output' FAILED
|
5
|
+
expected: /^'#<Object:0x[^>]+> should show class name in output' FAILED$/,
|
6
|
+
got: nil (using =~)
|
7
|
+
./test.rb:13:in `quicktest'
|
8
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `instance_eval'
|
9
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `run_tests'
|
10
|
+
|
11
|
+
2)
|
12
|
+
'#<Object:0xb789be14> new_method_added should show name of added method' FAILED
|
13
|
+
expected: /^'#<Object:0x[^>]+> new_method_added should show name of added method' FAILED$/,
|
14
|
+
got: nil (using =~)
|
15
|
+
./test.rb:23:in `quicktest'
|
16
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `instance_eval'
|
17
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `run_tests'
|
18
|
+
|
19
|
+
3)
|
20
|
+
'TestModule should show class name in output' FAILED
|
21
|
+
expected: /^'TestModule should show class name in output' FAILED$/,
|
22
|
+
got: nil (using =~)
|
23
|
+
./test.rb:33:in `quicktest'
|
24
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `instance_eval'
|
25
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `run_tests'
|
26
|
+
|
27
|
+
4)
|
28
|
+
'TestModule new_singleton_method_added should show class name in output' FAILED
|
29
|
+
expected: /^'TestModule new_singleton_method_added should show class name in output' FAILED$/,
|
30
|
+
got: nil (using =~)
|
31
|
+
./test.rb:44:in `quicktest'
|
32
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `instance_eval'
|
33
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `run_tests'
|
34
|
+
|
35
|
+
5)
|
36
|
+
'TestClass should show class name in output' FAILED
|
37
|
+
expected: /^'TestClass should show class name in output' FAILED$/,
|
38
|
+
got: nil (using =~)
|
39
|
+
./test.rb:55:in `quicktest'
|
40
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `instance_eval'
|
41
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `run_tests'
|
42
|
+
|
43
|
+
6)
|
44
|
+
'#<TestClass:0xb789a2e4> should show class name in output' FAILED
|
45
|
+
expected: /^'#<TestClass:0x[^>]+> should show class name in output' FAILED$/,
|
46
|
+
got: nil (using =~)
|
47
|
+
./test.rb:62:in `quicktest'
|
48
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `instance_eval'
|
49
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `run_tests'
|
50
|
+
|
51
|
+
7)
|
52
|
+
'#<TestClass:0xb7899c2c> new_method_added should show name of added method' FAILED
|
53
|
+
expected: /^'#<TestClass:0x[^>]+> new_method_added should show name of added method' FAILED$/,
|
54
|
+
got: nil (using =~)
|
55
|
+
./test.rb:72:in `quicktest'
|
56
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `instance_eval'
|
57
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `run_tests'
|
58
|
+
|
59
|
+
8)
|
60
|
+
'TestClass new_singleton_method_added should show class name in output' FAILED
|
61
|
+
expected: /^'TestClass new_singleton_method_added should show class name in output' FAILED$/,
|
62
|
+
got: nil (using =~)
|
63
|
+
./test.rb:83:in `quicktest'
|
64
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `instance_eval'
|
65
|
+
/home/greg/quicktest/lib/quicktest.rb:79:in `run_tests'
|
66
|
+
|
67
|
+
Finished in 0.02123 seconds
|
68
|
+
|
69
|
+
8 examples, 8 failures
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: quicktest
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2008-02-25 00:00:00 -06:00
|
8
|
+
summary: utility for inlining tests with the code tested
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: greg@gregweber.info
|
12
|
+
homepage: http://quicktest.rubyfore.org/
|
13
|
+
rubyforge_project: quicktest
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Greg Weber
|
31
|
+
files:
|
32
|
+
- ./bin
|
33
|
+
- ./doc
|
34
|
+
- ./lib
|
35
|
+
- ./pkg
|
36
|
+
- ./test
|
37
|
+
- ./README
|
38
|
+
- ./rakefile
|
39
|
+
- bin/quickspec
|
40
|
+
- doc/files
|
41
|
+
- doc/index.html
|
42
|
+
- doc/rdoc-style.css
|
43
|
+
- doc/fr_method_index.html
|
44
|
+
- doc/fr_class_index.html
|
45
|
+
- doc/fr_file_index.html
|
46
|
+
- doc/created.rid
|
47
|
+
- doc/classes
|
48
|
+
- lib/quicktest.rb
|
49
|
+
- pkg/quicktest-0.0.1.gem
|
50
|
+
- pkg/quicktest-0.0.2.gem
|
51
|
+
- pkg/quicktest-0.0.3.gem
|
52
|
+
- pkg/quicktest-0.0.4.gem
|
53
|
+
- pkg/quicktest-0.0.5.gem
|
54
|
+
- pkg/quicktest-0.0.6.gem
|
55
|
+
- pkg/quicktest-0.0.7.gem
|
56
|
+
- pkg/quicktest-0.0.8.gem
|
57
|
+
- test/test.rb
|
58
|
+
- test/test_result.txt
|
59
|
+
- README
|
60
|
+
test_files: []
|
61
|
+
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
extra_rdoc_files:
|
65
|
+
- README
|
66
|
+
executables:
|
67
|
+
- quickspec
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
dependencies: []
|
73
|
+
|