Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more kind of object in mock #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/savon/spec/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def with(body = nil, &block)
def returns(response = nil)
http = case response
when Symbol then { :body => Fixture[action, response] }
when Hash then response
else response
end

Savon.config.hooks.define(:spec_response, :soap_request) do |_, request|
Expand Down Expand Up @@ -80,9 +80,15 @@ def action=(action)

def respond_with(http = {})
defaults = { :code => 200, :headers => {}, :body => "" }
http = defaults.merge(http)

HTTPI::Response.new(http[:code], http[:headers], http[:body])
case http
when Hash
http = defaults.merge(http)
HTTPI::Response.new(http[:code], http[:headers], http[:body])
when HTTPI::Response
http
when Savon::SOAP::Response
http.http
end
end

# Extracted from CoreExt of Savon 0.9.9
Expand Down
56 changes: 56 additions & 0 deletions spec/savon/spec/mock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,62 @@

end

context "with a HTTPI::Response" do

let(:response) do
client.request(:get_user)
end

let(:http_response) do
HTTPI::Response.new(201, { "Set-Cookie" => "ID=1; Max-Age=3600;" }, "<with>cookie</with>" )
end

before do
savon.expects(:get_user).returns(http_response)
end

it "returns the given response code" do
response.http.code.should == http_response.code
end

it "returns the given response headers" do
response.http.headers.should == http_response.headers
end

it "returns the given response body" do
response.http.body.should == http_response.body
end

end

context "with a Savon::SOAP::Response" do

let(:response) do
client.request(:get_user)
end

let(:savon_response) do
Savon::SOAP::Response.new(double(:config, :raise_errors => false), HTTPI::Response.new(201, { "Set-Cookie" => "ID=1; Max-Age=3600;" }, "<with>cookie</with>" ))
end

before do
savon.expects(:get_user).returns(savon_response)
end

it "returns the given response code" do
response.http.code.should == savon_response.http.code
end

it "returns the given response headers" do
response.http.headers.should == savon_response.http.headers
end

it "returns the given response body" do
response.http.body.should == savon_response.http.body
end

end

end

end