Skip to content
This repository has been archived by the owner on Jun 21, 2018. It is now read-only.

Commit

Permalink
Prepared inheritance of request and response from API Blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
stekycz committed Apr 10, 2014
1 parent 9476ad7 commit 1756fce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -7,7 +7,8 @@
"dependencies": {
"cucumber": "~0.4",
"protagonist": "~0.8",
"gavel": "~0.2"
"gavel": "~0.2",
"dredd": "~0.3"
},
"devDependencies": {
"coffee-script": "~1.7",
Expand Down
4 changes: 2 additions & 2 deletions src/request/request-builder.coffee
@@ -1,5 +1,5 @@
class RequestBuilder
constructor: (@host, @port) ->
constructor: (@host, @port, @path) ->
@method = null
@uriTemplate = null
@setBody ''
Expand All @@ -10,7 +10,7 @@ class RequestBuilder
@method = method

setUriTemplate: (uriTemplate) ->
@uriTemplate = uriTemplate
@uriTemplate = @path + uriTemplate

setBody: (body) ->
@body = body
Expand Down
11 changes: 10 additions & 1 deletion src/world.coffee
Expand Up @@ -21,7 +21,10 @@ class World

getRequest: () ->
if !@request? and !@response?
@request = new RequestBuilder @baseUrl['hostname'], @baseUrl['port']
fullPath = ''
if @baseUrl['path'] is not '/'
fullPath = '/' + @baseUrl['path'].replace(/^\/|\/$/g, '')
@request = new RequestBuilder @baseUrl['hostname'], @baseUrl['port'], fullPath
return @request

processRequest: (callback, errorCallback) ->
Expand Down Expand Up @@ -61,6 +64,12 @@ class World
@getRequest().setMethod @structure.action.method
@getRequest().setUriTemplate @structure.resource.uriTemplate

if @structure.action.examples? and @structure.action.examples.length > 0 and @structure.action.examples[0].requests? and @structure.action.examples[0].requests.length > 0
request = @structure.action.examples[0].requests[0]
@getRequest().setBody request.body if request.body?
for key in Object.keys(request.headers)
@getRequest().setHeader key, request.headers[key].value if request.headers[key].value?

success()

module.exports = World

0 comments on commit 1756fce

Please sign in to comment.