0

我正在尝试指定一个通过 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这个规范传递了什么。无论如何我都想授权,因为这是我在实际为模型补水之前需要跳的圈。

这些存根似乎没有截获帖子,我不明白如何调试它。

任何提示表示赞赏!

谢谢

4

0 回答 0