问题
I'm trying to spec a client that goes through the following series of calls via XMLRPC:
post (https) myservice.auth.login (with params login, password)
post (http) myservice.items.list (with sessionid from login)
I'm trying to mock these so I don't have to hit a production XMLRPC service, so I did this:
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
Basically, I don't care what is passed into auth
for this spec. I want to authorize anyhow because it's the hoop I need to jump before actually hydrating the model.
These stubs don't seem to be intercepting the posts and I don't understand how I might go about debugging it.
Any hints appreciated!
Thanks
来源:https://stackoverflow.com/questions/20732908/using-webmock-to-mock-xmlrpc-client-in-rspec-rails