alinta-cucumber-rest-bdd 0.5.22 → 0.5.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cucumber-rest-bdd/data.rb +3 -3
- data/lib/cucumber-rest-bdd/steps/response.rb +62 -36
- data/lib/cucumber-rest-bdd/types.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5dec7f07c1f119eb37358b529c13278f00aac9d9a7b7266f012bf3b43edf4a8
|
4
|
+
data.tar.gz: 18cef53fd72a2717fb392c2ac23e2d853779038ae5fc779238a351dc649d252d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 266a787b8396ffd88d33d603c66b4245d79e7a66490f8bdcb0991d11ec9f7658813fad1b094d7ab33a9e3e66c4e5624f350b230c5684bac09fcb4b0ab90e8fdb
|
7
|
+
data.tar.gz: 278fc49764b69122daed202e8201d8171ea3519398410b633e4a4356e4091bc475f0d2800ce3a2a789678e7554a512791ff967d48f478c19bbd4ee1e8c306197
|
@@ -43,10 +43,10 @@ def get_child_data(level, data)
|
|
43
43
|
else
|
44
44
|
levelKey = case level[:type]
|
45
45
|
when 'single' then get_field(level[:key])
|
46
|
-
when 'multiple' then
|
47
|
-
when 'list' then
|
46
|
+
when 'multiple' then get_list_field(level[:key])
|
47
|
+
when 'list' then get_list_field(level[:key])
|
48
48
|
end
|
49
|
-
raise %/Key not found: #{level[:key]} as #{levelKey} in #{data}/ if !data[levelKey]
|
49
|
+
raise %/Key not found: #{level[:key]} as #{levelKey} in #{data}/ if data.is_a?(Array) || !data[levelKey]
|
50
50
|
return data[levelKey]
|
51
51
|
end
|
52
52
|
end
|
@@ -7,8 +7,18 @@ Then("print the response") do
|
|
7
7
|
puts %/The response:\n#{@response.to_json_s}/
|
8
8
|
end
|
9
9
|
|
10
|
-
#
|
10
|
+
# SIMPLE VALUE RESPONSE
|
11
11
|
|
12
|
+
# response is a string with the specified value
|
13
|
+
Then("the response #{HAVE_ALTERNATION} (the )(following )value {string}") do |value|
|
14
|
+
expected = value
|
15
|
+
data = @response.get get_root_data_key()
|
16
|
+
raise %/Response did not match: #{expected}\n#{data}/ if data.empty? || !data.include?(expected)
|
17
|
+
end
|
18
|
+
|
19
|
+
# OBJECT RESPONSE
|
20
|
+
|
21
|
+
# response is an object with a field that is validated by a pre-defined regex
|
12
22
|
Then("the response #{HAVE_ALTERNATION} {field_name} of type {word}") do |field, type|
|
13
23
|
regex = case type
|
14
24
|
when 'datetime' then /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:[+|-]\d{2}:\d{2})?$/i
|
@@ -21,92 +31,108 @@ Then("the response #{HAVE_ALTERNATION} {field_name} of type {word}") do |field,
|
|
21
31
|
field.validate_value(@response, value.to_s, Regexp.new(regex))
|
22
32
|
end
|
23
33
|
|
34
|
+
# response is an object with a field that is validated by a custom regex
|
24
35
|
Then("the response #{HAVE_ALTERNATION} {field_name} of type {word} that matches {string}") do |field, type, regex|
|
25
36
|
value = field.get_value(@response, type)
|
26
37
|
field.validate_value(@response, value.to_s, Regexp.new(regex))
|
27
38
|
end
|
28
39
|
|
29
|
-
|
30
|
-
list = @response.get_as_type get_root_data_key(), 'array'
|
31
|
-
raise %/Expected #{list_comparison.to_string()} items in array for path '#{get_root_data_key()}', found: #{list.count}\n#{@response.to_json_s}/ if !list_comparison.compare(list.count)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Responses without nesting
|
35
|
-
|
40
|
+
# response is an object with specific attributes having defined values
|
36
41
|
Then("the response #{HAVE_ALTERNATION} (the )(following )attributes:") do |attributes|
|
37
42
|
expected = get_attributes(attributes.hashes)
|
38
43
|
data = @response.get get_root_data_key()
|
39
44
|
raise %/Response did not match:\n#{expected.inspect}\n#{data}/ if data.empty? || !data.deep_include?(expected)
|
40
45
|
end
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
# ARRAY RESPONSE
|
48
|
+
|
49
|
+
# response is an array of objects
|
50
|
+
Then("the response is a list of/containing {list_has_count} {field_name}") do |list_comparison, item|
|
51
|
+
list = @response.get_as_type get_root_data_key(), 'array'
|
52
|
+
raise %/Expected #{list_comparison.to_string()} items in array for path '#{get_root_data_key()}', found: #{list.count}\n#{@response.to_json_s}/ if !list_comparison.compare(list.count)
|
46
53
|
end
|
47
54
|
|
48
|
-
|
55
|
+
# response is an array of objects where the specified number of entries match the defined data attributes
|
56
|
+
Then("the response is a list with {list_has_count} entry/entries having/containing/with (the )(following )(data )attributes:") do |list_comparison, attributes|
|
49
57
|
expected = get_attributes(attributes.hashes)
|
50
|
-
data =
|
58
|
+
data = @response.get_as_type get_root_data_key(), 'array'
|
51
59
|
matched = data.select { |item| !item.empty? && item.deep_include?(expected) }
|
52
60
|
raise %/Expected #{list_comparison.to_string()} items in array that matched:\n#{expected.inspect}\n#{data}/ if !list_comparison.compare(matched.count)
|
53
61
|
end
|
54
62
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
63
|
+
# response is an array of objects where the specified number of entries match the defined data attributes
|
64
|
+
Then("the response is a list with {list_has_count} entry/entries {list_nesting}") do |list_comparison, nesting|
|
65
|
+
nesting.push({
|
66
|
+
root: true,
|
67
|
+
type: 'multiple',
|
68
|
+
comparison: list_comparison
|
69
|
+
})
|
70
|
+
data = @response.get get_key(nesting.grouping)
|
71
|
+
raise %/Could not find a match for: #{nesting.match}\n#{@response.to_json_s}/ if data.empty? || !nest_match_attributes(data, nesting.grouping, {}, false)
|
60
72
|
end
|
61
73
|
|
62
|
-
#
|
63
|
-
|
64
|
-
Then("the response {list_nesting} #{HAVE_ALTERNATION} (the )(following )attributes:") do |nesting, attributes|
|
74
|
+
# response is an array of objects where the specified number of entries match the defined data attributes
|
75
|
+
Then("the response is a list with {list_has_count} entry/entries {list_nesting} #{HAVE_ALTERNATION} (the )(following )(data )attributes:") do |list_comparison, nesting, attributes|
|
65
76
|
expected = get_attributes(attributes.hashes)
|
66
77
|
nesting.push({
|
67
78
|
root: true,
|
68
|
-
type: '
|
79
|
+
type: 'multiple',
|
80
|
+
comparison: list_comparison
|
69
81
|
})
|
70
82
|
data = @response.get get_key(nesting.grouping)
|
71
83
|
raise %/Could not find a match for: #{nesting.match}\n#{expected.inspect}\n#{@response.to_json_s}/ if data.empty? || !nest_match_attributes(data, nesting.grouping, expected, false)
|
72
84
|
end
|
73
85
|
|
74
|
-
|
86
|
+
# response is an array of objects where the specified number of entries match the defined string value
|
87
|
+
Then("the response is a list with {list_has_count} entry/entries having/containing/with (the )(following )value {string}") do |list_comparison, value|
|
88
|
+
expected = value
|
89
|
+
data = @response.get_as_type get_root_data_key(), 'array'
|
90
|
+
matched = data.select { |item| !item.empty? && item.include?(expected) }
|
91
|
+
raise %/Expected #{list_comparison.to_string()} items in array that matched:\n#{expected}\n#{data}/ if !list_comparison.compare(matched.count)
|
92
|
+
end
|
93
|
+
|
94
|
+
# response is an array of objects where the specified number of entries match the defined string value
|
95
|
+
Then("the response is a list with {list_has_count} entry/entries {list_nesting} #{HAVE_ALTERNATION} (the )(following )value {string}") do |list_comparison, nesting, value|
|
75
96
|
expected = value
|
76
97
|
nesting.push({
|
77
98
|
root: true,
|
78
|
-
type: '
|
99
|
+
type: 'multiple',
|
100
|
+
comparison: list_comparison
|
79
101
|
})
|
80
102
|
data = @response.get get_key(nesting.grouping)
|
81
103
|
raise %/Could not find a match for: #{nesting.match}\n#{expected}\n#{@response.to_json_s}/ if data.empty? || !nest_match_attributes(data, nesting.grouping, expected, true)
|
82
104
|
end
|
83
105
|
|
84
|
-
|
106
|
+
# HIERARCHICAL RESPONSE
|
107
|
+
|
108
|
+
# response has the specified hierarchy of objects / lists where the specified number of leaf items match the defined data attributes
|
109
|
+
Then("the response {list_nesting} #{HAVE_ALTERNATION} (the )(following )attributes:") do |nesting, attributes|
|
110
|
+
expected = get_attributes(attributes.hashes)
|
85
111
|
nesting.push({
|
86
112
|
root: true,
|
87
113
|
type: 'single'
|
88
114
|
})
|
89
115
|
data = @response.get get_key(nesting.grouping)
|
90
|
-
raise %/Could not find a match for: #{nesting.match}\n#{@response.to_json_s}/ if data.empty? || !nest_match_attributes(data, nesting.grouping,
|
116
|
+
raise %/Could not find a match for: #{nesting.match}\n#{expected.inspect}\n#{@response.to_json_s}/ if data.empty? || !nest_match_attributes(data, nesting.grouping, expected, false)
|
91
117
|
end
|
92
118
|
|
93
|
-
|
94
|
-
|
119
|
+
# response has the specified hierarchy of objects / lists where the specified number of leaf items match the defined string value
|
120
|
+
Then("the response {list_nesting} #{HAVE_ALTERNATION} (the )(following )value {string}") do |nesting, value|
|
121
|
+
expected = value
|
95
122
|
nesting.push({
|
96
123
|
root: true,
|
97
|
-
type: '
|
98
|
-
comparison: list_comparison
|
124
|
+
type: 'single'
|
99
125
|
})
|
100
126
|
data = @response.get get_key(nesting.grouping)
|
101
|
-
raise %/
|
127
|
+
raise %/Could not find a match for: #{nesting.match}\n#{expected}\n#{@response.to_json_s}/ if data.empty? || !nest_match_attributes(data, nesting.grouping, expected, true)
|
102
128
|
end
|
103
129
|
|
104
|
-
|
130
|
+
# response has the specified hierarchy of objects / lists where the specified number of leaf items is as expected only (no data checked)
|
131
|
+
Then("the response {list_nesting}") do |nesting|
|
105
132
|
nesting.push({
|
106
133
|
root: true,
|
107
|
-
type: '
|
108
|
-
comparison: list_comparison
|
134
|
+
type: 'single'
|
109
135
|
})
|
110
136
|
data = @response.get get_key(nesting.grouping)
|
111
|
-
raise %/
|
137
|
+
raise %/Could not find a match for: #{nesting.match}\n#{@response.to_json_s}/ if data.empty? || !nest_match_attributes(data, nesting.grouping, {}, false)
|
112
138
|
end
|
@@ -123,6 +123,18 @@ def get_field(name)
|
|
123
123
|
return name
|
124
124
|
end
|
125
125
|
|
126
|
+
def get_list_field(name)
|
127
|
+
if name[0] == '`' && name[-1] == '`'
|
128
|
+
name = name[1..-2]
|
129
|
+
elsif name[0] != '[' || name[-1] != ']'
|
130
|
+
separator = ENV.has_key?('field_separator') ? ENV['field_separator'] : '_'
|
131
|
+
name = name.parameterize(separator: separator)
|
132
|
+
name = name.pluralize
|
133
|
+
name = name.camelize(:lower) if (ENV.has_key?('field_camel') && ENV['field_camel'] == 'true')
|
134
|
+
end
|
135
|
+
return name
|
136
|
+
end
|
137
|
+
|
126
138
|
def get_attributes(hashes)
|
127
139
|
attributes = hashes.each_with_object({}) do |row, hash|
|
128
140
|
name, value, type = row["attribute"], row["value"], row["type"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alinta-cucumber-rest-bdd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Bragg
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber-api
|