alinta-cucumber-rest-bdd 0.5.19 → 0.5.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/cucumber-rest-bdd/list.rb +7 -3
- data/lib/cucumber-rest-bdd/steps/response.rb +33 -3
- data/lib/cucumber-rest-bdd/types.rb +29 -15
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fbffb705889af8cb87393b7617f1c084c145c31ce37851e0bcbd83f99827bf86
|
4
|
+
data.tar.gz: 859abac39ab824a2386976b85badae3a9d60920bd511f917b1b308bc8c04ef6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3281d942a833aa3dcd689e53aa394e267a58b782632b544d93026bf2dc81d55b516fcf007772a4fde0ff5a9d71ec90b7298f46ac1a599be99aa0e8f77c4517c4
|
7
|
+
data.tar.gz: 2d9eaa3ed011778ef147668e16b7abaa3c9a16ccf9d04d3e6d3bb2da70a0622c4563dbdf278f792969b3221faaec21a2922837dfe7e04f9c7586b017924492f8
|
@@ -5,14 +5,17 @@ INT_AS_WORDS_SYNONYM = %q{zero|one|two|three|four|five|six|seven|eight|nine|ten}
|
|
5
5
|
|
6
6
|
ParameterType(
|
7
7
|
name: 'list_has_count',
|
8
|
-
regexp: /a|an|(?:(
|
9
|
-
transformer: -> (
|
8
|
+
regexp: /a|an|(?:(?:#{FEWER_MORE_THAN_SYNONYM})\s+)?(?:#{INT_AS_WORDS_SYNONYM}|\d+)/,
|
9
|
+
transformer: -> (match) {
|
10
|
+
matches = /(?:(#{FEWER_MORE_THAN_SYNONYM})\s+)?(#{INT_AS_WORDS_SYNONYM}|\d+)/.match(match)
|
11
|
+
return ListCountComparison.new(matches[1], matches[2])
|
12
|
+
},
|
10
13
|
use_for_snippets: false
|
11
14
|
)
|
12
15
|
|
13
16
|
ParameterType(
|
14
17
|
name: 'list_nesting',
|
15
|
-
regexp: %r{(
|
18
|
+
regexp: %r{(?:(?:#{HAVE_ALTERNATION.split('/').join('|')})\s+(?:a list of\s+)?(?:a|an|(?:(?:#{FEWER_MORE_THAN_SYNONYM})\s+)?(?:#{INT_AS_WORDS_SYNONYM}|\d+))\s+(?:#{FIELD_NAME_SYNONYM})\s*)+},
|
16
19
|
transformer: -> (match) { ListNesting.new(match) },
|
17
20
|
use_for_snippets: false
|
18
21
|
)
|
@@ -73,6 +76,7 @@ class ListNesting
|
|
73
76
|
end
|
74
77
|
|
75
78
|
class ListCountComparison
|
79
|
+
|
76
80
|
def initialize(type, amount)
|
77
81
|
@type = type.nil? ? CMP_EQUALS : to_compare(type)
|
78
82
|
@amount = amount.nil? ? 1 : to_num(amount)
|
@@ -31,7 +31,37 @@ Then("the response is a list of/containing {list_has_count} {field_name}") do |l
|
|
31
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
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
# Responses without nesting
|
35
|
+
|
36
|
+
Then("the response #{HAVE_ALTERNATION} (the )(following )attributes:") do |attributes|
|
37
|
+
expected = get_attributes(attributes.hashes)
|
38
|
+
data = @response.get get_root_data_key()
|
39
|
+
raise %/Response did not match:\n#{expected.inspect}\n#{data}/ if data.empty? || !data.deep_include?(expected)
|
40
|
+
end
|
41
|
+
|
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)
|
46
|
+
end
|
47
|
+
|
48
|
+
Then("{list_has_count} {field_name} #{HAVE_ALTERNATION} (the )(following )(data )attributes:") do |list_comparison, count_item, attributes|
|
49
|
+
expected = get_attributes(attributes.hashes)
|
50
|
+
data = @response.get get_root_data_key()
|
51
|
+
matched = data.select { |item| !item.empty? && item.deep_include?(expected) }
|
52
|
+
raise %/Expected #{list_comparison.to_string()} items in array that matched:\n#{expected.inspect}\n#{data}/ if !list_comparison.compare(matched.count)
|
53
|
+
end
|
54
|
+
|
55
|
+
Then("{list_has_count} {field_name} #{HAVE_ALTERNATION} (the )(following )value {string}") do |list_comparison, count_item, value|
|
56
|
+
expected = value
|
57
|
+
data = @response.get get_root_data_key()
|
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)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Responses with nesting
|
63
|
+
|
64
|
+
Then("the response {list_nesting} #{HAVE_ALTERNATION} (the )(following )attributes:") do |nesting, attributes|
|
35
65
|
expected = get_attributes(attributes.hashes)
|
36
66
|
nesting.push({
|
37
67
|
root: true,
|
@@ -41,7 +71,7 @@ Then("the response( {list_nesting}) #{HAVE_ALTERNATION} (the )(following )attrib
|
|
41
71
|
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)
|
42
72
|
end
|
43
73
|
|
44
|
-
Then("the response
|
74
|
+
Then("the response {list_nesting} #{HAVE_ALTERNATION} (the )(following )value {string}") do |nesting, value|
|
45
75
|
expected = value
|
46
76
|
nesting.push({
|
47
77
|
root: true,
|
@@ -60,7 +90,7 @@ Then("the response {list_nesting}") do |nesting|
|
|
60
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)
|
61
91
|
end
|
62
92
|
|
63
|
-
Then("{list_has_count} {field_name}
|
93
|
+
Then("{list_has_count} {field_name} {list_nesting} #{HAVE_ALTERNATION} (the )(following )(data )attributes:") do |list_comparison, count_item, nesting, attributes|
|
64
94
|
expected = get_attributes(attributes.hashes)
|
65
95
|
nesting.push({
|
66
96
|
root: true,
|
@@ -26,19 +26,6 @@ class FalseClass; include Boolean; end
|
|
26
26
|
module Enum; end
|
27
27
|
class String; include Enum; end
|
28
28
|
|
29
|
-
class String
|
30
|
-
def to_type(type)
|
31
|
-
# cannot use 'case type' which checks for instances of a type rather than type equality
|
32
|
-
if type == Boolean then !(self =~ /true|yes/i).nil?
|
33
|
-
elsif type == Enum then self.upcase.tr(" ", "_")
|
34
|
-
elsif type == Float then self.to_f
|
35
|
-
elsif type == Integer then self.to_i
|
36
|
-
elsif type == NilClass then nil
|
37
|
-
else self
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
29
|
class ResponseField
|
43
30
|
def initialize(names)
|
44
31
|
@fields = get_fields(names)
|
@@ -68,6 +55,7 @@ def parse_type(type)
|
|
68
55
|
/^bool$/i => 'boolean',
|
69
56
|
/^null$/i => 'nil_class',
|
70
57
|
/^nil$/i => 'nil_class',
|
58
|
+
/^string$/i => 'string',
|
71
59
|
/^text$/i => 'string'
|
72
60
|
}
|
73
61
|
type.tr(' ', '_')
|
@@ -75,6 +63,33 @@ def parse_type(type)
|
|
75
63
|
type
|
76
64
|
end
|
77
65
|
|
66
|
+
def string_to_type(value, type)
|
67
|
+
replacements = {
|
68
|
+
/^numeric$/i => 'integer',
|
69
|
+
/^int$/i => 'integer',
|
70
|
+
/^long$/i => 'integer',
|
71
|
+
/^number$/i => 'integer',
|
72
|
+
/^decimal$/i => 'float',
|
73
|
+
/^double$/i => 'float',
|
74
|
+
/^bool$/i => 'boolean',
|
75
|
+
/^null$/i => 'nil_class',
|
76
|
+
/^nil$/i => 'nil_class',
|
77
|
+
/^string$/i => 'string',
|
78
|
+
/^text$/i => 'string'
|
79
|
+
}
|
80
|
+
type.tr(' ', '_')
|
81
|
+
replacements.each { |k,v| type.gsub!(k, v) }
|
82
|
+
type = type.camelize.constantize
|
83
|
+
# cannot use 'case type' which checks for instances of a type rather than type equality
|
84
|
+
if type == Boolean then !(value =~ /true|yes/i).nil?
|
85
|
+
elsif type == Enum then value.upcase.tr(" ", "_")
|
86
|
+
elsif type == Float then value.to_f
|
87
|
+
elsif type == Integer then value.to_i
|
88
|
+
elsif type == NilClass then nil
|
89
|
+
else value
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
78
93
|
def get_resource(name)
|
79
94
|
if name[0] == '`' && name[-1] == '`'
|
80
95
|
name = name[1..-2]
|
@@ -114,9 +129,8 @@ def get_attributes(hashes)
|
|
114
129
|
value = resolve_functions(value)
|
115
130
|
value = resolve(value)
|
116
131
|
value.gsub!(/\\n/, "\n")
|
117
|
-
type = parse_type(type)
|
118
132
|
names = get_fields(name)
|
119
|
-
new_hash = names.reverse.inject(value
|
133
|
+
new_hash = names.reverse.inject(string_to_type(value, type)) { |a, n| add_to_hash(a, n) }
|
120
134
|
hash.deep_merge!(new_hash) { |key, old, new| new.kind_of?(Array) ? merge_arrays(old, new) : new }
|
121
135
|
end
|
122
136
|
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.
|
4
|
+
version: 0.5.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Bragg
|
@@ -17,14 +17,34 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '0.
|
20
|
+
version: '0.6'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '0.
|
27
|
+
version: '0.6'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: cucumber-expressions
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '5.0'
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 5.0.17
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - "~>"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '5.0'
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.0.17
|
28
48
|
- !ruby/object:Gem::Dependency
|
29
49
|
name: activesupport
|
30
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
114
|
version: '0'
|
95
115
|
requirements: []
|
96
116
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.6
|
117
|
+
rubygems_version: 2.7.6
|
98
118
|
signing_key:
|
99
119
|
specification_version: 4
|
100
120
|
summary: BDD Rest API specifics for cucumber
|