forked from loafle/openapi-generator-original
Add test cases for Response#deserialize
This commit is contained in:
parent
4c8c6c3880
commit
36f0ed6d0c
@ -8,7 +8,6 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
end
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
||||||
VCR.use_cassette('pet_resource', :record => :new_episodes) do
|
VCR.use_cassette('pet_resource', :record => :new_episodes) do
|
||||||
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/10002")
|
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/10002")
|
||||||
end
|
end
|
||||||
@ -18,8 +17,10 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
|
|
||||||
describe "initialization" do
|
describe "initialization" do
|
||||||
it "sets body" do
|
it "sets body" do
|
||||||
@response.body.class.should == Hash
|
@response.body.should be_a(String)
|
||||||
@response.body.has_key?(:'name').should == true
|
data = JSON.parse(@response.body)
|
||||||
|
data.should be_a(Hash)
|
||||||
|
data['id'].should == 10002
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets code" do
|
it "sets code" do
|
||||||
@ -32,7 +33,6 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "format" do
|
describe "format" do
|
||||||
|
|
||||||
it "recognizes json" do
|
it "recognizes json" do
|
||||||
@response.format.should == 'json'
|
@response.format.should == 'json'
|
||||||
@response.json?.should == true
|
@response.json?.should == true
|
||||||
@ -47,11 +47,9 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
@response.format.should == 'xml'
|
@response.format.should == 'xml'
|
||||||
@response.xml?.should == true
|
@response.xml?.should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "prettiness" do
|
describe "prettiness" do
|
||||||
|
|
||||||
it "has a pretty json body" do
|
it "has a pretty json body" do
|
||||||
@response.pretty_body.should =~ /\{.*\}/
|
@response.pretty_body.should =~ /\{.*\}/
|
||||||
end
|
end
|
||||||
@ -59,7 +57,26 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
it "has pretty headers" do
|
it "has pretty headers" do
|
||||||
@response.pretty_headers.should =~ /\{.*\}/
|
@response.pretty_headers.should =~ /\{.*\}/
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "deserialize" do
|
||||||
|
it "handles Hash<String, String>" do
|
||||||
|
@response.stub(:body) { '{"message": "Hello"}' }
|
||||||
|
data = @response.deserialize('Hash<String, String>')
|
||||||
|
data.should be_a(Hash)
|
||||||
|
data.should == {:message => 'Hello'}
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles Hash<String, Pet>" do
|
||||||
|
json = @response.body
|
||||||
|
@response.stub(:body) { "{\"pet\": #{json}}" }
|
||||||
|
data = @response.deserialize('Hash<String, Pet>')
|
||||||
|
data.should be_a(Hash)
|
||||||
|
data.keys.should == [:pet]
|
||||||
|
pet = data[:pet]
|
||||||
|
pet.should be_a(SwaggerClient::Pet)
|
||||||
|
pet.id.should == 10002
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user