cucumber-expressions 4.0.4 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cucumber-expressions.gemspec +1 -1
- data/lib/cucumber/cucumber_expressions/argument.rb +4 -2
- data/lib/cucumber/cucumber_expressions/parameter_type.rb +5 -3
- data/spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb +32 -3
- data/spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb +9 -9
- data/spec/cucumber/cucumber_expressions/expression_examples_spec.rb +1 -1
- data/spec/cucumber/cucumber_expressions/regular_expression_spec.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 496273cb3a1f1f91726135226ec1d3e8d69eef38
|
4
|
+
data.tar.gz: 7d0b9fe4bb923c498b8202a9a94c4bf62d86bb26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f1052d6c856b8d34a6ac44eb2027bf60b3e0f89d0089d3d76f0f58a913de40abe2c97c318142787c291bee3b084a8feda60d5728da5f7ab97230e1e682cb9ab
|
7
|
+
data.tar.gz: 6118073dcf156c9e2a9d580252aade7b371aa5202fb4a5ab7e29332b8ae57fffdd561037002bf7f42269cde1d6cff61986865dd5cf8de86595a96169b051979a
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'cucumber-expressions'
|
4
|
-
s.version = '
|
4
|
+
s.version = '5.0.0'
|
5
5
|
s.authors = ["Aslak Hellesøy"]
|
6
6
|
s.description = 'Cucumber Expressions - a simpler alternative to Regular Expressions'
|
7
7
|
s.summary = "cucumber-expressions-#{s.version}"
|
@@ -27,8 +27,10 @@ module Cucumber
|
|
27
27
|
@group, @parameter_type = group, parameter_type
|
28
28
|
end
|
29
29
|
|
30
|
-
def value
|
31
|
-
|
30
|
+
def value(self_obj=:nil)
|
31
|
+
raise "No self_obj" if self_obj == :nil
|
32
|
+
group_values = @group ? @group.values : nil
|
33
|
+
@parameter_type.transform(self_obj, group_values)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -34,15 +34,17 @@ module Cucumber
|
|
34
34
|
@regexps = string_array(regexp)
|
35
35
|
end
|
36
36
|
|
37
|
-
def transform(group_values)
|
37
|
+
def transform(self_obj, group_values)
|
38
38
|
if @transformer.arity == 1
|
39
39
|
non_nil_group_values = group_values.compact
|
40
40
|
raise CucumberExpressionError.new(
|
41
41
|
"Single transformer unexpectedly matched 2 values - \"#{non_nil_group_values[0]}\" and \"${non_nil_group_values[1]}\""
|
42
42
|
) if non_nil_group_values.length >= 2
|
43
|
-
|
43
|
+
args = [non_nil_group_values[0]]
|
44
|
+
else
|
45
|
+
args = group_values
|
44
46
|
end
|
45
|
-
|
47
|
+
self_obj.instance_exec(*args, &@transformer)
|
46
48
|
end
|
47
49
|
|
48
50
|
def <=>(other)
|
@@ -11,7 +11,7 @@ module Cucumber
|
|
11
11
|
expr = "I have {int} cuke(s)"
|
12
12
|
expression = CucumberExpression.new(expr, parameter_registry)
|
13
13
|
args = expression.match("I have 7 cukes")
|
14
|
-
expect(args[0].value).to eq(7)
|
14
|
+
expect(args[0].value(nil)).to eq(7)
|
15
15
|
### [capture-match-arguments]
|
16
16
|
end
|
17
17
|
|
@@ -69,13 +69,42 @@ module Cucumber
|
|
69
69
|
expect(CucumberExpression.new(expr, ParameterTypeRegistry.new).source).to eq(expr)
|
70
70
|
end
|
71
71
|
|
72
|
+
it "delegates transform to custom object" do
|
73
|
+
parameter_type_registry = ParameterTypeRegistry.new
|
74
|
+
parameter_type_registry.define_parameter_type(
|
75
|
+
ParameterType.new(
|
76
|
+
'widget',
|
77
|
+
/\w+/,
|
78
|
+
Object,
|
79
|
+
-> (s) {
|
80
|
+
self.create_widget(s)
|
81
|
+
},
|
82
|
+
false,
|
83
|
+
true
|
84
|
+
)
|
85
|
+
)
|
86
|
+
expression = CucumberExpression.new(
|
87
|
+
'I have a {widget}',
|
88
|
+
parameter_type_registry
|
89
|
+
)
|
90
|
+
|
91
|
+
class World
|
92
|
+
def create_widget(s)
|
93
|
+
"widget:#{s}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
args = expression.match("I have a bolt")
|
98
|
+
expect(args[0].value(World.new)).to eq('widget:bolt')
|
99
|
+
end
|
100
|
+
|
72
101
|
describe "escapes special characters" do
|
73
102
|
%w(\\ [ ] ^ $ . | ? * +).each do |character|
|
74
103
|
it "escapes #{character}" do
|
75
104
|
expr = "I have {int} cuke(s) and #{character}"
|
76
105
|
expression = CucumberExpression.new(expr, ParameterTypeRegistry.new)
|
77
106
|
arg1 = expression.match("I have 800 cukes and #{character}")[0]
|
78
|
-
expect(arg1.value).to eq(800)
|
107
|
+
expect(arg1.value(nil)).to eq(800)
|
79
108
|
end
|
80
109
|
end
|
81
110
|
end
|
@@ -84,7 +113,7 @@ module Cucumber
|
|
84
113
|
cucumber_expression = CucumberExpression.new(expression, ParameterTypeRegistry.new)
|
85
114
|
args = cucumber_expression.match(text)
|
86
115
|
return nil if args.nil?
|
87
|
-
args.map {|arg| arg.value}
|
116
|
+
args.map {|arg| arg.value(nil)}
|
88
117
|
end
|
89
118
|
end
|
90
119
|
end
|
@@ -62,7 +62,7 @@ module Cucumber
|
|
62
62
|
describe CucumberExpression do
|
63
63
|
it "matches parameters with custom parameter type" do
|
64
64
|
expression = CucumberExpression.new("I have a {color} ball", @parameter_type_registry)
|
65
|
-
transformed_argument_value = expression.match("I have a red ball")[0].value
|
65
|
+
transformed_argument_value = expression.match("I have a red ball")[0].value(nil)
|
66
66
|
expect(transformed_argument_value).to eq(Color.new('red'))
|
67
67
|
end
|
68
68
|
|
@@ -82,13 +82,13 @@ module Cucumber
|
|
82
82
|
)
|
83
83
|
args = expression.match('A 5 thick line from 10,20,30 to 40,50,60')
|
84
84
|
|
85
|
-
thick = args[0].value
|
85
|
+
thick = args[0].value(nil)
|
86
86
|
expect(thick).to eq(5)
|
87
87
|
|
88
|
-
from = args[1].value
|
88
|
+
from = args[1].value(nil)
|
89
89
|
expect(from).to eq(Coordinate.new(10, 20, 30))
|
90
90
|
|
91
|
-
to = args[2].value
|
91
|
+
to = args[2].value(nil)
|
92
92
|
expect(to).to eq(Coordinate.new(40, 50, 60))
|
93
93
|
end
|
94
94
|
|
@@ -103,7 +103,7 @@ module Cucumber
|
|
103
103
|
false
|
104
104
|
))
|
105
105
|
expression = CucumberExpression.new("I have a {color} ball", parameter_type_registry)
|
106
|
-
transformed_argument_value = expression.match("I have a dark red ball")[0].value
|
106
|
+
transformed_argument_value = expression.match("I have a dark red ball")[0].value(nil)
|
107
107
|
expect(transformed_argument_value).to eq(Color.new('dark red'))
|
108
108
|
end
|
109
109
|
|
@@ -118,7 +118,7 @@ module Cucumber
|
|
118
118
|
))
|
119
119
|
expression = CucumberExpression.new("I have a {throwing} parameter", @parameter_type_registry)
|
120
120
|
args = expression.match("I have a bad parameter")
|
121
|
-
expect {args[0].value}.to raise_error("Can't transform [bad]")
|
121
|
+
expect {args[0].value(nil)}.to raise_error("Can't transform [bad]")
|
122
122
|
end
|
123
123
|
|
124
124
|
describe "conflicting parameter type" do
|
@@ -157,11 +157,11 @@ module Cucumber
|
|
157
157
|
))
|
158
158
|
|
159
159
|
css_color = CucumberExpression.new("I have a {css-color} ball", @parameter_type_registry)
|
160
|
-
css_color_value = css_color.match("I have a blue ball")[0].value
|
160
|
+
css_color_value = css_color.match("I have a blue ball")[0].value(nil)
|
161
161
|
expect(css_color_value).to eq(CssColor.new("blue"))
|
162
162
|
|
163
163
|
color = CucumberExpression.new("I have a {color} ball", @parameter_type_registry)
|
164
|
-
color_value = color.match("I have a blue ball")[0].value
|
164
|
+
color_value = color.match("I have a blue ball")[0].value(nil)
|
165
165
|
expect(color_value).to eq(Color.new("blue"))
|
166
166
|
end
|
167
167
|
end
|
@@ -170,7 +170,7 @@ module Cucumber
|
|
170
170
|
describe RegularExpression do
|
171
171
|
it "matches arguments with custom parameter type" do
|
172
172
|
expression = RegularExpression.new(/I have a (red|blue|yellow) ball/, @parameter_type_registry)
|
173
|
-
value = expression.match("I have a red ball")[0].value
|
173
|
+
value = expression.match("I have a red ball")[0].value(nil)
|
174
174
|
expect(value).to eq(Color.new('red'))
|
175
175
|
end
|
176
176
|
end
|
@@ -13,7 +13,7 @@ module Cucumber
|
|
13
13
|
|
14
14
|
arguments = expression.match(text)
|
15
15
|
return nil if arguments.nil?
|
16
|
-
arguments.map { |arg| arg.value }
|
16
|
+
arguments.map { |arg| arg.value(nil) }
|
17
17
|
end
|
18
18
|
|
19
19
|
File.open(File.expand_path("../../../../examples.txt", __FILE__), "r:utf-8") do |io|
|
@@ -11,8 +11,8 @@ module Cucumber
|
|
11
11
|
expr = /I have (\d+) cukes? in my (\w*) now/
|
12
12
|
expression = RegularExpression.new(expr, parameter_type_registry)
|
13
13
|
args = expression.match("I have 7 cukes in my belly now")
|
14
|
-
expect( args[0].value ).to eq(7)
|
15
|
-
expect( args[1].value ).to eq("belly")
|
14
|
+
expect( args[0].value(nil) ).to eq(7)
|
15
|
+
expect( args[1].value(nil) ).to eq("belly")
|
16
16
|
### [capture-match-arguments]
|
17
17
|
end
|
18
18
|
|
@@ -62,7 +62,7 @@ module Cucumber
|
|
62
62
|
regular_expression = RegularExpression.new(expression, ParameterTypeRegistry.new)
|
63
63
|
arguments = regular_expression.match(text)
|
64
64
|
return nil if arguments.nil?
|
65
|
-
arguments.map { |arg| arg.value }
|
65
|
+
arguments.map { |arg| arg.value(nil) }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-expressions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aslak Hellesøy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,7 +130,7 @@ rubyforge_project:
|
|
130
130
|
rubygems_version: 2.6.8
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
|
-
summary: cucumber-expressions-
|
133
|
+
summary: cucumber-expressions-5.0.0
|
134
134
|
test_files:
|
135
135
|
- spec/capture_warnings.rb
|
136
136
|
- spec/coverage.rb
|