alinta-cucumber-rest-bdd 0.5.18 → 0.5.19

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
- SHA256:
3
- metadata.gz: 306b023580a0ac0b19100533e7b4e73d797157c9265927b40f538b742cd0af4a
4
- data.tar.gz: 2078787c5b3635af8df6f7f1b18b9623cdf763bd46a2925010062947f95c18f9
2
+ SHA1:
3
+ metadata.gz: 27c980d29ee35952fbc7bc96f4795dc0af56e31c
4
+ data.tar.gz: cbe202b5007ade6def21773d8a2bd6ed1ac838a8
5
5
  SHA512:
6
- metadata.gz: 2e9120ceb72b2398c55a93db9444e6197b2f76ee3b46c9ce0a9d57758691aa939a7607dbec7d8c6eda95afcc6acba440fe87d3415e70fb0589e37992dfdfa870
7
- data.tar.gz: 19acc5ff1a069aa7c5621ffc4c2aa8bcbac0b91c67f9f2372aa49ab240668f595ba945e49cc6946b433578361774608ccaf31c514c8c56d067099a520a0f2daa
6
+ metadata.gz: be9194bbf9479cb44f9b1cd3ee6ebe610fbd23c5ec049d69ee80677245414ee23e7be667cee6d65edbeadcf1275cf34e54ef79de37e638f8e932293b00cd82fb
7
+ data.tar.gz: 2e7c5f36fa32a8cda7e3dcacf0f132cfc9968c9b23f96e63f73bcf1058a1afaa693db70d9eaf695fc623eb96ce21bd5a7a216aa62b4ab35c75814ffacb596b98
@@ -17,11 +17,13 @@ Then("the response #{HAVE_ALTERNATION} {field_name} of type {word}") do |field,
17
17
  end
18
18
 
19
19
  type = 'string' if regex.nil?
20
- field.validate_value(field.get_value(type), Regexp.new(regex))
20
+ value = field.get_value(@response, type)
21
+ field.validate_value(@response, value.to_s, Regexp.new(regex))
21
22
  end
22
23
 
23
24
  Then("the response #{HAVE_ALTERNATION} {field_name} of type {word} that matches {string}") do |field, type, regex|
24
- field.validate_value(field.get_value(type), Regexp.new(regex))
25
+ value = field.get_value(@response, type)
26
+ field.validate_value(@response, value.to_s, Regexp.new(regex))
25
27
  end
26
28
 
27
29
  Then("the response is a list of/containing {list_has_count} {field_name}") do |list_comparison, item|
@@ -2,8 +2,8 @@ require 'active_support/inflector'
2
2
 
3
3
  HAVE_ALTERNATION = "has/have/having/contain/contains/containing/with"
4
4
  RESOURCE_NAME_SYNONYM = '\w+\b(?:\s+\w+\b)*?|`[^`]*`'
5
- FIELD_NAME_SYNONYM = "#{RESOURCE_NAME_SYNONYM}"
6
- MAXIMAL_FIELD_NAME_SYNONYM = '\w+\b(?:\s+\w+\b)*|`[^`]*`'
5
+ FIELD_NAME_SYNONYM = '\w+\b(?:(?:\s+:)?\s+\w+\b)*?|`[^`]*`'
6
+ MAXIMAL_FIELD_NAME_SYNONYM = '\w+\b(?:(?:\s+:)?\s+\w+\b)*|`[^`]*`'
7
7
 
8
8
  ParameterType(
9
9
  name: 'resource_name',
@@ -48,23 +48,23 @@ class ResponseField
48
48
  return "#{get_root_data_key()}#{@fields.join('.')}"
49
49
  end
50
50
 
51
- def get_value(type)
52
- return @response.get_as_type to_json_path(), parse_type(type)
51
+ def get_value(response, type)
52
+ return response.get_as_type to_json_path(), parse_type(type)
53
53
  end
54
54
 
55
- def validate_value(value, regex)
56
- raise %/Expected #{json_path} value '#{value}' to match regex: #{regex}\n#{@response.to_json_s}/ if (regex =~ value).nil?
55
+ def validate_value(response, value, regex)
56
+ raise %/Expected #{json_path} value '#{value}' to match regex: #{regex}\n#{response.to_json_s}/ if (regex =~ value).nil?
57
57
  end
58
58
  end
59
59
 
60
60
  def parse_type(type)
61
61
  replacements = {
62
- /^numeric$/i => 'integer',
63
- /^int$/i => 'integer',
64
- /^long$/i => 'integer',
65
- /^number$/i => 'integer',
66
- /^decimal$/i => 'float',
67
- /^double$/i => 'float',
62
+ /^numeric$/i => 'numeric',
63
+ /^int$/i => 'numeric',
64
+ /^long$/i => 'numeric',
65
+ /^number$/i => 'numeric',
66
+ /^decimal$/i => 'numeric',
67
+ /^double$/i => 'numeric',
68
68
  /^bool$/i => 'boolean',
69
69
  /^null$/i => 'nil_class',
70
70
  /^nil$/i => 'nil_class',
@@ -111,6 +111,7 @@ end
111
111
  def get_attributes(hashes)
112
112
  attributes = hashes.each_with_object({}) do |row, hash|
113
113
  name, value, type = row["attribute"], row["value"], row["type"]
114
+ value = resolve_functions(value)
114
115
  value = resolve(value)
115
116
  value.gsub!(/\\n/, "\n")
116
117
  type = parse_type(type)
@@ -120,6 +121,19 @@ def get_attributes(hashes)
120
121
  end
121
122
  end
122
123
 
124
+ def resolve_functions(value)
125
+ value.gsub!(/\[([a-zA-Z0-9_]+)\]/) do |s|
126
+ s.gsub!(/[\[\]]/, '')
127
+ case s.downcase
128
+ when "datetime"
129
+ Time.now.strftime("%Y%m%d%H%M%S")
130
+ else
131
+ raise 'Unrecognised function ' + s + '?'
132
+ end
133
+ end
134
+ value
135
+ end
136
+
123
137
  def add_to_hash(a, n)
124
138
  result = nil
125
139
  if (n[0] == '[' && n[-1] == ']') then
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.18
4
+ version: 0.5.19
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-04-02 00:00:00.000000000 Z
12
+ date: 2018-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber-api
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.7.6
97
+ rubygems_version: 2.6.14
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: BDD Rest API specifics for cucumber