From: Michael Granger Date: 2003-08-03T19:50:43+09:00 Subject: Re: Anonymous, single instance class creation On Saturday, Aug 2, 2003, at 07:03 America/Denver, Nathaniel Talbott wrote: > require 'test/unit' > > class TC_ParamPrettifier < Test::Unit::TestCase > def test_prettify > cgi = Object.new > def cgi.params > {'param1' => 'value1', 'param2' => 'value2'} > end > > [...] > The basic idea is that I have a class (like CGI) that's a pain to set > up > and/or use, and I want to mock (sham, fake, stub) it. So I create a > regular > old object (ROO... MOO? FOO? GOO? Sorry...) and take advantage of > Ruby's > wonderful dynamic nature to just add the methods that I need for that > test. > I'm just looking for ways to make it easier and/or more concise to do > this. > I guess this isn't more concise, but I use something like this: require 'test/unit' require 'test/unit/mock' class TC_ParamPrettifier < Test::Unit::TestCase def setup @cgi = Test::Unit::MockObject( CGI ).new end def test_prettify @cgi.setReturnValues( :params => [{'param1' => 'value1', 'param2' => 'value2'}] ) assert_equal((< Rubymage, Believer, Architect The FaerieMUD Consortium