我在我的规范中注册了这个存根:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.<name>.MapsActivity" />
当我运行测试时,我收到以下错误消息:
您可以使用以下代码段存储此请求:
stub_request(:post, "https://sandbox.usaepay.com/gate").
with(:body => {"UMaccount"=>nil, "UMaccounttype"=>nil, "UMaddcustomer"=>nil, "UMallowPartialAuth"=>nil, "UMamount"=>"123.45 ", "UMauthCode"=>nil, "UMauthExpireDays"=>nil, "UMauxonus"=>nil, "UMbillamount"=>nil, "UMbillcity"=>nil, "UMbillcompany"=>nil, "UMbillcountry"=>nil, "UMbillfname"=>nil, "UMbilllname"=>nil, "UMbillphone"=>nil, "UMbillsourcekey"=>nil, "UMbillstate"=>nil, "UMbillstreet"=>nil, "UMbillstreet2"=>nil, "UMbilltax"=>nil, "UMbillzip"=>nil, "UMcard"=>"4000100011112224", "UMcardauth"=>nil, "UMcardpresent"=>"false", "UMcavv"=>nil, "UMcheckformat"=>nil, "UMcheckimageback"=>nil, "UMcheckimageencoding"=>"base64", "UMcheckimagefront"=>nil, "UMchecknum"=>nil, "UMclerk"=>nil, "UMcommand"=>"sale", "UMcomments"=>nil, "UMcontactless"=>nil, "UMcurrency"=>nil, "UMcustemail"=>nil, "UMcustid"=>nil, "UMcustreceipt"=>nil, "UMcustreceiptname"=>nil, "UMcvv2"=>" 123 ", "UMdescription"=>"Payment for Job #2015011", "UMdiscount"=>nil, "UMdlnum"=>nil, "UMdlstate"=>nil, "UMdukpt"=>nil, "UMeci"=>nil, "UMemail"=>nil, "UMepcCode"=>nil, "UMexpir"=>"0919", "UMexpire"=>nil, "UMfax"=>nil, "UMhash"=>"s/201611182063/8bfd2a8b4f07fc07d63e0f7f652df1295e96bb50/n", "UMifAuthExpired"=>nil, "UMignoreDuplicate"=>nil, "UMinventorylocation"=>nil, "UMinvoice"=>nil, "UMip"=>nil, "UMkey"=>"_MobxK18CP42k6RfKjYnl7yve7W4dr4X", "UMmagstripe"=>nil, "UMmagsupport"=>nil, "UMname"=>"Some Guy", "UMnontaxable"=>nil, "UMnumleft"=>nil, "UMorderid"=>"2015011", "UMpares"=>nil, "UMponum"=>nil, "UMrecurring"=>nil, "UMrefNum"=>nil, "UMresttable"=>nil, "UMrouting"=>nil, "UMsaveCard"=>nil, "UMschedule"=>nil, "UMshipcity"=>nil, "UMshipcompany"=>nil, "UMshipcountry"=>nil, "UMshipfname"=>nil, "UMshiplname"=>nil, "UMshipphone"=>nil, "UMshipping"=>nil, "UMshipstate"=>nil, "UMshipstreet"=>nil, "UMshipstreet2"=>nil, "UMshipzip"=>nil, "UMsignature"=>nil, "UMsoftware"=>"USAePay RUBY API v. 1.0.2", "UMssn"=>nil, "UMstart"=>nil, "UMstreet"=>"1234 Anywhere Lane", "UMsubtotal"=>nil, "UMtax"=>nil, "UMtermtype"=>nil, "UMtestmode"=>nil, "UMtimeout"=>"45", "UMtip"=>nil, "UMtranterm"=>nil, "UMwebsite"=>nil, "UMxid"=>nil, "UMzip"=>"90210"},
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
to_return(:status => 200, :body => "", :headers => {})
注意注册存根如何没有提及&#34; .to_return&#34;部分 - 尽管在我的stub_request中已明确定义
之前有没有人遇到过Rspec这个问题?
使用了rspec和依赖版本:
stub_request(:post, "https://sandbox.usaepay.com/gate").
with(:body => {"UMaccount"=>nil, "UMaccounttype"=>nil, "UMaddcustomer"=>nil, "UMallowPartialAuth"=>nil, "UMamount"=>"123.45 ", "UMauthCode"=>nil, "UMauthExpireDays"=>nil, "UMauxonus"=>nil, "UMbillamount"=>nil, "UMbillcity"=>nil, "UMbillcompany"=>nil, "UMbillcountry"=>nil, "UMbillfname"=>nil, "UMbilllname"=>nil, "UMbillphone"=>nil, "UMbillsourcekey"=>nil, "UMbillstate"=>nil, "UMbillstreet"=>nil, "UMbillstreet2"=>nil, "UMbilltax"=>nil, "UMbillzip"=>nil, "UMcard"=>"4000100011112224", "UMcardauth"=>nil, "UMcardpresent"=>"false", "UMcavv"=>nil, "UMcheckformat"=>nil, "UMcheckimageback"=>nil, "UMcheckimageencoding"=>"base64", "UMcheckimagefront"=>nil, "UMchecknum"=>nil, "UMclerk"=>nil, "UMcommand"=>"sale", "UMcomments"=>nil, "UMcontactless"=>nil, "UMcurrency"=>nil, "UMcustemail"=>nil, "UMcustid"=>nil, "UMcustreceipt"=>nil, "UMcustreceiptname"=>nil, "UMcvv2"=>" 123 ", "UMdescription"=>"Payment for Job #2015011", "UMdiscount"=>nil, "UMdlnum"=>nil, "UMdlstate"=>nil, "UMdukpt"=>nil, "UMeci"=>nil, "UMemail"=>nil, "UMepcCode"=>nil, "UMexpir"=>"0919", "UMexpire"=>nil, "UMfax"=>nil, "UMhash"=>"s/2016111820672/b0175954f0ce709aa2899e45a1329c6fb63905d5/n", "UMifAuthExpired"=>nil, "UMignoreDuplicate"=>nil, "UMinventorylocation"=>nil, "UMinvoice"=>nil, "UMip"=>nil, "UMkey"=>"_MobxK18CP42k6RfKjYnl7yve7W4dr4X", "UMmagstripe"=>nil, "UMmagsupport"=>nil, "UMname"=>"Some guy", "UMnontaxable"=>nil, "UMnumleft"=>nil, "UMorderid"=>"2015011", "UMpares"=>nil, "UMponum"=>nil, "UMrecurring"=>nil, "UMrefNum"=>nil, "UMresttable"=>nil, "UMrouting"=>nil, "UMsaveCard"=>nil, "UMschedule"=>nil, "UMshipcity"=>nil, "UMshipcompany"=>nil, "UMshipcountry"=>nil, "UMshipfname"=>nil, "UMshiplname"=>nil, "UMshipphone"=>nil, "UMshipping"=>nil, "UMshipstate"=>nil, "UMshipstreet"=>nil, "UMshipstreet2"=>nil, "UMshipzip"=>nil, "UMsignature"=>nil, "UMsoftware"=>"USAePay RUBY API v. 1.0.2", "UMssn"=>nil, "UMstart"=>nil, "UMstreet"=>"1234 Anywhere Lane", "UMsubtotal"=>nil, "UMtax"=>nil, "UMtermtype"=>nil, "UMtestmode"=>nil, "UMtimeout"=>"45", "UMtip"=>nil, "UMtranterm"=>nil, "UMwebsite"=>nil, "UMxid"=>nil, "UMzip"=>"90210"},
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
to_return(:status => 200, :body => "", :headers => {})
registered request stubs:
stub_request(:post, "https://sandbox.usaepay.com/gate").
with(:body => {"UMaccount"=>nil, "UMaccounttype"=>nil, "UMaddcustomer"=>nil, "UMallowPartialAuth"=>nil, "UMamount"=>"123.45 ", "UMauthCode"=>nil, "UMauthExpireDays"=>nil, "UMauxonus"=>nil, "UMbillamount"=>nil, "UMbillcity"=>nil, "UMbillcompany"=>nil, "UMbillcountry"=>nil, "UMbillfname"=>nil, "UMbilllname"=>nil, "UMbillphone"=>nil, "UMbillsourcekey"=>nil, "UMbillstate"=>nil, "UMbillstreet"=>nil, "UMbillstreet2"=>nil, "UMbilltax"=>nil, "UMbillzip"=>nil, "UMcard"=>"4000100011112224", "UMcardauth"=>nil, "UMcardpresent"=>"false", "UMcavv"=>nil, "UMcheckformat"=>nil, "UMcheckimageback"=>nil, "UMcheckimageencoding"=>"base64", "UMcheckimagefront"=>nil, "UMchecknum"=>nil, "UMclerk"=>nil, "UMcommand"=>"sale", "UMcomments"=>nil, "UMcontactless"=>nil, "UMcurrency"=>nil, "UMcustemail"=>nil, "UMcustid"=>nil, "UMcustreceipt"=>nil, "UMcustreceiptname"=>nil, "UMcvv2"=>" 123 ", "UMdescription"=>"Payment for Job #2015011", "UMdiscount"=>nil, "UMdlnum"=>nil, "UMdlstate"=>nil, "UMdukpt"=>nil, "UMeci"=>nil, "UMemail"=>nil, "UMepcCode"=>nil, "UMexpir"=>"0919", "UMexpire"=>nil, "UMfax"=>nil, "UMhash"=>"s/201611182063/8bfd2a8b4f07fc07d63e0f7f652df1295e96bb50/n", "UMifAuthExpired"=>nil, "UMignoreDuplicate"=>nil, "UMinventorylocation"=>nil, "UMinvoice"=>nil, "UMip"=>nil, "UMkey"=>"_MobxK18CP42k6RfKjYnl7yve7W4dr4X", "UMmagstripe"=>nil, "UMmagsupport"=>nil, "UMname"=>" Some Guy", "UMnontaxable"=>nil, "UMnumleft"=>nil, "UMorderid"=>"2015011", "UMpares"=>nil, "UMponum"=>nil, "UMrecurring"=>nil, "UMrefNum"=>nil, "UMresttable"=>nil, "UMrouting"=>nil, "UMsaveCard"=>nil, "UMschedule"=>nil, "UMshipcity"=>nil, "UMshipcompany"=>nil, "UMshipcountry"=>nil, "UMshipfname"=>nil, "UMshiplname"=>nil, "UMshipphone"=>nil, "UMshipping"=>nil, "UMshipstate"=>nil, "UMshipstreet"=>nil, "UMshipstreet2"=>nil, "UMshipzip"=>nil, "UMsignature"=>nil, "UMsoftware"=>"USAePay RUBY API v. 1.0.2", "UMssn"=>nil, "UMstart"=>nil, "UMstreet"=>"1234 Anywhere Lane", "UMsubtotal"=>nil, "UMtax"=>nil, "UMtermtype"=>nil, "UMtestmode"=>nil, "UMtimeout"=>"45", "UMtip"=>nil, "UMtranterm"=>nil, "UMwebsite"=>nil, "UMxid"=>nil, "UMzip"=>"90210"},
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'})
答案 0 :(得分:1)
UMhash
参数在每个请求中都是不同的,您必须定义一个忽略它的存根或确保它在每个测试请求上都相同。例如。如果UMhash取决于时间,则使用timecop冻结时间。
to_return
,因为匹配请求并不重要。 to_return仅用于声明存根响应。
您很可能必须定义匹配某些真实响应的to_return
。