cucumber-rest-bdd 0.3.6 → 0.4.0.pre.107
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +3 -0
- data/README.md +30 -0
- data/STEPS.md +30 -3
- data/cucumber-rest-bdd.gemspec +1 -1
- data/docker-compose.yml +3 -1
- data/features/levels.feature +121 -0
- data/lib/cucumber-rest-bdd/level.rb +47 -0
- data/lib/cucumber-rest-bdd/steps/resource.rb +45 -20
- data/lib/cucumber-rest-bdd/steps/response.rb +2 -2
- data/lib/cucumber-rest-bdd/steps/status.rb +4 -0
- data/server/routes.json +5 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bd9df6fe6b0ed73ad283c752d2e38df0d32c020
|
4
|
+
data.tar.gz: 320037080282cf11d62ea58f8dd08c0ef044943e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 762d3ff737827b4c43b10f468fda469f20309c7b11e57c722ce2b739c3a5f8bab14b55949e02af34b123612de03ced3ec620d50c3d198cbe59c77db89f6af975
|
7
|
+
data.tar.gz: 3f61671e6ec3e5f75dba30bcc180bae6fcf1aea471b12b7bf688101850442db5a113435d5705803cc80a048573bd9e02552811e98567f937f63ed0bb5ea83761
|
data/Dockerfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
FROM ruby
|
2
2
|
|
3
3
|
MAINTAINER "Harry Bragg <harry.bragg@graze.com>"
|
4
|
+
LABEL version="0.4.0" \
|
5
|
+
license="MIT"
|
4
6
|
|
5
7
|
COPY . /usr/local/cucumber-rest-bdd
|
6
8
|
WORKDIR /usr/local/cucumber-rest-bdd
|
@@ -16,5 +18,6 @@ ENV field_camel=false
|
|
16
18
|
ENV resource_single=false
|
17
19
|
ENV cucumber_api_verbose=false
|
18
20
|
ENV data_key=
|
21
|
+
ENV set_parent_id=false
|
19
22
|
|
20
23
|
CMD ["cucumber"]
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[![](https://images.microbadger.com/badges/image/graze/cucumber-rest-bdd.svg)](https://microbadger.com/images/graze/cucumber-rest-bdd "Get your own image badge on microbadger.com")
|
5
5
|
[![](https://images.microbadger.com/badges/version/graze/cucumber-rest-bdd.svg)](https://microbadger.com/images/graze/cucumber-rest-bdd "Get your own version badge on microbadger.com")
|
6
6
|
[![](https://images.microbadger.com/badges/license/graze/cucumber-rest-bdd.svg)](https://microbadger.com/images/graze/cucumber-rest-bdd "Get your own license badge on microbadger.com")
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/cucumber-rest-bdd.svg)](https://badge.fury.io/rb/cucumber-rest-bdd)
|
7
8
|
|
8
9
|
A set of Behavioural tests that can be run against a REST API.
|
9
10
|
|
@@ -37,6 +38,7 @@ The following environment variables modify how this will operate:
|
|
37
38
|
- `field_separator` - (string) the separator used between words by the api
|
38
39
|
- `field_camel` - (bool [`true`|`false`]) does this endpoint use camelCase for fields (default: `false`)
|
39
40
|
- `resource_single` - (bool [`true`|`false`]) if each resource should be singularized or not (default: `false`)
|
41
|
+
- `set_parent_id` - (bool [`true`|`false`]) when creating sub resources, automatically add parent ids
|
40
42
|
|
41
43
|
## Examples
|
42
44
|
|
@@ -57,6 +59,15 @@ And the response has the following attributes:
|
|
57
59
|
| Body | string | quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto |
|
58
60
|
```
|
59
61
|
|
62
|
+
```gherkin
|
63
|
+
Given I am a client
|
64
|
+
When I request the photo "1" for album "1" for user "1"
|
65
|
+
Then the request was successful
|
66
|
+
And the response has the attributes:
|
67
|
+
| attribute | type | value |
|
68
|
+
| title | string | accusamus beatae ad facilis cum similique qui sunt |
|
69
|
+
```
|
70
|
+
|
60
71
|
```gherkin
|
61
72
|
Given I am a client
|
62
73
|
When I request a list of posts with:
|
@@ -160,6 +171,25 @@ And the response has the following attributes:
|
|
160
171
|
| Body | string | bar |
|
161
172
|
```
|
162
173
|
|
174
|
+
If the environment variable: `set_parent_id` is set to `true` then when you create sub resources it will add the level aboves id into the json, otherwise it will rely on the api to do it for you
|
175
|
+
|
176
|
+
```gherkin
|
177
|
+
Given I am a client
|
178
|
+
When I request to create a photo in album "2" for user "1" with:
|
179
|
+
| attribute | type | value |
|
180
|
+
| title | string | foo |
|
181
|
+
Then the comment was created
|
182
|
+
And the response has the attributes:
|
183
|
+
| attribute | type | value |
|
184
|
+
| Album Id | int | 2 |
|
185
|
+
| Title | string | foo |
|
186
|
+
When I request a list of photos for album "2" for user "1"
|
187
|
+
Then the request was successful
|
188
|
+
And one comment has the attributes:
|
189
|
+
| attribute | type | value |
|
190
|
+
| Title | string | foo |
|
191
|
+
```
|
192
|
+
|
163
193
|
### Removal
|
164
194
|
|
165
195
|
```gherkin
|
data/STEPS.md
CHANGED
@@ -86,12 +86,12 @@ Then the request failed because I am unauthorised Then the response status sho
|
|
86
86
|
Then the request failed because it was forbidden Then the response status should be "403"
|
87
87
|
|
88
88
|
Then the request failed because the item was not Then the response status should be "404"
|
89
|
-
found
|
89
|
+
found
|
90
90
|
|
91
91
|
Then the request failed because it was not allowed Then the response status should be "405"
|
92
92
|
|
93
93
|
Then the request failed because there was a Then the response status should be "409"
|
94
|
-
conflict
|
94
|
+
conflict
|
95
95
|
|
96
96
|
Then the request failed because the item has gone Then the response status should be "410"
|
97
97
|
|
@@ -127,7 +127,7 @@ Then two items have have the following attributes: <N/A>
|
|
127
127
|
| Body | string | bar |
|
128
128
|
|
129
129
|
Then more than two items have have the following <N/A>
|
130
|
-
|
130
|
+
attributes:
|
131
131
|
| attribute | type | value |
|
132
132
|
| User Id | integer | 12 |
|
133
133
|
| Title | string | foo |
|
@@ -148,6 +148,33 @@ When I save "User Id" as "user" When I grab "$.userId" as "u
|
|
148
148
|
And I request the user "{user}" And I send a GET request to "http://url/users/{user}"
|
149
149
|
```
|
150
150
|
|
151
|
+
### Nested requests
|
152
|
+
|
153
|
+
```
|
154
|
+
Behavioural Functional
|
155
|
+
--------------------------------------------------- --------------------------------------------------------------
|
156
|
+
When I request a list of comments for post "1" When I send a GET request to "http://url/posts/1/comments"
|
157
|
+
|
158
|
+
When I request the comment "2" for post "3" When I send a GET request to "http://url/posts/2/comments/3"
|
159
|
+
|
160
|
+
When I request the photo "3" in album "4" for user When I send a GET request to
|
161
|
+
"5" "http://url/users/5/albums/4/photos/3"
|
162
|
+
|
163
|
+
When I request a list of photos in album "6" for When I send a GET request to
|
164
|
+
user "7" "http://url/users/7/albums/6/photos"
|
165
|
+
|
166
|
+
When I request to create a comment for post "8" When I send a POST request to "http://url/posts/8/comments"
|
167
|
+
|
168
|
+
When I request to modify the comment "9" for post When I send a PATCH request to
|
169
|
+
"10" "http://url/posts/10/comments/9"
|
170
|
+
|
171
|
+
When I request to set photo "11" in album "12" to: When I set JSON request body to:
|
172
|
+
| attribute | type | value | """
|
173
|
+
| url | string | http://url/image.jpg | {"url":"http://url/image.jpg"}
|
174
|
+
"""
|
175
|
+
And I send a PUT request to "http://url/albums/12/photos/11"
|
176
|
+
```
|
177
|
+
|
151
178
|
### Nested responses
|
152
179
|
|
153
180
|
```
|
data/cucumber-rest-bdd.gemspec
CHANGED
data/docker-compose.yml
CHANGED
@@ -2,8 +2,9 @@ version: '2'
|
|
2
2
|
services:
|
3
3
|
test-server:
|
4
4
|
image: clue/json-server
|
5
|
+
command: --routes /data/routes.json
|
5
6
|
volumes:
|
6
|
-
- ./server
|
7
|
+
- ./server:/data:ro
|
7
8
|
|
8
9
|
runner:
|
9
10
|
image: graze/cucumber-rest-bdd
|
@@ -18,3 +19,4 @@ services:
|
|
18
19
|
- field_camel=true
|
19
20
|
- resource_single=false
|
20
21
|
- data_key=
|
22
|
+
- set_parent_id=true
|
@@ -0,0 +1,121 @@
|
|
1
|
+
Feature: Request multiple levels of REST api
|
2
|
+
As a user
|
3
|
+
I would like to query a url with multiple levels of depth
|
4
|
+
So that I can get all the data from this api
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given I am a client
|
8
|
+
|
9
|
+
Scenario: get single id from sub layer
|
10
|
+
When I request the comment "1" for post "1"
|
11
|
+
Then the request was successful
|
12
|
+
And the response has the attributes:
|
13
|
+
| attribute | type | value |
|
14
|
+
| id | int | 1 |
|
15
|
+
|
16
|
+
Scenario: get list from sub layer
|
17
|
+
When I request a list of comments for post "1"
|
18
|
+
Then the request was successful
|
19
|
+
And the response is a list of more than 4 comments
|
20
|
+
And one comment has the attributes:
|
21
|
+
| attribute | type | value |
|
22
|
+
| id | int | 1 |
|
23
|
+
|
24
|
+
Scenario: multiple sub levels
|
25
|
+
When I request the photo "1" for album "1" for user "1"
|
26
|
+
Then the request was successful
|
27
|
+
And the response has the attributes:
|
28
|
+
| attribute | type | value |
|
29
|
+
| title | string | accusamus beatae ad facilis cum similique qui sunt |
|
30
|
+
|
31
|
+
Scenario: request a list of multiple sub levels
|
32
|
+
When I request a list of photos for album "1" for user "1"
|
33
|
+
Then the request was successful
|
34
|
+
And the response is a list of more than 2 photos
|
35
|
+
And one photo has the attributes:
|
36
|
+
| attribute | type | value |
|
37
|
+
| title | string | accusamus beatae ad facilis cum similique qui sunt |
|
38
|
+
|
39
|
+
Scenario: create a item as a child
|
40
|
+
When I request to create a comment for post "18" with:
|
41
|
+
| attribute | type | value |
|
42
|
+
| Title | string | foo |
|
43
|
+
| Body | string | bar |
|
44
|
+
Then the comment was created
|
45
|
+
And the response has the attributes:
|
46
|
+
| attribute | type | value |
|
47
|
+
| Post Id | string | 18 |
|
48
|
+
| Title | string | foo |
|
49
|
+
| Body | string | bar |
|
50
|
+
When I request a list of comments for post "18"
|
51
|
+
Then the request was successful
|
52
|
+
And one comment has the attributes:
|
53
|
+
| attribute | type | value |
|
54
|
+
| Title | string | foo |
|
55
|
+
| Body | string | bar |
|
56
|
+
|
57
|
+
Scenario: create a 2nd level child item
|
58
|
+
When I request to create a photo in album "2" for user "1" with:
|
59
|
+
| attribute | type | value |
|
60
|
+
| title | string | foo |
|
61
|
+
Then the comment was created
|
62
|
+
And the response has the attributes:
|
63
|
+
| attribute | type | value |
|
64
|
+
| Album Id | int | 2 |
|
65
|
+
| Title | string | foo |
|
66
|
+
When I request a list of photos for album "2" for user "1"
|
67
|
+
Then the request was successful
|
68
|
+
And one comment has the attributes:
|
69
|
+
| attribute | type | value |
|
70
|
+
| Title | string | foo |
|
71
|
+
|
72
|
+
Scenario: delete a child item
|
73
|
+
When I request to delete the comment "91" for post "19"
|
74
|
+
Then the request was successful
|
75
|
+
When I request a list of comments for post "19"
|
76
|
+
Then the request was successful
|
77
|
+
And zero comments have the attributes:
|
78
|
+
| attribute | type | value |
|
79
|
+
| id | int | 91 |
|
80
|
+
|
81
|
+
Scenario: modify a child item
|
82
|
+
When I request to modify the comment "102" for post "21" with:
|
83
|
+
| attribute | type | value |
|
84
|
+
| Name | string | foo |
|
85
|
+
| Body | string | bar |
|
86
|
+
Then the request was successful
|
87
|
+
And the response has the attributes:
|
88
|
+
| attribute | type | value |
|
89
|
+
| Post Id | int | 21 |
|
90
|
+
| Name | string | foo |
|
91
|
+
| Body | string | bar |
|
92
|
+
When I request a list of comments for post "21"
|
93
|
+
Then the request was successful
|
94
|
+
And one comment has the attributes:
|
95
|
+
| attribute | type | value |
|
96
|
+
| Name | string | foo |
|
97
|
+
| Body | string | bar |
|
98
|
+
|
99
|
+
Scenario: modify a child item
|
100
|
+
When I request to replace the comment "106" for post "22" with:
|
101
|
+
| attribute | type | value |
|
102
|
+
| Title | string | foo |
|
103
|
+
| Body | string | bar |
|
104
|
+
Then the request was successful
|
105
|
+
And the response has the attributes:
|
106
|
+
| attribute | type | value |
|
107
|
+
| Post Id | int | 22 |
|
108
|
+
| Title | string | foo |
|
109
|
+
| Body | string | bar |
|
110
|
+
When I request a list of comments for post "22"
|
111
|
+
Then the request was successful
|
112
|
+
And one comment has the attributes:
|
113
|
+
| attribute | type | value |
|
114
|
+
| Title | string | foo |
|
115
|
+
| Body | string | bar |
|
116
|
+
When I request the comment "106"
|
117
|
+
Then the request was successful
|
118
|
+
And the response has the attributes:
|
119
|
+
| attribute | type | value |
|
120
|
+
| Title | string | foo |
|
121
|
+
| Body | string | bar |
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'cucumber-rest-bdd/types'
|
2
|
+
require 'active_support/inflector'
|
3
|
+
|
4
|
+
LEVELS = %{(?: (?:for|in|on) [^"]+?(?: with (?:key|id))? "[^"]+")*}%
|
5
|
+
|
6
|
+
class Level
|
7
|
+
@urls = []
|
8
|
+
|
9
|
+
def initialize(levels)
|
10
|
+
arr = []
|
11
|
+
while matches = /^ (?:for|in|on) ([^"]+?)(?: with (?:key|id))? "([^"]*)"/.match(levels)
|
12
|
+
levels = levels[matches[0].length, levels.length]
|
13
|
+
item = {
|
14
|
+
resource: get_resource(matches[1]),
|
15
|
+
id: matches[2]
|
16
|
+
}
|
17
|
+
item[:id] = item[:id].to_i if item[:id].match(/^\d+$/)
|
18
|
+
arr.append(item)
|
19
|
+
end
|
20
|
+
@urls = arr.reverse
|
21
|
+
end
|
22
|
+
|
23
|
+
def url
|
24
|
+
@urls.map{ |l| "#{l[:resource]}/#{l[:id]}/"}.join()
|
25
|
+
end
|
26
|
+
|
27
|
+
def hash
|
28
|
+
hash = {}
|
29
|
+
@urls.each{ |l| hash[get_parameter("#{get_parameter(l[:resource]).singularize}_id")] = l[:id] }
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def last_hash
|
34
|
+
last = @urls.last
|
35
|
+
if !last.nil?
|
36
|
+
key = get_parameter("#{get_parameter(last[:resource]).singularize}_id")
|
37
|
+
return {
|
38
|
+
key => last[:id]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
return {}
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
self.url
|
46
|
+
end
|
47
|
+
end
|
@@ -3,6 +3,7 @@ require 'cucumber-api/steps'
|
|
3
3
|
require 'active_support/inflector'
|
4
4
|
require 'cucumber-rest-bdd/url'
|
5
5
|
require 'cucumber-rest-bdd/types'
|
6
|
+
require 'cucumber-rest-bdd/level'
|
6
7
|
require 'cucumber-rest-bdd/hash'
|
7
8
|
require 'easy_diff'
|
8
9
|
|
@@ -14,15 +15,15 @@ end
|
|
14
15
|
|
15
16
|
# GET
|
16
17
|
|
17
|
-
When(/^I request (?:an
|
18
|
+
When(/^I request (?:an?(?! list)|the) ([^"]+?)(?: with (?:key|id))? "([^"]*)"(#{LEVELS})?$/) do |resource, id, levels|
|
18
19
|
resource_name = get_resource(resource)
|
19
|
-
url = get_url("#{resource_name}/#{
|
20
|
+
url = get_url("#{Level.new(levels).url}#{resource_name}/#{id}")
|
20
21
|
steps %Q{When I send a GET request to "#{url}"}
|
21
22
|
end
|
22
23
|
|
23
|
-
When(/^I request (?:an
|
24
|
+
When(/^I request (?:an?(?! list)|the) (.+?)(?: with (?:key|id))? "([^"]*)"(#{LEVELS})? with:$/) do |resource, id, levels, params|
|
24
25
|
resource_name = get_resource(resource)
|
25
|
-
url = get_url("#{resource_name}/#{
|
26
|
+
url = get_url("#{Level.new(levels).url}#{resource_name}/#{id}")
|
26
27
|
unless params.raw.empty?
|
27
28
|
query = params.raw.map{|key, value| %/#{get_parameter(key)}=#{resolve(value)}/}.join("&")
|
28
29
|
url = "#{url}?#{query}"
|
@@ -30,15 +31,15 @@ When(/^I request (?:an?|the) (.+?)(?: with (?:key|id))? "([^"]*)" with:$/) do |r
|
|
30
31
|
steps %Q{When I send a GET request to "#{url}"}
|
31
32
|
end
|
32
33
|
|
33
|
-
When(/^I request a list of ([^:]
|
34
|
+
When(/^I request a list of ([^:]+?)(#{LEVELS})?$/) do |resource, levels|
|
34
35
|
resource_name = get_resource(resource)
|
35
|
-
url = get_url("#{resource_name}")
|
36
|
+
url = get_url("#{Level.new(levels).url}#{resource_name}")
|
36
37
|
steps %Q{When I send a GET request to "#{url}"}
|
37
38
|
end
|
38
39
|
|
39
|
-
When(/^I request a list of (
|
40
|
+
When(/^I request a list of (.+?)(#{LEVELS})? with:$/) do |resource, levels, params|
|
40
41
|
resource_name = get_resource(resource)
|
41
|
-
url = get_url("#{resource_name}")
|
42
|
+
url = get_url("#{Level.new(levels).url}#{resource_name}")
|
42
43
|
unless params.raw.empty?
|
43
44
|
query = params.raw.map{|key, value| %/#{get_parameter(key)}=#{resolve(value)}/}.join("&")
|
44
45
|
url = "#{url}?#{query}"
|
@@ -48,25 +49,37 @@ end
|
|
48
49
|
|
49
50
|
# DELETE
|
50
51
|
|
51
|
-
When(/^I request to (?:delete|remove) the (
|
52
|
+
When(/^I request to (?:delete|remove) the ([^"]+?) "([^"]*)"(#{LEVELS})?$/) do |resource, id, levels|
|
52
53
|
resource_name = get_resource(resource)
|
53
|
-
url = get_url("#{resource_name}/#{
|
54
|
+
url = get_url("#{Level.new(levels).url}#{resource_name}/#{id}")
|
54
55
|
steps %Q{When I send a DELETE request to "#{url}"}
|
55
56
|
end
|
56
57
|
|
57
58
|
# POST
|
58
59
|
|
59
|
-
When(/^I request to create an? ([^:]+?)
|
60
|
+
When(/^I request to create an? ([^:]+?)(#{LEVELS})?$/) do |resource, levels|
|
60
61
|
resource_name = get_resource(resource)
|
61
|
-
|
62
|
+
level = Level.new(levels)
|
63
|
+
if ENV['set_parent_id'] == 'true'
|
64
|
+
json = MultiJson.dump(level.last_hash)
|
65
|
+
steps %Q{
|
66
|
+
When I set JSON request body to:
|
67
|
+
"""
|
68
|
+
#{json}
|
69
|
+
"""
|
70
|
+
}
|
71
|
+
end
|
72
|
+
url = get_url("#{level.url}#{resource_name}")
|
62
73
|
steps %Q{When I send a POST request to "#{url}"}
|
63
74
|
end
|
64
75
|
|
65
|
-
When(/^I request to create an? ([^"]+?) with:$/) do |resource, params|
|
76
|
+
When(/^I request to create an? ((?!<.+?(?: for | in | on ))[^"]+?)(#{LEVELS})? with:$/) do |resource, levels, params|
|
66
77
|
resource_name = get_resource(resource)
|
67
78
|
request_hash = get_attributes(params.hashes)
|
79
|
+
level = Level.new(levels)
|
80
|
+
request_hash = request_hash.merge(level.last_hash) if ENV['set_parent_id'] == 'true'
|
68
81
|
json = MultiJson.dump(request_hash)
|
69
|
-
url = get_url("#{resource_name}")
|
82
|
+
url = get_url("#{level.url}#{resource_name}")
|
70
83
|
steps %Q{
|
71
84
|
When I set JSON request body to:
|
72
85
|
"""
|
@@ -78,19 +91,31 @@ end
|
|
78
91
|
|
79
92
|
# PUT
|
80
93
|
|
81
|
-
When(/^I request to (?:create|replace) (?:an?|the) ([^"]+?)(?: with (?:key|id))? "([^"]+)"
|
94
|
+
When(/^I request to (?:create|replace) (?:an?|the) ((?![^"]+?(?: for | in | on ))[^"]+?)(?: with (?:key|id))? "([^"]+)"(#{LEVELS})?$/) do |resource, id, levels|
|
82
95
|
resource_name = get_resource(resource)
|
83
|
-
|
96
|
+
level = Level.new(levels)
|
97
|
+
if ENV['set_parent_id'] == 'true'
|
98
|
+
json = MultiJson.dump(level.last_hash)
|
99
|
+
steps %Q{
|
100
|
+
When I set JSON request body to:
|
101
|
+
"""
|
102
|
+
#{json}
|
103
|
+
"""
|
104
|
+
}
|
105
|
+
end
|
106
|
+
url = get_url("#{level.url}#{resource_name}/#{id}")
|
84
107
|
steps %Q{
|
85
108
|
When I send a PUT request to "#{url}"
|
86
109
|
}
|
87
110
|
end
|
88
111
|
|
89
|
-
When(/^I request to (?:create|replace) (?:an?|the) ([^"]+?)(?: with (?:key|id))? "([^"]+)" with:$/) do |resource, id, params|
|
112
|
+
When(/^I request to (?:create|replace|set) (?:an?|the) ((?![^"]+?(?: for | in | on ))[^"]+?)(?: with (?:key|id))? "([^"]+)"(#{LEVELS})? (?:with|to):$/) do |resource, id, levels, params|
|
90
113
|
resource_name = get_resource(resource)
|
91
114
|
request_hash = get_attributes(params.hashes)
|
115
|
+
level = Level.new(levels)
|
116
|
+
request_hash = request_hash.merge(level.last_hash) if ENV['set_parent_id'] == 'true'
|
92
117
|
json = MultiJson.dump(request_hash)
|
93
|
-
url = get_url("#{resource_name}/#{id}")
|
118
|
+
url = get_url("#{level.url}#{resource_name}/#{id}")
|
94
119
|
steps %Q{
|
95
120
|
When I set JSON request body to:
|
96
121
|
"""
|
@@ -102,11 +127,11 @@ end
|
|
102
127
|
|
103
128
|
# PATCH
|
104
129
|
|
105
|
-
When(/^I request to modify the (
|
130
|
+
When(/^I request to modify the ((?![^"]+?(?: for | in | on ))[^"]+?)(?: with (?:key|id))? "([^"]+)"(#{LEVELS})? with:$/) do |resource, id, levels, params|
|
106
131
|
resource_name = get_resource(resource)
|
107
132
|
request_hash = get_attributes(params.hashes)
|
108
133
|
json = MultiJson.dump(request_hash)
|
109
|
-
url = get_url("#{resource_name}/#{id}")
|
134
|
+
url = get_url("#{Level.new(levels).url}#{resource_name}/#{id}")
|
110
135
|
steps %Q{
|
111
136
|
When I set JSON request body to:
|
112
137
|
"""
|
@@ -17,7 +17,7 @@ Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{C
|
|
17
17
|
type: 'single'
|
18
18
|
})
|
19
19
|
data = @response.get get_root_json_path()
|
20
|
-
raise %/Could not find a match for: #{nesting}\n#{@response.to_json_s}/ if !nest_match(data, grouping, expected)
|
20
|
+
raise %/Could not find a match for: #{nesting}\n#{expected.inspect}\n#{@response.to_json_s}/ if !nest_match(data, grouping, expected)
|
21
21
|
end
|
22
22
|
|
23
23
|
Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{CAPTURE_INT}|\d+)) (?:\w+)\s?)+)$/) do |nesting|
|
@@ -42,7 +42,7 @@ Then(/^(#{FEWER_MORE_THAN})?\s*(#{CAPTURE_INT}|\d+) (?:.*?) ((?:#{HAVE_SYNONYM}
|
|
42
42
|
count_mod: count_mod
|
43
43
|
})
|
44
44
|
data = @response.get get_root_json_path()
|
45
|
-
raise %/Expected #{compare_to_string(count_mod)}#{count} items in array with attributes for: #{nesting}\n#{@response.to_json_s}/ if !nest_match(data, grouping, expected)
|
45
|
+
raise %/Expected #{compare_to_string(count_mod)}#{count} items in array with attributes for: #{nesting}\n#{expected.inspect}\n#{@response.to_json_s}/ if !nest_match(data, grouping, expected)
|
46
46
|
end
|
47
47
|
|
48
48
|
Then(/^(#{FEWER_MORE_THAN})?\s*(#{CAPTURE_INT}|\d+) (?:.*?) ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{CAPTURE_INT}|\d+)) (?:\w+)\s?)+)$/) do |count_mod, count, nesting|
|
@@ -13,6 +13,10 @@ Then(/^(?:it|the request) fail(?:s|ed)$/) do
|
|
13
13
|
raise %/Expected failed response code 4xx\/5xx but was #{@response.code}/ if @response.code < 400 || @response.code >= 600
|
14
14
|
end
|
15
15
|
|
16
|
+
Then(/^the (?!request)(?:.+?) (?:is|was) created$/) do
|
17
|
+
steps %Q{Then the response status should be "201"}
|
18
|
+
end
|
19
|
+
|
16
20
|
Then(/^the request (?:is|was) successful and (?:a resource|.+) (?:is|was) created$/) do
|
17
21
|
steps %Q{Then the response status should be "201"}
|
18
22
|
end
|
data/server/routes.json
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-rest-bdd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0.pre.107
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Bragg
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- features/functional.feature
|
72
72
|
- features/grabs.feature
|
73
73
|
- features/headers.feature
|
74
|
+
- features/levels.feature
|
74
75
|
- features/methods.feature
|
75
76
|
- features/response.feature
|
76
77
|
- features/status.feature
|
@@ -78,6 +79,7 @@ files:
|
|
78
79
|
- features/types.feature
|
79
80
|
- lib/cucumber-rest-bdd.rb
|
80
81
|
- lib/cucumber-rest-bdd/hash.rb
|
82
|
+
- lib/cucumber-rest-bdd/level.rb
|
81
83
|
- lib/cucumber-rest-bdd/steps.rb
|
82
84
|
- lib/cucumber-rest-bdd/steps/functional.rb
|
83
85
|
- lib/cucumber-rest-bdd/steps/resource.rb
|
@@ -86,6 +88,7 @@ files:
|
|
86
88
|
- lib/cucumber-rest-bdd/types.rb
|
87
89
|
- lib/cucumber-rest-bdd/url.rb
|
88
90
|
- server/db.json
|
91
|
+
- server/routes.json
|
89
92
|
homepage: http://github.com/graze/cucumber-rest-bdd
|
90
93
|
licenses:
|
91
94
|
- MIT
|
@@ -101,9 +104,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
104
|
version: '0'
|
102
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
106
|
requirements:
|
104
|
-
- - "
|
107
|
+
- - ">"
|
105
108
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
109
|
+
version: 1.3.1
|
107
110
|
requirements: []
|
108
111
|
rubyforge_project:
|
109
112
|
rubygems_version: 2.4.8
|