我试图通过XMLRPC指定经过以下一系列调用的客户端:
post (https) myservice.auth.login (with params login, password)
post (http) myservice.items.list (with sessionid from login)
我试图嘲笑这些,所以我不必点击生产XMLRPC服务,所以我这样做了:
require 'spec_helper'
describe ItemList do
it "hydrates the model" do
stub_request(:post, 'secure-api.myservice.com/webservices/xmlrpc/').
with(:body =~ /myservice.auth.login/m).
to_return(:body => AUTH_XML, :status => 200).
stub_request(:post, 'api.myservice.com/webservices/xmlrpc/').
with(:body =~ /myservice.items.list/m).
to_return(:body => ITEMLIST_XML, :status => 200)
expect{ItemList.hydrate_item_list}.to change(ItemList, :count).from(0).to(3)
end
end
ITEMLIST_XML=<<EOD
<myserviceResponse sessionid="000123401200002312" membername="abc">
<itemList>
<item itemid="123" name="Faves" public="false" membername="abc" itemcount="30" views="20">
<description>Stuff I like</description>
<keywords>walks, rain, pina colada</keywords>
</item>
<item itemid="124" name="Yuck!" public="false" membername="abc" itemcount="35" views="5">
<description>Stuff I don't like</description>
<keywords>spinach, brussle sprouts, liver</keywords>
</item>
<item itemid="125" name="Project" public="true" membername="def" itemcount="5" views="2">
<description>Brochure images</description>
<keywords></keywords>
</item>
</itemList>
</myserviceResponse>
EOD
AUTH_XML=<<EOD
<myserviceResponse sessionID="10301">
<memberName>redrover</memberName>
</myserviceResponse>
EOD
基本上,我并不关心此规范传递给auth
的内容。无论如何我想要授权,因为它是我在实际保湿模型之前需要跳的箍。
这些存根似乎并没有拦截这些帖子,我也不明白如何调试它。
任何提示都赞赏!
由于