Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
Parse swagger example into a hash
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-andrews committed Mar 18, 2015
1 parent 5bdec95 commit 2bd52fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/pacto/formats/swagger/contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def build_examples(response)
default: {
request: {}, # Swagger doesn't have a clear way to capture request examples
response: {
body: response_body
body: response_body.parse
}
}
}
Expand Down
18 changes: 16 additions & 2 deletions spec/unit/pacto/formats/swagger/contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Formats
module Swagger
describe Contract do
let(:swagger_yaml) do
''"
%(
swagger: '2.0'
info:
title: Sample API
Expand All @@ -23,7 +23,15 @@ module Swagger
200:
description: |-
Success.
"''
examples:
application/json: |-
{
"item": {
"id": 45,
"name": "basketball"
}
}
)
end
let(:swagger_definition) do
::Swagger.build(swagger_yaml, format: :yaml)
Expand All @@ -40,6 +48,12 @@ module Swagger
described_class.new(api_operation, file: file)
end

describe 'contract examples' do
let(:example) { contract.examples }
it { expect(example).to be_truthy }
it { expect(example[:default][:response][:body]).to be_a(Hash) }
end

it_behaves_like 'a contract'
end
end
Expand Down

0 comments on commit 2bd52fb

Please sign in to comment.