2015-12-13 63 views
1

我正在查看Savon的測試文檔here,我不明白髮生了什麼事情。我相當新的測試模擬和存根,也許這就是問題所在。這裏是這樣的例子:我不明白savon的測試

require "spec_helper" 

# require the helper module 
require "savon/mock/spec_helper" 

describe AuthenticationService do 
    # include the helper module 
    include Savon::SpecHelper 

    # set Savon in and out of mock mode 
    before(:all) { savon.mock! } 
    after(:all) { savon.unmock! } 

    describe "#authenticate" do 
    it "authenticates the user with the service" do 
     message = { username: "luke", password: "secret" } 
     fixture = File.read("spec/fixtures/authentication_service/authenticate.xml") 

     # set up an expectation 
     savon.expects(:authenticate).with(message: message).returns(fixture) 

     # call the service 
     service = AuthenticationService.new 
     response = service.authenticate(message) 

     expect(response).to be_successful 
    end 
    end 
end 

我知道我們設置了夾具的期望值,即響應應該是什麼。

然後,我們調用服務並獲得響應。我的問題是: 1.是否有真正的呼叫? 2.這個迴應是真實的迴應嗎? 3.有人可以試着爲我解釋這個總體嗎?

乾杯

回答

0

不會進行遠程請求。由於您嘲笑authenticate,響應將會短路到您指定的值。但是,其他一些初步請求可能會首先發生,例如WSDL的GET。