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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e78ccb9ec136ed4347daaa0afafc066e44beaabd5a19cafbffd54a4e2039507c
4
- data.tar.gz: 6f73934f0c2df4bb620d2e09412b1c4cb5e1273aac70d771df1e65e6ac7ca854
3
+ metadata.gz: c5dec7f07c1f119eb37358b529c13278f00aac9d9a7b7266f012bf3b43edf4a8
4
+ data.tar.gz: 18cef53fd72a2717fb392c2ac23e2d853779038ae5fc779238a351dc649d252d
5
5
  SHA512:
6
- metadata.gz: 4fa555baada878b6e8480d319a2a26155b802fd38d2a410fe27a271c0a37283c9f5c7bfc51c70f74da909ae2e7cc2fa594467b62ce0818ce28fdccd0bbe6ee32
7
- data.tar.gz: 6995a6ebaf778b666dbbd17e4a3a18e16f8fbbbe4d99abf03f1ef0c4e2aba0c76c2f6709de56e8857791efab69f76ae4fe98b1d61d97ba32a3c689d7ebd1306a
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 get_field(level[:key])
47
- when 'list' then get_resource(level[:key])
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
- # response interrogation
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
- Then("the response is a list of/containing {list_has_count} {field_name}") do |list_comparison, item|
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
- Then("the response #{HAVE_ALTERNATION} (the )(following )value {string}") do |value|
43
- expected = value
44
- data = @response.get get_root_data_key()
45
- raise %/Response did not match: #{expected}\n#{data}/ if data.empty? || !data.include?(expected)
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
- Then("{list_has_count} {field_name} #{HAVE_ALTERNATION} (the )(following )(data )attributes:") do |list_comparison, field, attributes|
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 = field.get_value(@response, 'array')
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
- Then("{list_has_count} {field_name} #{HAVE_ALTERNATION} (the )(following )value {string}") do |list_comparison, field, value|
56
- expected = value
57
- data = field.get_value(@response, 'array')
58
- matched = data.select { |item| !item.empty? && item.include?(expected) }
59
- raise %/Expected #{list_comparison.to_string()} items in array that matched:\n#{expected}\n#{data}/ if !list_comparison.compare(matched.count)
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
- # Responses with nesting
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: 'single'
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
- Then("the response {list_nesting} #{HAVE_ALTERNATION} (the )(following )value {string}") do |nesting, value|
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: 'single'
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
- Then("the response {list_nesting}") do |nesting|
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, {}, false)
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
- Then("{list_has_count} {field_name} {list_nesting} #{HAVE_ALTERNATION} (the )(following )(data )attributes:") do |list_comparison, count_item, nesting, attributes|
94
- expected = get_attributes(attributes.hashes)
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: 'multiple',
98
- comparison: list_comparison
124
+ type: 'single'
99
125
  })
100
126
  data = @response.get get_key(nesting.grouping)
101
- raise %/Expected #{list_comparison.to_string()} items in array with attributes for: #{nesting.match}\n#{expected.inspect}\n#{@response.to_json_s}/ if !nest_match_attributes(data, nesting.grouping, expected, false)
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
- Then("{list_has_count} {field_name} {list_nesting}") do |list_comparison, item, nesting|
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: 'multiple',
108
- comparison: list_comparison
134
+ type: 'single'
109
135
  })
110
136
  data = @response.get get_key(nesting.grouping)
111
- raise %/Expected #{list_comparison.to_string()} items in array with: #{nesting.match}\n#{@response.to_json_s}/ if !nest_match_attributes(data, nesting.grouping, {}, false)
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.22
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-06-26 00:00:00.000000000 Z
12
+ date: 2018-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber-api