test-unit-mock 0.30

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 (10) hide show
  1. data/COPYING +58 -0
  2. data/ChangeLog +262 -0
  3. data/README +203 -0
  4. data/install.rb +85 -0
  5. data/misc/readmecode.rb +125 -0
  6. data/mock.rb +467 -0
  7. data/test-unit-mock.gemspec +20 -0
  8. data/test.rb +327 -0
  9. data/utils.rb +345 -0
  10. metadata +59 -0
data/COPYING ADDED
@@ -0,0 +1,58 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the GPL
3
+ (see COPYING.txt file), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) rename any non-standard executables so the names do not conflict
21
+ with standard executables, which must also be provided.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or executable
26
+ form, provided that you do at least ONE of the following:
27
+
28
+ a) distribute the executables and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard executables non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under this terms.
43
+
44
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
45
+ files under the ./missing directory. See each file for the copying
46
+ condition.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
53
+
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
+ PURPOSE.
58
+
@@ -0,0 +1,262 @@
1
+ 2003-10-01 09:11 Michael Granger <ged@FaerieMUD.org>
2
+
3
+ * mock.rb (1.10):
4
+
5
+ - Added #respond_to? to UnmockedMethods. Thanks to Samuel Tesla
6
+ <samuel@alieniloquent.com> for the bug report and patch.
7
+
8
+ 2003-10-01 09:10 Michael Granger <ged@FaerieMUD.org>
9
+
10
+ * test.rb (1.5):
11
+
12
+ - Added better add{setup,teardown}Block mechanics
13
+
14
+ - Added tests for UnmockedMethods
15
+
16
+ 2003-05-31 13:26 Michael Granger <ged@FaerieMUD.org>
17
+
18
+ * mock.rb (1.9, RELEASE_0_02):
19
+
20
+ - Moved the regex that matches unmocked methods into a constant and //x'ed it,
21
+ as it was becoming unwieldy and/or unreadable.
22
+
23
+ - Added an is_a? alias for the faked kind_of?.
24
+
25
+ 2003-05-12 12:42 Michael Granger <ged@FaerieMUD.org>
26
+
27
+ * docs/lib/rdoc/generators/template/html/mues.rb (1.6):
28
+
29
+ - Fixed XHTML validity by adding missing </td>.
30
+
31
+ - Updated copyright dates.
32
+
33
+ 2003-03-05 13:44 Michael Granger <ged@FaerieMUD.org>
34
+
35
+ * misc/readmecode.rb (1.2, RELEASE_0_02):
36
+
37
+ - Wrapped the callTrace for each test in a $DEBUG block.
38
+
39
+ 2003-03-05 13:43 Michael Granger <ged@FaerieMUD.org>
40
+
41
+ * mock.rb (1.8):
42
+
43
+ - New method: fullStackTrace().
44
+
45
+ 2003-03-05 13:35 Michael Granger <ged@FaerieMUD.org>
46
+
47
+ * README (1.3, RELEASE_0_02):
48
+
49
+ - Added example usage of the #callTrace method.
50
+
51
+ - Added example of using MockObject() factory method for a superclass.
52
+
53
+ 2003-03-04 17:07 Michael Granger <ged@FaerieMUD.org>
54
+
55
+ * docs/makesitedocs.rb (1.2, RELEASE_0_02):
56
+
57
+ Updated upload URL
58
+
59
+ 2003-03-04 16:44 Michael Granger <ged@FaerieMUD.org>
60
+
61
+ * COPYING (1.1), makedist.rb (1.1) (utags: RELEASE_0_02,
62
+ RELEASE_0_01):
63
+
64
+ Initial commit.
65
+
66
+ 2003-03-04 16:42 Michael Granger <ged@FaerieMUD.org>
67
+
68
+ * README (1.2, RELEASE_0_01):
69
+
70
+ - Modified documentation instructions to not requires the docs/ directory, which
71
+ won't be in the distribution.
72
+
73
+ 2003-03-04 16:39 Michael Granger <ged@FaerieMUD.org>
74
+
75
+ * mock.rb (1.7, RELEASE_0_01):
76
+
77
+ - Updated, clarified, and corrected documentation.
78
+
79
+ - Made calls to #verify use Test::Unit::Assertions.
80
+
81
+ - Fixed bug in __makeCallOrderFailMsg() that manifested when @callOrder
82
+ contained more entries than @calls.
83
+
84
+ - Removed unnecessary arguments to super() in the generated mock methods.
85
+
86
+ 2003-03-04 16:35 Michael Granger <ged@FaerieMUD.org>
87
+
88
+ * test.rb (1.4, RELEASE_0_02, RELEASE_0_01):
89
+
90
+ - Made changes to requires to reflect reorganization of distro.
91
+
92
+ 2003-03-04 16:35 Michael Granger <ged@FaerieMUD.org>
93
+
94
+ * utils.rb (1.2, RELEASE_0_02, RELEASE_0_01):
95
+
96
+ - Updated with changes from other modules.
97
+
98
+ 2003-03-04 16:32 Michael Granger <ged@FaerieMUD.org>
99
+
100
+ * README (1.1), install.rb (1.1, RELEASE_0_02, RELEASE_0_01),
101
+ misc/readmecode.rb (1.1, RELEASE_0_01), docs/.cvsignore (1.1,
102
+ RELEASE_0_02, RELEASE_0_01), docs/CATALOG (1.1, RELEASE_0_02,
103
+ RELEASE_0_01), docs/makedocs.rb (1.1, RELEASE_0_02, RELEASE_0_01),
104
+ docs/makesitedocs.rb (1.1, RELEASE_0_01):
105
+
106
+ Initial commit.
107
+
108
+ 2003-03-04 10:52 Michael Granger <ged@FaerieMUD.org>
109
+
110
+ * test.rb (1.3):
111
+
112
+ - Added tests for double-underscored and non-camelCased methods.
113
+
114
+ 2003-03-03 23:33 Michael Granger <ged@FaerieMUD.org>
115
+
116
+ * mock.rb (1.6):
117
+
118
+ - Fixed an accidentally-slashed <tt> in the RDocs.
119
+
120
+ 2003-01-25 18:31 Michael Granger <ged@FaerieMUD.org>
121
+
122
+ * mock.rb (1.5):
123
+
124
+ - More documenation fixes.
125
+
126
+ 2003-01-25 18:29 Michael Granger <ged@FaerieMUD.org>
127
+
128
+ * mock.rb (1.4):
129
+
130
+ - Documented usage of the MockObject method in a class definition.
131
+
132
+ - Untabified literal/synopsis sections.
133
+
134
+ 2003-01-25 18:09 Michael Granger <ged@FaerieMUD.org>
135
+
136
+ * mock.rb (1.3):
137
+
138
+ - Updated for newer versions of Ruby.
139
+
140
+ - Prefixed internal methods for MockObject with '__' to avoid collision with
141
+ actual methods.
142
+
143
+ - Added block argument to mocked methods.
144
+
145
+ - Added '#hash' to the list of methods not mocked.
146
+
147
+ 2003-01-25 18:06 Michael Granger <ged@FaerieMUD.org>
148
+
149
+ * test.rb (1.2):
150
+
151
+ - Updated for newer versions of Ruby.
152
+
153
+ - Updated for newer versions of Test::Unit.
154
+
155
+ 2002-10-02 10:56 Michael Granger <ged@FaerieMUD.org>
156
+
157
+ * mock.rb (1.2):
158
+
159
+ - Finished up the comment header.
160
+
161
+ 2002-10-02 03:03 Michael Granger <ged@FaerieMUD.org>
162
+
163
+ * mock.rb (1.1), test.rb (1.1), utils.rb (1.1):
164
+
165
+ Initial revision
166
+
167
+ 2002-10-02 03:03 Michael Granger <ged@FaerieMUD.org>
168
+
169
+ * mock.rb (1.1.1.1), test.rb (1.1.1.1), utils.rb (1.1.1.1) (utags:
170
+ ALPHA_1_1):
171
+
172
+ Initial import
173
+
174
+ 2002-09-12 03:55 Michael Granger <ged@FaerieMUD.org>
175
+
176
+ * docs/lib/rdoc/: generators/html_generator.rb (1.3),
177
+ parsers/parse_faeriemud_rb.rb (1.2) (utags: RELEASE_0_02,
178
+ RELEASE_0_01):
179
+
180
+ - Initial stab at the :todo: hack. Not yet working.
181
+
182
+ 2002-08-29 01:15 Michael Granger <ged@FaerieMUD.org>
183
+
184
+ * docs/lib/rdoc/generators/template/html/mues.rb (1.5,
185
+ RELEASE_0_01, RELEASE_0_02):
186
+
187
+ - Added the <br /> I mistakenly removed with the viewcvs commit back in.
188
+
189
+ 2002-08-02 14:07 Michael Granger <ged@FaerieMUD.org>
190
+
191
+ * docs/lib/rdoc/generators/template/html/mues.rb (1.4):
192
+
193
+ - Added a link to the appropriate URL on cvs.FaerieMUD.org.
194
+
195
+ 2002-07-07 12:16 Michael Granger <ged@FaerieMUD.org>
196
+
197
+ * docs/lib/rdoc/generators/template/html/css2.rb (1.1,
198
+ RELEASE_0_01, RELEASE_0_02):
199
+
200
+ Initial commit.
201
+
202
+ 2002-06-04 06:56 Michael Granger <ged@FaerieMUD.org>
203
+
204
+ * docs/lib/rdoc/generators/faeriemud_generator.rb (1.3):
205
+
206
+ Renamed to html_generator.rb
207
+
208
+ 2002-05-28 11:07 Michael Granger <ged@FaerieMUD.org>
209
+
210
+ * docs/lib/rdoc/generators/template/html/mues.rb (1.3):
211
+
212
+ - Renamed from faeriemud.rb
213
+
214
+ - Converted to output XHTML.
215
+
216
+ - Added comment header and other nicities in preparation for release.
217
+
218
+ 2002-05-28 11:06 Michael Granger <ged@FaerieMUD.org>
219
+
220
+ * docs/lib/rdoc/generators/template/html/faeriemud.rb (1.3):
221
+
222
+ - Renamed to mues.rb.
223
+
224
+ 2002-05-15 22:02 Michael Granger <ged@FaerieMUD.org>
225
+
226
+ * docs/lib/rdoc/generators/template/html/: faeriemud.rb (1.2),
227
+ mues.rb (1.2):
228
+
229
+ - Removed break in class header 'Last Updated' label.
230
+
231
+ 2002-05-15 21:42 Michael Granger <ged@FaerieMUD.org>
232
+
233
+ * docs/lib/rdoc/generators/myhtml_generator.rb (1.3):
234
+
235
+ - Renamed to faeriemud_generator.rb in preparation for submitting to PragDave.
236
+
237
+ 2002-05-15 21:40 Michael Granger <ged@FaerieMUD.org>
238
+
239
+ * docs/lib/rdoc/generators/: faeriemud_generator.rb (1.2),
240
+ html_generator.rb (1.2), myhtml_generator.rb (1.2):
241
+
242
+ - Touched up comments
243
+
244
+ - Added a missing require
245
+
246
+ 2002-05-15 21:30 Michael Granger <ged@FaerieMUD.org>
247
+
248
+ * docs/lib/rdoc/myparser.rb (1.2):
249
+
250
+ - Moved into docs/lib/rdoc/parsers/parse_faeriemud_rb.rb.
251
+
252
+ 2002-03-30 12:01 Michael Granger <ged@FaerieMUD.org>
253
+
254
+ * docs/lib/rdoc/: myparser.rb (1.1),
255
+ generators/faeriemud_generator.rb (1.1),
256
+ generators/html_generator.rb (1.1), generators/myhtml_generator.rb
257
+ (1.1), generators/template/html/faeriemud.rb (1.1),
258
+ generators/template/html/mues.rb (1.1),
259
+ parsers/parse_faeriemud_rb.rb (1.1):
260
+
261
+ Initial commit.
262
+
data/README ADDED
@@ -0,0 +1,203 @@
1
+
2
+ = Test-Unit-Mock: A mock-object class for Test::Unit
3
+
4
+ == Authors
5
+
6
+ Michael Granger <ged@FaerieMUD.org>
7
+
8
+
9
+ == Description
10
+
11
+ Test-Unit-Mock is a class for conveniently building mock objects in Test::Unit
12
+ test cases. It is based on ideas in Ruby/Mock by Nat Pryce
13
+ <nat.pryce@b13media.com>, which is a class for doing much the same thing for
14
+ RUnit test cases.
15
+
16
+ It allows you do make a mocked object that will respond to all the methods of
17
+ the real class (albeit probably not with correct results) with one line of
18
+ code. Eg.,
19
+
20
+ mockSocket = Test::Unit::MockObject( TCPSocket ).new
21
+
22
+ You can then specify return values for the methods you wish to test in one of
23
+ several different ways:
24
+
25
+ # Make the #addr method return three cycling values (which will be repeated
26
+ # when it reaches the end
27
+ mockSocket.setReturnValues( :addr => [
28
+ ["AF_INET", 23, "localhost", "127.0.0.1"],
29
+ ["AF_INET", 80, "slashdot.org", "66.35.250.150"],
30
+ ["AF_INET", 2401, "helium.ruby-lang.org", "210.251.121.214"],
31
+ ] )
32
+
33
+ # Make the #write and #read methods call a Proc and a Method, respectively
34
+ mockSocket.setReturnValues( :write => Proc::new {|str| str.length},
35
+ :read => method(:fakeRead) )
36
+
37
+ # Set up the #getsockopt method to return a value based on the arguments
38
+ # given:
39
+ mockSocket.setReturnValues( :getsockopt => {
40
+ [Socket::SOL_TCP, Socket::TCP_NODELAY] => [0].pack("i_"),
41
+ [Socket::SOL_SOCKET, Socket::SO_REUSEADDR] => [1].pack("i_"),
42
+ } )
43
+
44
+ You can also set the order in which you expect methods to be called, but you
45
+ don't have to do so if you don't care:
46
+
47
+ mockSocket.setCallOrder( :addr, :getsockopt, :write, :read, :write, :read )
48
+
49
+
50
+ By default, when testing for call order, other method calls may be interspersed
51
+ between the calls specified without effect, and only a missing or misordered method
52
+ call causes the assertions to fail. If you want the call order to be adhered to
53
+ strictly, you can set that:
54
+
55
+ mockSocket.strictCallOrder = true
56
+
57
+ Then, when you're ready to test, just activate the object and send it off to
58
+ whatever code you're testing:
59
+
60
+ mockSocket.activate
61
+ testedObject.setSocket( mockSocket )
62
+ ...
63
+
64
+ # Check method call order on the mocked socket (adds assertions)
65
+ mockSocket.verify
66
+
67
+ Assertion failures contain a message that specifies exactly what went wrong,
68
+ eg.:
69
+
70
+ $ ruby misc/readmecode.rb
71
+
72
+ 1) Failure!!!
73
+ test_incorrectorder(MockTestExperiment) [./mock.rb:255]:
74
+ Call order assertion failed: Expected call to :write, but got call to :read
75
+ from misc/readmecode.rb:77:in `test_incorrectorder' at 0.00045
76
+ instead
77
+
78
+ 2) Failure!!!
79
+ test_missingcall(MockTestExperiment) [./mock.rb:255]:
80
+ Call order assertion failed: Missing call to :read.
81
+
82
+ If you require more advanced functionality, you can also use the mocked object
83
+ class as a superclass:
84
+
85
+ # Create a mock socket class
86
+ class MockSocket < Test::Unit::MockObject( TCPSocket )
87
+ def initialize
88
+ super
89
+ setCallOrder( :read, :read, :read, :write, :read )
90
+ strictCallOrder = true
91
+ @io = ''
92
+ end
93
+
94
+ def read( len )
95
+ super # Call the mocked method to record the call
96
+ rval = @io[0,len]
97
+ @io[0,len] = ''
98
+
99
+ return rval
100
+ end
101
+
102
+ def write( str )
103
+ super # Call the mocked method to record the call
104
+ @io += str
105
+ return str.length
106
+ end
107
+ end
108
+
109
+
110
+ You can also add debugging to your tests to give you a timestamped history of
111
+ each call:
112
+
113
+ # Call the methods in the correct order
114
+ mockSocket.addr
115
+ mockSocket.getsockopt( Socket::SOL_TCP, Socket::TCP_NODELAY )
116
+ mockSocket.write( "foo" )
117
+ mockSocket.read( 1024 )
118
+ mockSocket.write( "bar" )
119
+ mockSocket.read( 4096 )
120
+
121
+ # Check method call order on the mocked socket
122
+ mockSocket.verify
123
+
124
+ if $DEBUG
125
+ puts "Call trace:\n\t" + mockSocket.callTrace.join("\n\t")
126
+ end
127
+
128
+ This outputs something like:
129
+
130
+ Call trace:
131
+ addr( ) at 0.00015 seconds from misc/readmecode.rb:64:in `test'
132
+ getsockopt( 6,1 ) at 0.00030 seconds from misc/readmecode.rb:65:in `test'
133
+ write( "foo" ) at 0.00040 seconds from misc/readmecode.rb:66:in `test'
134
+ read( 1024 ) at 0.00050 seconds from misc/readmecode.rb:67:in `test'
135
+ write( "bar" ) at 0.00063 seconds from misc/readmecode.rb:68:in `test'
136
+ read( 4096 ) at 0.00072 seconds from misc/readmecode.rb:69:in `test'
137
+
138
+
139
+ == More Information
140
+
141
+ For more information about mock objects and unit testing, see:
142
+
143
+ <URL: http://www.sidewize.com/company/mockobjects.pdf>
144
+
145
+
146
+ == Requirements
147
+
148
+ * Ruby >= 1.6.8 - Older versions have not been tested, but may work.
149
+ <URL: http://www.ruby-lang.org/en/>
150
+
151
+ * Test::Unit - Of course.
152
+ <URL: http://raa.ruby-lang.org/list.rhtml?name=testunit>
153
+
154
+ * The 'diff' library - Used to compare the call lists.
155
+ <URL: http://raa.ruby-lang.org/list.rhtml?name=diff>
156
+
157
+
158
+ == Caveats
159
+
160
+ This module, while simple, has not been extensively tested under environments
161
+ other than my own (Linux). It has worked well for me, but your mileage may vary.
162
+
163
+ I would greatly appreciate feedback on any aspect of this software. Suggestions,
164
+ feature requests, questions, design critiques, and bug reports are most
165
+ welcome. Relevant patches are particularly helpful. I may be reached at
166
+ <ged@FaerieMUD.org>.
167
+
168
+
169
+ == Installation
170
+
171
+ To run the included test suite:
172
+
173
+ $ ruby test.rb
174
+
175
+ To generate HTML documentation:
176
+
177
+ $ rdoc README mock.rb
178
+
179
+ To install:
180
+
181
+ $ su
182
+ # ruby install.rb
183
+
184
+
185
+ == Legal
186
+
187
+ Test-Unit-Mock is Free Software which is Copyright (c) 2002,2003 by The
188
+ FaerieMUD Consortium.
189
+
190
+ You may use, modify, and/or redistribute this software under the terms of the
191
+ Ruby License, a copy of which should have been included in this distribution
192
+ (See the file COPYING). If it was not, a copy of it may be obtained online at
193
+ http://www.ruby-lang.org/en/LICENSE.txt (English language) or
194
+ http://www.ruby-lang.org/ja/LICENSE.txt (Japanese language).
195
+
196
+ THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
197
+ INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
198
+ FITNESS FOR A PARTICULAR PURPOSE.
199
+
200
+
201
+ $Id: README,v 1.3 2003/03/05 20:35:28 deveiant Exp $
202
+
203
+