Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在rspec-rails中使用webmock模拟XMLRPC客户端_Ruby On Rails_Ruby_Rspec_Xml Rpc_Webmock - Fatal编程技术网

Ruby on rails 在rspec-rails中使用webmock模拟XMLRPC客户端

Ruby on rails 在rspec-rails中使用webmock模拟XMLRPC客户端,ruby-on-rails,ruby,rspec,xml-rpc,webmock,Ruby On Rails,Ruby,Rspec,Xml Rpc,Webmock,我试图规范一个通过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

我试图规范一个通过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
require'spec\u helper'
描述项目列表做什么
它“水化物模型”做什么
存根请求(:post'secure api.myservice.com/webservices/xmlrpc/)。
使用(:body=~/myservice.auth.login/m)。
to_返回(:body=>AUTH_XML,:status=>200)。
存根请求(:post'api.myservice.com/webservices/xmlrpc/')。
使用(:body=~/myservice.items.list/m)。
返回(:body=>ITEMLIST\uxml,:status=>200)
预期{ItemList.hydrome\u item\u list}.将(ItemList,:count.)从(0)更改为(3)
终止
终止

ITEMLIST_XML=您正在使用哪个http库?XMLRPC::Client(Ruby std lib版本),它可能使用Net::http。