alinta-cucumber-rest-bdd 0.5.14 → 0.5.15

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
  SHA1:
3
- metadata.gz: 354c46fe9607db986dffbed0a48e9f2758e8a77e
4
- data.tar.gz: f29e45217a0bf112a9eadacba17dc6c3f0fdb4cd
3
+ metadata.gz: 6c1c08f37c955dfab322c7f134f644e30503a01c
4
+ data.tar.gz: dbd38aab4b7e14cf854eb9e95c3226bd811e0abd
5
5
  SHA512:
6
- metadata.gz: dcf73bf5d3bb13ba6f313ee4a56458e1110edd97b98103f630623ec2a85214975a3779413f935512b1793aa59f8793e7a68cc43ae97c7280ef76788c4f55c4e1
7
- data.tar.gz: 0cabb8f56aa36905668f02924f2d733fd597f3dc41a7c607ef832dcbbe57ba3b2132421d6a61f4b420a72be6d961abb099299a87e96a9476c4ca0d4fbedeee90
6
+ metadata.gz: 51fbffaf21822b8c00fe6ccc82c9b92338d143974ca842f58bf2bdcaecac181d1a0e9ed486fa2f7cee1a6e2002c8b42524135b2ac9ca14b4bb336f52e047b12b
7
+ data.tar.gz: 45ff06672c504df19e3acc5332fdefa49a45cda5fc81a94dea8fa2bdf1ea0b8f848459e551ec2e93c3ee1dc07c97bd1b87d4e25fd38845fb8123eb417712cfc5
@@ -1,7 +1,7 @@
1
1
  require 'cucumber-rest-bdd/types'
2
2
  require 'active_support/inflector'
3
3
 
4
- LEVELS = %{(?: (?:for|in|on) [^"]+?(?: with (?:key|id))? "[^"]+")*}%
4
+ LEVELS = %{((?: (?:for|in|on) #{RESOURCE_NAME}(?: with (?:key|id))? "[^"]*")*)?}%
5
5
 
6
6
  class Level
7
7
  @urls = []
@@ -26,14 +26,14 @@ class Level
26
26
 
27
27
  def hash
28
28
  hash = {}
29
- @urls.each{ |l| hash[get_parameter("#{get_parameter(l[:resource]).singularize}_id")] = l[:id] }
29
+ @urls.each{ |l| hash[get_field("#{get_field(l[:resource]).singularize}_id")] = l[:id] }
30
30
  hash
31
31
  end
32
32
 
33
33
  def last_hash
34
34
  last = @urls.last
35
35
  if !last.nil?
36
- key = get_parameter("#{get_parameter(last[:resource]).singularize}_id")
36
+ key = get_field("#{get_field(last[:resource]).singularize}_id")
37
37
  return {
38
38
  key => last[:id]
39
39
  }
@@ -20,7 +20,7 @@ Given(/^I retrieve the secret "(.*?)" from Azure Storage Vault "(.*?)" using ten
20
20
  }
21
21
  access_token = @response.get_as_type "$..access_token", "string"
22
22
  steps %Q{
23
- And I request the secret "#{secret_name}" from Azure Storage Vault "#{vault_name}" using token "#{access_token}"
23
+ Given I retrieve the secret "#{secret_name}" from Azure Storage Vault "#{vault_name}" using access token "#{access_token}"
24
24
  }
25
25
  end
26
26
 
@@ -33,13 +33,17 @@ end
33
33
  Given(/^I authenticate with "(.*?)" using client credentials "(.*?)" and "(.*?)"$/) do |url, client_id, client_secret|
34
34
  steps %Q{
35
35
  Given I send "www-x-form-urlencoded" and accept JSON
36
- When I set JSON request body to '{"grant_type": "client_credentials", "client_id": "#{client_id}", "client_secret": "#{client_secret}", "resource": "https://vault.azure.net"}'
36
+ When I set form request body to:
37
+ | grant_type | client_credentials |
38
+ | client_id | #{client_id} |
39
+ | client_secret | #{client_secret} |
40
+ | resource | https://vault.azure.net |
37
41
  And I send a POST request to "#{url}"
38
42
  Then the request was successful
39
43
  }
40
44
  end
41
45
 
42
- Given(/^I request the secret "(.*?)" from Azure Storage Vault "(.*?)" using token "(.*?)"$/) do |secret_name, vault_name, access_token|
46
+ Given(/^I retrieve the secret "([^"]*)" from Azure Storage Vault "([^"]*)" using access token "([^"]*)"$/) do |secret_name, vault_name, access_token|
43
47
  api_version = '2015-06-01'
44
48
  url = "https://#{vault_name}.vault.azure.net/secrets/#{secret_name}?api-version=#{api_version}"
45
49
  steps %Q{
@@ -15,7 +15,7 @@ Then(/^the JSON response should have "([^"]*)" of type array with (\d+) entr(?:y
15
15
  raise %/Expected #{number} items in array for path '#{json_path}', found: #{list.count}\n#{@response.to_json_s}/ if list.count != number.to_i
16
16
  end
17
17
 
18
- Then(/^the JSON response should have "([^"]*)" of type array with (#{FEWER_MORE_THAN}) (\d+) entr(?:y|ies)$/) do |json_path, count_mod, number|
18
+ Then(/^the JSON response should have "([^"]*)" of type array with ({fewer_more_than}) (\d+) entr(?:y|ies)$/) do |json_path, count_mod, number|
19
19
  list = @response.get_as_type json_path, 'array'
20
20
  raise %/Expected #{count_mod} #{number} items in array for path '#{json_path}', found: #{list.count}\n#{@response.to_json_s}/ \
21
21
  if !num_compare(count_mod, list.count, number.to_i)
@@ -7,45 +7,48 @@ require 'cucumber-rest-bdd/level'
7
7
  require 'cucumber-rest-bdd/hash'
8
8
  require 'easy_diff'
9
9
 
10
+ GET_TYPES = %{(?:an?(?! list)|the)}%
11
+ WITH_ID = %{(?: with (?:key|id))? "([^"]*)"}%
12
+
10
13
  Given(/^I am a client$/) do
11
14
  steps %Q{
12
15
  Given I send "application/json" and accept JSON
13
16
  }
14
17
  end
15
18
 
16
- Given(/^I am issuing requests for (.+?)$/) do |resource|
19
+ Given(/^I am issuing requests for #{RESOURCE_NAME_CAPTURE}$/) do |resource|
17
20
  @urlbasepath = get_resource(resource)
18
21
  end
19
22
 
20
23
  # GET
21
24
 
22
- When(/^I request (?:an?(?! list)|the) ([^"]+?)(?: with (?:key|id))? "([^"]*)"(#{LEVELS})?$/) do |resource, id, levels|
25
+ When(/^I request #{GET_TYPES} #{RESOURCE_NAME_CAPTURE}#{WITH_ID}#{LEVELS}$/) do |resource, id, levels|
23
26
  resource_name = get_resource(resource)
24
27
  url = get_url("#{Level.new(levels).url}#{resource_name}/#{id}")
25
28
  steps %Q{When I send a GET request to "#{url}"}
26
29
  end
27
30
 
28
- When(/^I request (?:an?(?! list)|the) (.+?)(?: with (?:key|id))? "([^"]*)"(#{LEVELS})? with:$/) do |resource, id, levels, params|
31
+ When(/^I request #{GET_TYPES} #{RESOURCE_NAME_CAPTURE}#{WITH_ID}#{LEVELS} with:$/) do |resource, id, levels, params|
29
32
  resource_name = get_resource(resource)
30
33
  url = get_url("#{Level.new(levels).url}#{resource_name}/#{id}")
31
34
  unless params.raw.empty?
32
- query = params.raw.map{|key, value| %/#{get_parameter(key)}=#{resolve(value)}/}.join("&")
35
+ query = params.raw.map{|key, value| %/#{get_field(key)}=#{resolve(value)}/}.join("&")
33
36
  url = "#{url}?#{query}"
34
37
  end
35
38
  steps %Q{When I send a GET request to "#{url}"}
36
39
  end
37
40
 
38
- When(/^I request a list of ([^:]+?)(#{LEVELS})?$/) do |resource, levels|
41
+ When(/^I request a list of #{RESOURCE_NAME_CAPTURE}#{LEVELS}$/) do |resource, levels|
39
42
  resource_name = get_resource(resource)
40
43
  url = get_url("#{Level.new(levels).url}#{resource_name}")
41
44
  steps %Q{When I send a GET request to "#{url}"}
42
45
  end
43
46
 
44
- When(/^I request a list of (.+?)(#{LEVELS})? with:$/) do |resource, levels, params|
47
+ When(/^I request a list of #{RESOURCE_NAME_CAPTURE}#{LEVELS} with:$/) do |resource, levels, params|
45
48
  resource_name = get_resource(resource)
46
49
  url = get_url("#{Level.new(levels).url}#{resource_name}")
47
50
  unless params.raw.empty?
48
- query = params.raw.map{|key, value| %/#{get_parameter(key)}=#{resolve(value)}/}.join("&")
51
+ query = params.raw.map{|key, value| %/#{get_field(key)}=#{resolve(value)}/}.join("&")
49
52
  url = "#{url}?#{query}"
50
53
  end
51
54
  steps %Q{When I send a GET request to "#{url}"}
@@ -53,7 +56,7 @@ end
53
56
 
54
57
  # DELETE
55
58
 
56
- When(/^I request to (?:delete|remove) the ([^"]+?) "([^"]*)"(#{LEVELS})?$/) do |resource, id, levels|
59
+ When(/^I request to (?:delete|remove) #{ARTICLE} #{RESOURCE_NAME_CAPTURE}#{WITH_ID}#{LEVELS}$/) do |resource, id, levels|
57
60
  resource_name = get_resource(resource)
58
61
  url = get_url("#{Level.new(levels).url}#{resource_name}/#{id}")
59
62
  steps %Q{When I send a DELETE request to "#{url}"}
@@ -61,7 +64,7 @@ end
61
64
 
62
65
  # POST
63
66
 
64
- When(/^I request to create an? ([^:]+?)(#{LEVELS})?$/) do |resource, levels|
67
+ When(/^I request to create #{ARTICLE} #{RESOURCE_NAME_CAPTURE}#{LEVELS}$/) do |resource, levels|
65
68
  resource_name = get_resource(resource)
66
69
  level = Level.new(levels)
67
70
  if ENV['set_parent_id'] == 'true'
@@ -77,7 +80,7 @@ When(/^I request to create an? ([^:]+?)(#{LEVELS})?$/) do |resource, levels|
77
80
  steps %Q{When I send a POST request to "#{url}"}
78
81
  end
79
82
 
80
- When(/^I request to create an? ((?!<.+?(?: for | in | on ))[^"]+?)(#{LEVELS})? with:$/) do |resource, levels, params|
83
+ When(/^I request to create #{ARTICLE} #{RESOURCE_NAME_CAPTURE}#{LEVELS} with:$/) do |resource, levels, params|
81
84
  resource_name = get_resource(resource)
82
85
  request_hash = get_attributes(params.hashes)
83
86
  level = Level.new(levels)
@@ -95,7 +98,7 @@ end
95
98
 
96
99
  # PUT
97
100
 
98
- When(/^I request to (?:create|replace|set) (?:an?|the) ((?![^"]+?(?: for | in | on ))[^"]+?)(?: with (?:key|id))? "([^"]+)"(#{LEVELS})?$/) do |resource, id, levels|
101
+ When(/^I request to (?:create|replace|set) #{ARTICLE} #{RESOURCE_NAME_CAPTURE}#{WITH_ID}#{LEVELS}$/) do |resource, id, levels|
99
102
  resource_name = get_resource(resource)
100
103
  level = Level.new(levels)
101
104
  if ENV['set_parent_id'] == 'true'
@@ -113,7 +116,7 @@ When(/^I request to (?:create|replace|set) (?:an?|the) ((?![^"]+?(?: for | in |
113
116
  }
114
117
  end
115
118
 
116
- When(/^I request to (?:create|replace|set) (?:an?|the) ((?![^"]+?(?: for | in | on ))[^"]+?)(?: with (?:key|id))? "([^"]+)"(#{LEVELS})? (?:with|to):$/) do |resource, id, levels, params|
119
+ When(/^I request to (?:create|replace|set) #{ARTICLE} #{RESOURCE_NAME_CAPTURE}#{WITH_ID}#{LEVELS} (?:with|to):$/) do |resource, id, levels, params|
117
120
  resource_name = get_resource(resource)
118
121
  request_hash = get_attributes(params.hashes)
119
122
  level = Level.new(levels)
@@ -131,7 +134,7 @@ end
131
134
 
132
135
  # PATCH
133
136
 
134
- When(/^I request to modify the ((?![^"]+?(?: for | in | on ))[^"]+?)(?: with (?:key|id))? "([^"]+)"(#{LEVELS})? with:$/) do |resource, id, levels, params|
137
+ When(/^I request to modify #{ARTICLE} #{RESOURCE_NAME_CAPTURE}#{WITH_ID}#{LEVELS} with:$/) do |resource, id, levels, params|
135
138
  resource_name = get_resource(resource)
136
139
  request_hash = get_attributes(params.hashes)
137
140
  json = MultiJson.dump(request_hash)
@@ -1,13 +1,16 @@
1
1
  require 'cucumber-rest-bdd/steps/resource'
2
2
  require 'cucumber-rest-bdd/types'
3
3
 
4
+ LIST_HAS_SYNONYM = %r{(?:a|an|(?:(#{FEWER_MORE_THAN_SYNONYM})\s+)?(#{INT_AS_WORDS_SYNONYM}|\d+))\s+(#{FIELD_NAME_SYNONYM})}
5
+ LIST_HAS_SYNONYM_WITHOUT_CAPTURE = %r{(?:a|an|(?:(?:#{FEWER_MORE_THAN_SYNONYM})\s+)?(?:#{INT_AS_WORDS_SYNONYM}|\d+))\s+(?:#{FIELD_NAME_SYNONYM})}
6
+
4
7
  Then(/^print the response$/) do
5
8
  puts %/The response:\n#{@response.to_json_s}/
6
9
  end
7
10
 
8
11
  # response interrogation
9
12
 
10
- Then(/^the response #{HAVE_SYNONYM} ([\w\s]+|`[^`]*`) of type (datetime|guid)$/) do |names, type|
13
+ Then(/^the response #{HAVE_SYNONYM} (#{FIELD_NAME_SYNONYM}) of type (datetime|guid)$/) do |names, type|
11
14
  regex = case type
12
15
  when 'datetime' then /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:[+|-]\d{2}:\d{2})?$/i
13
16
  when 'guid' then /^[{(]?[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$/i
@@ -16,7 +19,7 @@ Then(/^the response #{HAVE_SYNONYM} ([\w\s]+|`[^`]*`) of type (datetime|guid)$/)
16
19
  validate_value(names, 'string', regex)
17
20
  end
18
21
 
19
- Then(/^the response #{HAVE_SYNONYM} ([\w\s]+|`[^`]*`) of type (\w+) that matches "(.+)"$/) do |names, type, regex|
22
+ Then(/^the response #{HAVE_SYNONYM} (#{FIELD_NAME_SYNONYM}) of type (\w+) that matches "(.+)"$/) do |names, type, regex|
20
23
  validate_value(names, type, Regexp.new(regex))
21
24
  end
22
25
 
@@ -27,12 +30,12 @@ def validate_value(names, type, regex)
27
30
  raise %/Expected #{json_path} value '#{value}' to match regex: #{regex}\n#{@response.to_json_s}/ if (regex =~ value).nil?
28
31
  end
29
32
 
30
- Then(/^the response is a list (?:of|containing) (#{FEWER_MORE_THAN})?\s*(#{CAPTURE_INT}|\d+) .*?$/) do |count_mod, count|
33
+ Then("the response is a list of/containing {list_has_count} {field_name}") do |list_comparison, item|
31
34
  list = @response.get_as_type get_root_data_key(), 'array'
32
- raise %/Expected at least #{count} items in array for path '#{get_root_data_key()}', found: #{list.count}\n#{@response.to_json_s}/ if !num_compare(count_mod, list.count, count.to_i)
35
+ raise %/Expected at least #{count} items in array for path '#{get_root_data_key()}', found: #{list.count}\n#{@response.to_json_s}/ if !list_comparison.compare(list.count)
33
36
  end
34
37
 
35
- Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{CAPTURE_INT}|\d+)) (?:[\w\s]+|`[^`]*`) )*)#{HAVE_SYNONYM} (?:the )?(?:following )?(?:data|error )?attributes:$/) do |nesting, attributes|
38
+ Then(/^the response ((?:#{HAVE_SYNONYM}\s+#{LIST_HAS_SYNONYM_WITHOUT_CAPTURE}\s+)*)#{HAVE_SYNONYM} (?:the )?(?:following )?(?:data|error )?attributes:$/) do |nesting, attributes|
36
39
  expected = get_attributes(attributes.hashes)
37
40
  groups = nesting
38
41
  grouping = get_grouping(groups)
@@ -44,7 +47,7 @@ Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{C
44
47
  raise %/Could not find a match for: #{nesting}\n#{expected.inspect}\n#{@response.to_json_s}/ if data.empty? || !nest_match_attributes(data, grouping, expected)
45
48
  end
46
49
 
47
- Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{CAPTURE_INT}|\d+)) (?:[\w\s]+|`[^`]*`) )*)#{HAVE_SYNONYM} (?:the )?(?:following )?value "([^"]*)"$/) do |nesting, value|
50
+ Then(/^the response ((?:#{HAVE_SYNONYM}\s+#{LIST_HAS_SYNONYM_WITHOUT_CAPTURE}\s+)*)#{HAVE_SYNONYM} (?:the )?(?:following )?value "([^"]*)"$/) do |nesting, value|
48
51
  expected = value
49
52
  groups = nesting
50
53
  grouping = get_grouping(groups)
@@ -56,7 +59,7 @@ Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{C
56
59
  raise %/Could not find a match for: #{nesting}\n#{expected}\n#{@response.to_json_s}/ if data.empty? || !nest_match_value(data, grouping, expected)
57
60
  end
58
61
 
59
- Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{CAPTURE_INT}|\d+)) (?:[\w\s]+|`[^`]*`)\s?)+)$/) do |nesting|
62
+ Then(/^the response ((?:#{HAVE_SYNONYM}\s+#{LIST_HAS_SYNONYM_WITHOUT_CAPTURE}\s+)+)$/) do |nesting|
60
63
  groups = nesting
61
64
  grouping = get_grouping(groups)
62
65
  grouping.push({
@@ -67,34 +70,34 @@ Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{C
67
70
  raise %/Could not find a match for: #{nesting}\n#{@response.to_json_s}/ if data.empty? || !nest_match_attributes(data, grouping, {})
68
71
  end
69
72
 
70
- Then(/^(#{FEWER_MORE_THAN})?\s*(#{CAPTURE_INT}|\d+) (?:.*?) ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{CAPTURE_INT}|\d+)) (?:[\w\s]+|`[^`]*`) )*)#{HAVE_SYNONYM} (?:the )?(?:following )?(?:data )?attributes:$/) do |count_mod, count, nesting, attributes|
73
+ Then(/^#{LIST_HAS_SYNONYM} ((?:#{HAVE_SYNONYM}\s+#{LIST_HAS_SYNONYM_WITHOUT_CAPTURE}\s+)*)#{HAVE_SYNONYM} (?:the )?(?:following )?(?:data )?attributes:$/) do |count_mod, count, count_item, nesting, attributes|
71
74
  expected = get_attributes(attributes.hashes)
72
75
  groups = nesting
73
76
  grouping = get_grouping(groups)
74
77
  grouping.push({
75
78
  root: true,
76
79
  type: 'multiple',
77
- count: count.to_i,
78
- count_mod: count_mod
80
+ count: to_num(count),
81
+ count_mod: to_compare(count_mod)
79
82
  })
80
83
  data = @response.get get_key(grouping)
81
84
  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_attributes(data, grouping, expected)
82
85
  end
83
86
 
84
- Then(/^(#{FEWER_MORE_THAN})?\s*(#{CAPTURE_INT}|\d+) (?:.*?) ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{CAPTURE_INT}|\d+)) (?:[\w\s]+|`[^`]*`)\s?)+)$/) do |count_mod, count, nesting|
87
+ Then(/^#{LIST_HAS_SYNONYM} ((?:#{HAVE_SYNONYM}\s+#{LIST_HAS_SYNONYM_WITHOUT_CAPTURE}\s+)+)$/) do |count_mod, count, count_item, nesting|
85
88
  groups = nesting
86
89
  grouping = get_grouping(groups)
87
90
  grouping.push({
88
91
  root: true,
89
92
  type: 'multiple',
90
- count: count.to_i,
91
- count_mod: count_mod
93
+ count: to_num(count),
94
+ count_mod: to_compare(count_mod)
92
95
  })
93
96
  data = @response.get get_key(grouping)
94
97
  raise %/Expected #{compare_to_string(count_mod)}#{count} items in array with: #{nesting}\n#{@response.to_json_s}/ if !nest_match_attributes(data, grouping, {})
95
98
  end
96
99
 
97
- Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{CAPTURE_INT}|\d+)) (?:[\w\s]+|`[^`]*`) )*)#{HAVE_SYNONYM} a list of (#{FEWER_MORE_THAN})?\s*(#{CAPTURE_INT} |\d+ )?(\w+)$/) do |nesting, num_mod, num, item|
100
+ Then(/^the response ((?:#{HAVE_SYNONYM}\s+#{LIST_HAS_SYNONYM_WITHOUT_CAPTURE}\s+)*)#{HAVE_SYNONYM} a list of #{LIST_HAS_SYNONYM}$/) do |nesting, num_mod, num, item|
98
101
  groups = nesting
99
102
  list = {
100
103
  type: 'list',
@@ -114,7 +117,7 @@ Then(/^the response ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{C
114
117
  raise %/Could not find a match for #{nesting}#{compare_to_string(num_mod)}#{num} #{item}\n#{@response.to_json_s}/ if !nest_match_attributes(data, grouping, {})
115
118
  end
116
119
 
117
- Then(/^(#{FEWER_MORE_THAN})?\s*(#{CAPTURE_INT}|\d+) (?:.*?) ((?:#{HAVE_SYNONYM} (?:a|an|(?:(?:#{FEWER_MORE_THAN})?\s*#{CAPTURE_INT}|\d+)) (?:[\w\s]+|`[^`]*`) )*)#{HAVE_SYNONYM} a list of (#{FEWER_MORE_THAN})?\s*(?:(#{CAPTURE_INT}|\d+) )?(\w+)$/) do |count_mod, count, nesting, num_mod, num, item|
120
+ Then(/^#{LIST_HAS_SYNONYM} ((?:#{HAVE_SYNONYM}\s+#{LIST_HAS_SYNONYM_WITHOUT_CAPTURE}\s+)*)#{HAVE_SYNONYM} a list of #{LIST_HAS_SYNONYM}$/) do |count_mod, count, count_item, nesting, num_mod, num, item|
118
121
  groups = nesting
119
122
  list = {
120
123
  type: 'list',
@@ -129,8 +132,8 @@ Then(/^(#{FEWER_MORE_THAN})?\s*(#{CAPTURE_INT}|\d+) (?:.*?) ((?:#{HAVE_SYNONYM}
129
132
  grouping.push({
130
133
  root: true,
131
134
  type: 'multiple',
132
- count: count.to_i,
133
- count_mod: count_mod
135
+ count: to_num(count),
136
+ count_mod: to_compare(count_mod)
134
137
  })
135
138
  data = @response.get get_key(grouping)
136
139
  raise %/Expected #{compare_to_string(count_mod)}#{count} items with #{nesting}#{compare_to_string(num_mod)}#{num}#{item}\n#{@response.to_json_s}/ if !nest_match_attributes(data, grouping, {})
@@ -148,8 +151,8 @@ end
148
151
  # gets an array in the nesting format that nest_match_attributes understands to interrogate nested object and array data
149
152
  def get_grouping(nesting)
150
153
  grouping = []
151
- while matches = /^#{HAVE_SYNONYM} (?:a|an|(?:(#{FEWER_MORE_THAN})?\s*(#{CAPTURE_INT}|\d+))) ([\w\s]+|`[^`]*`)\s?+/.match(nesting)
152
- nesting = nesting[matches[0].length, nesting.length]
154
+ while matches = /#{LIST_HAS_SYNONYM}/.match(nesting)
155
+ nesting = nesting[matches.end(0), nesting.length]
153
156
  if matches[2].nil? then
154
157
  level = {
155
158
  type: 'single',
@@ -176,6 +179,10 @@ end
176
179
  #
177
180
  # returns true if the expected data is contained within the data based on the nesting information
178
181
  def nest_match_attributes(data, nesting, expected)
182
+ print 'data:' + data.to_s
183
+ print 'nesting:' + nesting.to_s
184
+ print 'expected:' + expected.to_s
185
+
179
186
  return false if !data
180
187
  return data.deep_include?(expected) if nesting.size == 0
181
188
 
@@ -183,11 +190,12 @@ def nest_match_attributes(data, nesting, expected)
183
190
  level = local_nesting.pop
184
191
  case level[:type]
185
192
  when 'single' then
186
- child_data = level[:root] ? data.dup : data[get_parameter(level[:key])]
193
+ child_data = level[:root] ? data.dup : data[get_field(level[:key])]
187
194
  return nest_match_attributes(child_data, local_nesting, expected)
188
195
  when 'multiple' then
189
- child_data = level[:root] ? data.dup : data[get_parameter(level[:key])]
196
+ child_data = level[:root] ? data.dup : data[get_field(level[:key])]
190
197
  matched = child_data.select { |item| nest_match_attributes(item, local_nesting, expected) }
198
+ print 'matched:' + matched.count.to_s
191
199
  return num_compare(level[:count_mod], matched.count, level[:count])
192
200
  when 'list' then
193
201
  child_data = level[:root] ? data.dup : data[get_resource(level[:key])]
@@ -209,11 +217,11 @@ def nest_match_value(data, nesting, expected)
209
217
  level = local_nesting.pop
210
218
  case level[:type]
211
219
  when 'single' then
212
- child_data = level[:root] ? data.dup : data[get_parameter(level[:key])]
220
+ child_data = level[:root] ? data.dup : data[get_field(level[:key])]
213
221
  return nest_match_value(child_data, local_nesting, expected)
214
222
  when 'multiple' then
215
- child_data = level[:root] ? data.dup : data[get_parameter(level[:key])]
216
- raise %/Key not found: #{level[:key]} as #{get_parameter(level[:key])} in #{data}/ if !child_data
223
+ child_data = level[:root] ? data.dup : data[get_field(level[:key])]
224
+ raise %/Key not found: #{level[:key]} as #{get_field(level[:key])} in #{data}/ if !child_data
217
225
  matched = child_data.select { |item| nest_match_value(item, local_nesting, expected) }
218
226
  return num_compare(level[:count_mod], matched.count, level[:count])
219
227
  when 'list' then
@@ -1,14 +1,40 @@
1
1
  require 'active_support/inflector'
2
2
 
3
- CAPTURE_INT = Transform(/^(?:zero|one|two|three|four|five|six|seven|eight|nine|ten)$/) do |v|
4
- %w(zero one two three four five six seven eight nine ten).index(v)
5
- end
6
-
7
- FEWER_MORE_THAN = Transform(/^(?:(?:fewer|less|more) than|at (?:least|most))$/) do |v|
8
- to_compare(v)
9
- end
10
-
11
3
  HAVE_SYNONYM = %{(?:has|have|having|contain|contains|containing|with)}
4
+ RESOURCE_NAME = '[\w\s]+'
5
+ RESOURCE_NAME_CAPTURE = /([\w\s]+)/
6
+ ARTICLE = %{(?:an?|the)}
7
+ FIELD_NAME_SYNONYM = %q{[\w\s]+|`[^`]*`}
8
+ FEWER_MORE_THAN_SYNONYM = %q{(?:fewer|less|more) than|at (?:least|most)}
9
+ INT_AS_WORDS_SYNONYM = %q{zero|one|two|three|four|five|six|seven|eight|nine|ten}
10
+
11
+ ParameterType(
12
+ name: 'field_name',
13
+ regexp: /[\w\s]+|`[^`]*`/,
14
+ transformer: -> (s) { get_fields(s) },
15
+ use_for_snippets: false
16
+ )
17
+
18
+ ParameterType(
19
+ name: 'int_as_words',
20
+ regexp: /#{INT_AS_WORDS_SYNONYM}/,
21
+ transformer: -> (s) { to_num(s) }
22
+ )
23
+
24
+ ParameterType(
25
+ name: 'fewer_more_than',
26
+ regexp: /#{FEWER_MORE_THAN_SYNONYM}/,
27
+ transformer: -> (s) { to_compare(s) }
28
+ )
29
+
30
+ ParameterType(
31
+ name: 'list_has_count',
32
+ regexp: /a|an|(?:(#{FEWER_MORE_THAN_SYNONYM})\s+)?(#{INT_AS_WORDS_SYNONYM})/,
33
+ transformer: -> (count_mod, count) {
34
+ ListCountComparison.new(count_mod.nil? ? to_compare(count_mod) : CMP_EQUALS, count.nil? ? to_num(count) : 1)
35
+ },
36
+ use_for_snippets: false
37
+ )
12
38
 
13
39
  CMP_LESS_THAN = '<'
14
40
  CMP_MORE_THAN = '>'
@@ -40,7 +66,7 @@ def compare_to_string(compare)
40
66
  end
41
67
  end
42
68
 
43
- # compare two numbers using the FEWER_MORE_THAN optional modifier
69
+ # compare two numbers using the fewer_more_than optional modifier
44
70
  def num_compare(type, left, right)
45
71
  case type
46
72
  when CMP_LESS_THAN then left < right
@@ -79,6 +105,24 @@ class String
79
105
  end
80
106
  end
81
107
 
108
+ class ListCountComparison
109
+ def initialize(type, amount)
110
+ @type = type
111
+ @amount = amount
112
+ end
113
+
114
+ def compare(actual)
115
+ case @type
116
+ when CMP_LESS_THAN then actual < @amount
117
+ when CMP_MORE_THAN then actual > @amount
118
+ when CMP_AT_MOST then actual <= @amount
119
+ when CMP_AT_LEAST then actual >= @amount
120
+ when CMP_EQUALS then actual == @amount
121
+ else actual == @amount
122
+ end
123
+ end
124
+ end
125
+
82
126
  def parse_type(type)
83
127
  replacements = {
84
128
  /^numeric$/i => 'integer',
@@ -112,14 +156,14 @@ def get_root_error_key()
112
156
  end
113
157
 
114
158
  def get_json_path(names)
115
- return "#{get_root_data_key()}#{get_parameters(names).join('.')}"
159
+ return "#{get_root_data_key()}#{get_fields(names).join('.')}"
116
160
  end
117
161
 
118
- def get_parameters(names)
119
- return names.split(':').map { |n| get_parameter(n.strip) }
162
+ def get_fields(names)
163
+ return names.split(':').map { |n| get_field(n.strip) }
120
164
  end
121
165
 
122
- def get_parameter(name)
166
+ def get_field(name)
123
167
  if name[0] == '`' && name[-1] == '`'
124
168
  name = name[1..-2]
125
169
  elsif name[0] != '[' || name[-1] != ']'
@@ -136,7 +180,7 @@ def get_attributes(hashes)
136
180
  value = resolve(value)
137
181
  value.gsub!(/\\n/, "\n")
138
182
  type = parse_type(type)
139
- names = get_parameters(name)
183
+ names = get_fields(name)
140
184
  new_hash = names.reverse.inject(value.to_type(type.camelize.constantize)) { |a, n| add_to_hash(a, n) }
141
185
  hash.deep_merge!(new_hash) { |key, old, new| new.kind_of?(Array) ? merge_arrays(old, new) : new }
142
186
  end
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.14
4
+ version: 0.5.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Bragg
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.6.14
95
+ rubygems_version: 2.6.13
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: BDD Rest API specifics for cucumber