Test::Unit::TestCase
Test case class
(Not documented)
(Not documented)
Append a setup block for the current testcase
# File lib/arrow/testcase.rb, line 153
153: def self::addSetupBlock( &block )
154: @@methodCounter += 1
155: newMethodName = "setup_#{@@methodCounter}".intern
156: define_method( newMethodName, &block )
157: self.setupMethods.push newMethodName
158: end
Prepend a teardown block for the current testcase
# File lib/arrow/testcase.rb, line 162
162: def self::addTeardownBlock( &block )
163: @@methodCounter += 1
164: newMethodName = "teardown_#{@@methodCounter}".intern
165: define_method( newMethodName, &block )
166: self.teardownMethods.unshift newMethodName
167: end
Returns a String containing the specified ANSI escapes suitable for inclusion in another string. The attributes should be one or more of the keys of AnsiAttributes.
# File lib/arrow/testcase.rb, line 122
122: def self::ansiCode( *attributes )
123: return '' unless /(?:xterm(?:-color)?|eterm|linux)/i =~ ENV['TERM']
124:
125: attr = attributes.collect {|a|
126: AnsiAttributes[a] ? AnsiAttributes[a] : nil
127: }.compact.join(';')
128: if attr.empty?
129: return ''
130: else
131: return "\e[%sm" % attr
132: end
133: end
Output the specified msgs joined together to STDERR if $DEBUG is set.
# File lib/arrow/testcase.rb, line 138
138: def self::debugMsg( *msgs )
139: return unless $DEBUG
140: self.message "%sDEBUG>>> %s %s" %
141: [ ansiCode('dark', 'white'), msgs.join(''), ansiCode('reset') ]
142: end
Inheritance callback — adds @setupMethods and @teardownMethods ivars and accessors to the inheriting class.
# File lib/arrow/testcase.rb, line 106
106: def self::inherited( klass )
107: klass.module_eval {
108: @setupMethods = []
109: @teardownMethods = []
110:
111: class << self
112: attr_accessor :setupMethods
113: attr_accessor :teardownMethods
114: end
115: }
116: end
Add the specified block to the code that gets executed by #setup.
# File lib/arrow/testcase.rb, line 219
219: def addSetupBlock( &block ); self.class.addSetupBlock( &block ); end
Add the specified block to the code that gets executed by #teardown.
# File lib/arrow/testcase.rb, line 223
223: def addTeardownBlock( &block ); self.class.addTeardownBlock( &block ); end
Instance-alias for the like-named class method
# File lib/arrow/testcase.rb, line 461
461: def ansiCode( *attributes )
462: self.class.ansiCode( *attributes )
463: end
Assert that the specified klass defines the specified instance method meth.
# File lib/arrow/testcase.rb, line 434
434: def assert_has_instance_method( klass, meth )
435: msg = "<%s> expected to define instance method #%s" %
436: [ klass, meth ]
437: assert_block( msg ) {
438: klass.instance_methods.include?( meth.to_s )
439: }
440: rescue Test::Unit::AssertionFailedError => err
441: cutframe = err.backtrace.reverse.find {|frame|
442: /assert_has_instance_method/ =~ frame
443: }
444: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
445: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
446: end
Assert that the specified object has an instance variable which matches the specified sym. The ’@’ at the beginning of the sym will be prepended if not present.
# File lib/arrow/testcase.rb, line 399
399: def assert_has_ivar( sym, object )
400: sym = "@#{sym}" unless /^@/ =~ sym.to_s
401: msg = "Object <%s> expected to have an instance variable <%s>" %
402: [ object.inspect, sym ]
403: assert_block( msg ) {
404: object.instance_variables.include?( sym.to_s )
405: }
406: rescue Test::Unit::AssertionFailedError => err
407: cutframe = err.backtrace.reverse.find {|frame|
408: /assert_has_ivar/ =~ frame
409: }
410: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
411: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
412: end
Test Hashes for equivalent content
# File lib/arrow/testcase.rb, line 234
234: def assert_hash_equal( expected, actual, msg="" )
235: errmsg = "Expected hash <%p> to be equal to <%p>" % [expected, actual]
236: errmsg += ": #{msg}" unless msg.empty?
237:
238: assert_block( errmsg ) {
239: diffs = compare_hashes( expected, actual )
240: unless diffs.empty?
241: errmsg += ": " + diffs.join("; ")
242: return false
243: else
244: return true
245: end
246: }
247: rescue Test::Unit::AssertionFailedError => err
248: cutframe = err.backtrace.reverse.find {|frame|
249: /assert_hash_equal/ =~ frame
250: }
251: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
252: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
253: end
Succeeds if obj include? item.
# File lib/arrow/testcase.rb, line 333
333: def assert_include( item, obj, msg=nil )
334: msg ||= "<%p> expected to include <%p>." % [ obj, item ]
335: assert_block( msg ) { obj.respond_to?(:include?) && obj.include?(item) }
336: rescue Test::Unit::AssertionFailedError => err
337: cutframe = err.backtrace.reverse.find {|frame|
338: /assert_include/ =~ frame
339: }
340: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
341: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
342: end
Assert that the instance variable specified by sym of an object is equal to the specified value. The ’@’ at the beginning of the sym will be prepended if not present.
# File lib/arrow/testcase.rb, line 379
379: def assert_ivar_equal( value, object, sym )
380: sym = "@#{sym}".intern unless /^@/ =~ sym.to_s
381: msg = "Instance variable '%s'\n\tof <%s>\n\texpected to be <%s>\n" %
382: [ sym, object.inspect, value.inspect ]
383: msg += "\tbut was: <%p>" % [ object.instance_variable_get(sym) ]
384: assert_block( msg ) {
385: value == object.instance_variable_get(sym)
386: }
387: rescue Test::Unit::AssertionFailedError => err
388: cutframe = err.backtrace.reverse.find {|frame|
389: /assert_ivar_equal/ =~ frame
390: }
391: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
392: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
393: end
Assert that the specified str does not match the given regular expression re.
# File lib/arrow/testcase.rb, line 417
417: def assert_not_match( re, str )
418: msg = "<%s> expected not to match %p" %
419: [ str, re ]
420: assert_block( msg ) {
421: !re.match( str )
422: }
423: rescue Test::Unit::AssertionFailedError => err
424: cutframe = err.backtrace.reverse.find {|frame|
425: /assert_not_match/ =~ frame
426: }
427: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
428: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
429: end
Override the stupid deprecated #assert_not_nil so when it disappears, code doesn‘t break.
# File lib/arrow/testcase.rb, line 320
320: def assert_not_nil( obj, msg=nil )
321: msg ||= "<%p> expected to not be nil." % obj
322: assert_block( msg ) { !obj.nil? }
323: rescue Test::Unit::AssertionFailedError => err
324: cutframe = err.backtrace.reverse.find {|frame|
325: /assert_not_nil/ =~ frame
326: }
327: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
328: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
329: end
Negative of assert_respond_to
# File lib/arrow/testcase.rb, line 361
361: def assert_not_respond_to( obj, meth )
362: msg = "%s expected NOT to respond to '%s'" %
363: [ obj.inspect, meth ]
364: assert_block( msg ) {
365: !obj.respond_to?( meth )
366: }
367: rescue Test::Unit::AssertionFailedError => err
368: cutframe = err.backtrace.reverse.find {|frame|
369: /assert_not_respond_to/ =~ frame
370: }
371: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
372: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
373: end
Negative of assert_respond_to
# File lib/arrow/testcase.rb, line 346
346: def assert_not_tainted( obj, msg=nil )
347: msg ||= "<%p> expected to NOT be tainted" % [ obj ]
348: assert_block( msg ) {
349: !obj.tainted?
350: }
351: rescue Test::Unit::AssertionFailedError => err
352: cutframe = err.backtrace.reverse.find {|frame|
353: /assert_not_tainted/ =~ frame
354: }
355: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
356: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
357: end
Test Hashes (or any other objects with a #keys method) for key set equality
# File lib/arrow/testcase.rb, line 284
284: def assert_same_keys( expected, actual, msg="" )
285: errmsg = "Expected keys of <%p> to be equal to those of <%p>" %
286: [ actual, expected ]
287: errmsg += ": #{msg}" unless msg.empty?
288:
289: ekeys = expected.keys; akeys = actual.keys
290: assert_block( errmsg ) {
291: diffs = []
292:
293: # XOR the arrays and make a diff for each one
294: ((ekeys + akeys) - (ekeys & akeys)).each do |key|
295: if ekeys.include?( key )
296: diffs << "missing key %p" % [key]
297: else
298: diffs << "extra key %p" % [key]
299: end
300: end
301:
302: unless diffs.empty?
303: errmsg += "\n" + diffs.join("; ")
304: return false
305: else
306: return true
307: end
308: }
309: rescue Test::Unit::AssertionFailedError => err
310: cutframe = err.backtrace.reverse.find {|frame|
311: /assert_hash_equal/ =~ frame
312: }
313: firstIdx = (err.backtrace.rindex( cutframe )||0) + 1
314: Kernel.raise( err, err.message, err.backtrace[firstIdx..-1] )
315: end
Try to force garbage collection to start.
# File lib/arrow/testcase.rb, line 502
502: def collectGarbage
503: a = []
504: 1000.times { a << {} }
505: a = nil
506: GC.start
507: end
Compare two hashes for content, returning a list of their differences as descriptions. An empty Array return-value means they were the same.
# File lib/arrow/testcase.rb, line 258
258: def compare_hashes( hash1, hash2, subkeys=nil )
259: diffs = []
260: seenKeys = []
261:
262: hash1.each {|k,v|
263: if !hash2.key?( k )
264: diffs << "missing %p pair" % k
265: elsif hash1[k].is_a?( Hash ) && hash2[k].is_a?( Hash )
266: diffs.push( compare_hashes(hash1[k], hash2[k]) )
267: elsif hash2[k] != hash1[k]
268: diffs << "value for %p expected to be %p, but was %p" %
269: [ k, hash1[k], hash2[k] ]
270: else
271: seenKeys << k
272: end
273: }
274:
275: extraKeys = (hash2.keys - hash1.keys)
276: diffs << "extra key/s: #{extraKeys.join(', ')}" unless extraKeys.empty?
277:
278: return diffs.flatten
279: end
Instance alias for the like-named class method
# File lib/arrow/testcase.rb, line 467
467: def debugMsg( *msgs )
468: self.class.debugMsg( *msgs )
469: end
Turn off the stupid ‘No tests were specified‘
# File lib/arrow/testcase.rb, line 227
227: def default_test; end
Return a separator line made up of length of the specified char.
# File lib/arrow/testcase.rb, line 474
474: def hrule( length=75, char="-" )
475: return (char * length ) + "\n"
476: end
Return a section delimited by hrules with the specified caption and content.
# File lib/arrow/testcase.rb, line 480
480: def hruleSection( content, caption='' )
481: caption << ' ' unless caption.empty?
482: return caption +
483: hrule( 75 - caption.length ) +
484: content.chomp + "\n" +
485: hrule()
486: end
Instance alias for the like-named class method.
# File lib/arrow/testcase.rb, line 455
455: def message( *msgs )
456: self.class.message( *msgs )
457: end
Output a header for delimiting tests
# File lib/arrow/testcase.rb, line 490
490: def printTestHeader( desc )
491: return unless $VERBOSE || $DEBUG
492: message "%s>>> %s <<<%s" %
493: [ ansiCode('bold','yellow','on_blue'), desc, ansiCode('reset') ]
494: end
Output the specified promptString as a prompt (in green) and return the user‘s input with leading and trailing spaces removed.
# File lib/arrow/testcase.rb, line 547
547: def prompt( promptString )
548: promptString.chomp!
549: return readline( ansiCode('bold', 'green') + "#{promptString}: " +
550: ansiCode('reset') ).strip
551: end
Prompt the user with the given promptString via #prompt, substituting the given default if the user doesn‘t input anything.
# File lib/arrow/testcase.rb, line 557
557: def promptWithDefault( promptString, default )
558: response = prompt( "%s [%s]" % [ promptString, default ] )
559: if response.empty?
560: return default
561: else
562: return response
563: end
564: end
Output the name of the test as it‘s running if in verbose mode.
# File lib/arrow/testcase.rb, line 518
518: def run( result )
519: $stderr.puts self.name if $VERBOSE || $DEBUG
520:
521: # Support debugging for individual tests
522: olddb = nil
523: if $DebugPattern && $DebugPattern =~ @method_name
524: Arrow::Logger.global.outputters <<
525: Arrow::Logger::Outputter.create( 'file:stderr' )
526: Arrow::Logger.global.level = :debug
527:
528: olddb = $DEBUG
529: $DEBUG = true
530: end
531:
532: super
533:
534: unless olddb.nil?
535: $DEBUG = olddb
536: Arrow::Logger.global.outputters.clear
537: end
538: end
Run dynamically-added setup methods
# File lib/arrow/testcase.rb, line 180
180: def setup( *args )
181: if self.class < Arrow::TestCase
182: self.class.setupMethods.each {|sblock|
183: self.send( sblock )
184: }
185: end
186: end
Skip the current step (called from #setup) with the reason given.
# File lib/arrow/testcase.rb, line 202
202: def skip( reason=nil )
203: if reason
204: msg = "Skipping %s: %s" % [ @method_name, reason ]
205: else
206: msg = "Skipping %s: No reason given." % @method_name
207: end
208:
209: $stderr.puts( msg ) if $VERBOSE
210: @method_name = :skipped_test
211: end
Run dynamically-added teardown methods
# File lib/arrow/testcase.rb, line 191
191: def teardown( *args )
192: if self.class < Arrow::TestCase
193: self.class.teardownMethods.each {|tblock|
194: self.send( tblock )
195: }
196: end
197: end
--- SEC00176
--- ""
--- - name: setupMethods rw: RW a_desc: "" - name: teardownMethods rw: RW a_desc: ""
---
- methods:
- visibility: public
aref: M000239
name: addSetupBlock
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 153</span>\n\
153: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">addSetupBlock</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
154: <span class=\"ruby-ivar\">@@methodCounter</span> <span class=\"ruby-operator\">+=</span> <span class=\"ruby-value\">1</span>\n\
155: <span class=\"ruby-identifier\">newMethodName</span> = <span class=\"ruby-node\">"setup_#{@@methodCounter}"</span>.<span class=\"ruby-identifier\">intern</span>\n\
156: <span class=\"ruby-identifier\">define_method</span>( <span class=\"ruby-identifier\">newMethodName</span>, <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
157: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">setupMethods</span>.<span class=\"ruby-identifier\">push</span> <span class=\"ruby-identifier\">newMethodName</span>\n\
158: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Append a <a href="TestCase.html#M000241">setup</a> block for the current
testcase
</p>
params: ( &block )
- visibility: public
aref: M000240
name: addTeardownBlock
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 162</span>\n\
162: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">addTeardownBlock</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
163: <span class=\"ruby-ivar\">@@methodCounter</span> <span class=\"ruby-operator\">+=</span> <span class=\"ruby-value\">1</span>\n\
164: <span class=\"ruby-identifier\">newMethodName</span> = <span class=\"ruby-node\">"teardown_#{@@methodCounter}"</span>.<span class=\"ruby-identifier\">intern</span>\n\
165: <span class=\"ruby-identifier\">define_method</span>( <span class=\"ruby-identifier\">newMethodName</span>, <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
166: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">teardownMethods</span>.<span class=\"ruby-identifier\">unshift</span> <span class=\"ruby-identifier\">newMethodName</span>\n\
167: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Prepend a <a href="TestCase.html#M000243">teardown</a> block for the
current testcase
</p>
params: ( &block )
- visibility: public
aref: M000236
name: ansiCode
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 122</span>\n\
122: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">ansiCode</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">attributes</span> )\n\
123: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-value str\">''</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-regexp re\">/(?:xterm(?:-color)?|eterm|linux)/i</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-constant\">ENV</span>[<span class=\"ruby-value str\">'TERM'</span>]\n\
124: \n\
125: <span class=\"ruby-identifier\">attr</span> = <span class=\"ruby-identifier\">attributes</span>.<span class=\"ruby-identifier\">collect</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">a</span><span class=\"ruby-operator\">|</span>\n\
126: <span class=\"ruby-constant\">AnsiAttributes</span>[<span class=\"ruby-identifier\">a</span>] <span class=\"ruby-operator\">?</span> <span class=\"ruby-constant\">AnsiAttributes</span>[<span class=\"ruby-identifier\">a</span>] <span class=\"ruby-operator\">:</span> <span class=\"ruby-keyword kw\">nil</span>\n\
127: }.<span class=\"ruby-identifier\">compact</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-value str\">';'</span>)\n\
128: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">attr</span>.<span class=\"ruby-identifier\">empty?</span> \n\
129: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-value str\">''</span>\n\
130: <span class=\"ruby-keyword kw\">else</span>\n\
131: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-value str\">"\\e[%sm"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-identifier\">attr</span>\n\
132: <span class=\"ruby-keyword kw\">end</span>\n\
133: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns a <a href="../String.html">String</a> containing the specified ANSI
escapes suitable for inclusion in another string. The <tt>attributes</tt>
should be one or more of the keys of AnsiAttributes.
</p>
params: ( *attributes )
- visibility: public
aref: M000237
name: debugMsg
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 138</span>\n\
138: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">debugMsg</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">msgs</span> )\n\
139: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">$DEBUG</span>\n\
140: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">message</span> <span class=\"ruby-value str\">"%sDEBUG>>> %s %s"</span> <span class=\"ruby-operator\">%</span>\n\
141: [ <span class=\"ruby-identifier\">ansiCode</span>(<span class=\"ruby-value str\">'dark'</span>, <span class=\"ruby-value str\">'white'</span>), <span class=\"ruby-identifier\">msgs</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-value str\">''</span>), <span class=\"ruby-identifier\">ansiCode</span>(<span class=\"ruby-value str\">'reset'</span>) ]\n\
142: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Output the specified <tt>msgs</tt> joined together to <tt>STDERR</tt> if
<tt>$DEBUG</tt> is set.
</p>
params: ( *msgs )
- visibility: public
aref: M000235
name: inherited
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 106</span>\n\
106: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">inherited</span>( <span class=\"ruby-identifier\">klass</span> )\n\
107: <span class=\"ruby-identifier\">klass</span>.<span class=\"ruby-identifier\">module_eval</span> {\n\
108: <span class=\"ruby-ivar\">@setupMethods</span> = []\n\
109: <span class=\"ruby-ivar\">@teardownMethods</span> = []\n\
110: \n\
111: <span class=\"ruby-keyword kw\">class</span> <span class=\"ruby-operator\"><<</span> <span class=\"ruby-keyword kw\">self</span>\n\
112: <span class=\"ruby-identifier\">attr_accessor</span> <span class=\"ruby-identifier\">:setupMethods</span>\n\
113: <span class=\"ruby-identifier\">attr_accessor</span> <span class=\"ruby-identifier\">:teardownMethods</span>\n\
114: <span class=\"ruby-keyword kw\">end</span>\n\
115: }\n\
116: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Inheritance callback — adds @setupMethods and @teardownMethods ivars
and accessors to the inheriting class.
</p>
params: ( klass )
- visibility: public
aref: M000238
name: message
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 147</span>\n\
147: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">message</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">msgs</span> )\n\
148: <span class=\"ruby-identifier\">$stderr</span>.<span class=\"ruby-identifier\">puts</span> <span class=\"ruby-identifier\">msgs</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-value str\">''</span>)\n\
149: <span class=\"ruby-identifier\">$stderr</span>.<span class=\"ruby-identifier\">flush</span>\n\
150: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Output the specified <tt>msgs</tt> joined together to <tt>STDOUT</tt>.
</p>
params: ( *msgs )
category: Class
type: Public
- methods:
- visibility: public
aref: M000246
name: addSetupBlock
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 219</span>\n\
219: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">addSetupBlock</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> ); <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">addSetupBlock</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> ); <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Add the specified <tt>block</tt> to the code that gets executed by <a
href="TestCase.html#M000241">#setup</a>.
</p>
params: ( &block )
- visibility: public
aref: M000247
name: addTeardownBlock
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 223</span>\n\
223: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">addTeardownBlock</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> ); <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">addTeardownBlock</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> ); <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Add the specified <tt>block</tt> to the code that gets executed by <a
href="TestCase.html#M000243">#teardown</a>.
</p>
params: ( &block )
- visibility: public
aref: M000261
name: ansiCode
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 461</span>\n\
461: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">ansiCode</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">attributes</span> )\n\
462: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">ansiCode</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">attributes</span> )\n\
463: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Instance-alias for the like-named class method
</p>
params: ( *attributes )
- visibility: public
aref: M000259
name: assert_has_instance_method
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 434</span>\n\
434: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">assert_has_instance_method</span>( <span class=\"ruby-identifier\">klass</span>, <span class=\"ruby-identifier\">meth</span> )\n\
435: <span class=\"ruby-identifier\">msg</span> = <span class=\"ruby-value str\">"<%s> expected to define instance method #%s"</span> <span class=\"ruby-operator\">%</span>\n\
436: [ <span class=\"ruby-identifier\">klass</span>, <span class=\"ruby-identifier\">meth</span> ]\n\
437: <span class=\"ruby-identifier\">assert_block</span>( <span class=\"ruby-identifier\">msg</span> ) {\n\
438: <span class=\"ruby-identifier\">klass</span>.<span class=\"ruby-identifier\">instance_methods</span>.<span class=\"ruby-identifier\">include?</span>( <span class=\"ruby-identifier\">meth</span>.<span class=\"ruby-identifier\">to_s</span> )\n\
439: }\n\
440: <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Test</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Unit</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">AssertionFailedError</span> =<span class=\"ruby-operator\">></span> <span class=\"ruby-identifier\">err</span>\n\
441: <span class=\"ruby-identifier\">cutframe</span> = <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">reverse</span>.<span class=\"ruby-identifier\">find</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">frame</span><span class=\"ruby-operator\">|</span>\n\
442: <span class=\"ruby-regexp re\">/assert_has_instance_method/</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-identifier\">frame</span>\n\
443: }\n\
444: <span class=\"ruby-identifier\">firstIdx</span> = (<span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">rindex</span>( <span class=\"ruby-identifier\">cutframe</span> )<span class=\"ruby-operator\">||</span><span class=\"ruby-value\">0</span>) <span class=\"ruby-operator\">+</span> <span class=\"ruby-value\">1</span>\n\
445: <span class=\"ruby-constant\">Kernel</span>.<span class=\"ruby-identifier\">raise</span>( <span class=\"ruby-identifier\">err</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">message</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>[<span class=\"ruby-identifier\">firstIdx</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">-1</span>] )\n\
446: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Assert that the specified <tt>klass</tt> defines the specified instance
method <tt>meth</tt>.
</p>
params: ( klass, meth )
- visibility: public
aref: M000257
name: assert_has_ivar
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 399</span>\n\
399: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">assert_has_ivar</span>( <span class=\"ruby-identifier\">sym</span>, <span class=\"ruby-identifier\">object</span> )\n\
400: <span class=\"ruby-identifier\">sym</span> = <span class=\"ruby-node\">"@#{sym}"</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-regexp re\">/^@/</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-identifier\">sym</span>.<span class=\"ruby-identifier\">to_s</span>\n\
401: <span class=\"ruby-identifier\">msg</span> = <span class=\"ruby-value str\">"Object <%s> expected to have an instance variable <%s>"</span> <span class=\"ruby-operator\">%</span>\n\
402: [ <span class=\"ruby-identifier\">object</span>.<span class=\"ruby-identifier\">inspect</span>, <span class=\"ruby-identifier\">sym</span> ]\n\
403: <span class=\"ruby-identifier\">assert_block</span>( <span class=\"ruby-identifier\">msg</span> ) {\n\
404: <span class=\"ruby-identifier\">object</span>.<span class=\"ruby-identifier\">instance_variables</span>.<span class=\"ruby-identifier\">include?</span>( <span class=\"ruby-identifier\">sym</span>.<span class=\"ruby-identifier\">to_s</span> )\n\
405: }\n\
406: <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Test</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Unit</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">AssertionFailedError</span> =<span class=\"ruby-operator\">></span> <span class=\"ruby-identifier\">err</span>\n\
407: <span class=\"ruby-identifier\">cutframe</span> = <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">reverse</span>.<span class=\"ruby-identifier\">find</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">frame</span><span class=\"ruby-operator\">|</span>\n\
408: <span class=\"ruby-regexp re\">/assert_has_ivar/</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-identifier\">frame</span>\n\
409: }\n\
410: <span class=\"ruby-identifier\">firstIdx</span> = (<span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">rindex</span>( <span class=\"ruby-identifier\">cutframe</span> )<span class=\"ruby-operator\">||</span><span class=\"ruby-value\">0</span>) <span class=\"ruby-operator\">+</span> <span class=\"ruby-value\">1</span>\n\
411: <span class=\"ruby-constant\">Kernel</span>.<span class=\"ruby-identifier\">raise</span>( <span class=\"ruby-identifier\">err</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">message</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>[<span class=\"ruby-identifier\">firstIdx</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">-1</span>] )\n\
412: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Assert that the specified <tt>object</tt> has an instance variable which
matches the specified <tt>sym</tt>. The ’@’ at the beginning of
the <tt>sym</tt> will be prepended if not present.
</p>
params: ( sym, object )
- visibility: public
aref: M000249
name: assert_hash_equal
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 234</span>\n\
234: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">assert_hash_equal</span>( <span class=\"ruby-identifier\">expected</span>, <span class=\"ruby-identifier\">actual</span>, <span class=\"ruby-identifier\">msg</span>=<span class=\"ruby-value str\">""</span> )\n\
235: <span class=\"ruby-identifier\">errmsg</span> = <span class=\"ruby-value str\">"Expected hash <%p> to be equal to <%p>"</span> <span class=\"ruby-operator\">%</span> [<span class=\"ruby-identifier\">expected</span>, <span class=\"ruby-identifier\">actual</span>]\n\
236: <span class=\"ruby-identifier\">errmsg</span> <span class=\"ruby-operator\">+=</span> <span class=\"ruby-node\">": #{msg}"</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">msg</span>.<span class=\"ruby-identifier\">empty?</span>\n\
237: \n\
238: <span class=\"ruby-identifier\">assert_block</span>( <span class=\"ruby-identifier\">errmsg</span> ) {\n\
239: <span class=\"ruby-identifier\">diffs</span> = <span class=\"ruby-identifier\">compare_hashes</span>( <span class=\"ruby-identifier\">expected</span>, <span class=\"ruby-identifier\">actual</span> )\n\
240: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">diffs</span>.<span class=\"ruby-identifier\">empty?</span>\n\
241: <span class=\"ruby-identifier\">errmsg</span> <span class=\"ruby-operator\">+=</span> <span class=\"ruby-value str\">": "</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">diffs</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-value str\">"; "</span>)\n\
242: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">false</span>\n\
243: <span class=\"ruby-keyword kw\">else</span>\n\
244: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">true</span>\n\
245: <span class=\"ruby-keyword kw\">end</span>\n\
246: }\n\
247: <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Test</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Unit</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">AssertionFailedError</span> =<span class=\"ruby-operator\">></span> <span class=\"ruby-identifier\">err</span>\n\
248: <span class=\"ruby-identifier\">cutframe</span> = <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">reverse</span>.<span class=\"ruby-identifier\">find</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">frame</span><span class=\"ruby-operator\">|</span>\n\
249: <span class=\"ruby-regexp re\">/assert_hash_equal/</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-identifier\">frame</span>\n\
250: }\n\
251: <span class=\"ruby-identifier\">firstIdx</span> = (<span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">rindex</span>( <span class=\"ruby-identifier\">cutframe</span> )<span class=\"ruby-operator\">||</span><span class=\"ruby-value\">0</span>) <span class=\"ruby-operator\">+</span> <span class=\"ruby-value\">1</span>\n\
252: <span class=\"ruby-constant\">Kernel</span>.<span class=\"ruby-identifier\">raise</span>( <span class=\"ruby-identifier\">err</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">message</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>[<span class=\"ruby-identifier\">firstIdx</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">-1</span>] )\n\
253: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Test Hashes for equivalent content
</p>
params: ( expected, actual, msg="" )
- visibility: public
aref: M000253
name: assert_include
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/testcase.rb, line 333</span>\n\
333: <spa