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

Commit

Permalink
Created step definitions for request and response header
Browse files Browse the repository at this point in the history
  • Loading branch information
stekycz committed Mar 14, 2014
1 parent 153b8ea commit c041026
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions features/MachinesCollection.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Feature: Machines collection

Scenario: Create a Machine
When I do action Machines > Machines collection > Create a Machine
And the request message header Accept is application/json
And the request message body is JSON
"""
{
Expand All @@ -17,6 +18,7 @@ Feature: Machines collection
}
"""
Then It should be Accepted (202)
And the response message header Content-Encoding is none
And the response message body is JSON
"""
{
Expand All @@ -26,7 +28,9 @@ Feature: Machines collection

Scenario: Retrieve all Machines
When I do action Machines > Machines collection > Retrieve all Machines
And the request message header Accept is application/json
Then It should be Ok
And the response message header Content-Encoding is none
And the response message body is JSON
"""
[{
Expand Down
16 changes: 12 additions & 4 deletions src/step-definitions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,27 @@ class ApiBlueprintStepDefinitionsWrapper
@reset()
@setAction action, callback, callback.fail

this.When /^the request message body is(?: (\w+))?$/, (contentType, body, callback) ->
this.When /^the request message header ([\w-]+) is (.*)$/, (header, value, callback) ->
@reset()
@getRequest().setHeader header, value
callback()

this.When /^the request message body is(?: ([\w-]+))?$/, (contentType, body, callback) ->
@reset()
@getRequest().setHeader 'Content-Type', contentTypeTranslate(contentType)
@getRequest().setBody body

callback()

this.Then /It should be ([^()]+)(?: \((\d+)\))?$/, (name, code, callback) ->
this.Then /^It should be ([^()]+)(?: \((\d+)\))?$/, (name, code, callback) ->
code = statusCodeTranslate name if !code
@expectedResponse.setStatusCode code ? parseInt(code)
@processRequest callback, callback.fail

this.Then /^the response message body is(?: (\w+))?$/, (contentType, body, callback) ->
this.Then /^the response message header ([\w-]+) is (.*)$/, (header, value, callback) ->
@expectedResponse.setHeader header, value
@processRequest callback, callback.fail

this.Then /^the response message body is(?: ([\w-]+))?$/, (contentType, body, callback) ->
@expectedResponse.setHeader 'Content-Type', contentTypeTranslate(contentType)
@expectedResponse.setBody body
@processRequest callback, callback.fail
Expand Down
2 changes: 2 additions & 0 deletions test/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ app = express()

app.post '/machines', (req, res) ->
res.setHeader 'Content-Type', 'application/json'
res.setHeader 'Content-Encoding', 'none'
response =
message: "Accepted"
res.send 202, response

app.get '/machines', (req, res) ->
res.setHeader 'Content-Type', 'application/json'
res.setHeader 'Content-Encoding', 'none'
machine =
_id: '52341870ed55224b15ff07ef'
type: 'bulldozer'
Expand Down

0 comments on commit c041026

Please sign in to comment.