On Apr 19, 2006, at 9:19 PM, bao lee wrote:
class XmlrpcAgent
def create(params)
200
end
end
This is a stub, not a mock.
but the value of the value returned is fixed. which is quite hard
for me
to test the controller when different values are returned from the rpc
call… is there a way to make the number returned dynamic??
Dynamic in
the sense that i can pre-define the returned number in the functional
test case to simulate the different kind of situation that might
arise…
I use the following pattern when I use stubs, taking advantage of
Ruby’s open classes. My flickr interface use open-uri to do its
work, so I inject my own open that will be called before Kernel’s. I
record the passed URIs and give the positional response. This makes
it easy to verify the method DTRT.
class Flickr
attr_accessor :responses, :uris
def open(uri)
@uris << uri
yield StringIO.new(@responses.shift)
end
end
class FlickrTest < Test::Unit::TestCase
#…
def test_find_email
@flickr.responses << <<-EOF
<?xml version="1.0" encoding="utf-8" ?>
drbrain
EOF
nsid = @flickr.find_email :find_email => '[email protected]'
assert_equal 1, @flickr.uris.length
assert_equal 'http://flickr.com/services/rest/?
api_key=API_KEY&find_email=dr
brain%40segment7.net&method=flickr.people.findByEmail’,
@flickr.uris.first
assert_equal '50178138@N00', nsid
end
end
–
Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
http://trackmap.robotcoop.com