cucumber-expressions 2.0.0 → 2.0.1
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 +7 -3
- data/lib/cucumber/cucumber_expressions/argument_builder.rb +1 -2
- data/lib/cucumber/cucumber_expressions/parameter_registry.rb +3 -3
- data/spec/cucumber/cucumber_expressions/custom_parameter_spec.rb +31 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8c5e8a795eb6fea91f46e61cc01985a8af0572d
|
4
|
+
data.tar.gz: 92fa95001cddb0f9d931a02602c0e2d793678d53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7baf62e65277d441049bce8133cc50a6b44a48027cdf53a921b14006cac39358b45ba838890d43d1b1f7ec0edd8a74197e32b2979bfe8885bc5c4b1c963f0c12
|
7
|
+
data.tar.gz: 44b4dd881b1b7d8649f185b4f60a31ecf91f4ff1ccf6b7934ecd9d1b143200bf0c2ee74f4913c3f4ea308457943ffbacf02d3bfede92dca31746cc698e522749
|
@@ -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 = '2.0.
|
4
|
+
s.version = '2.0.1'
|
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}"
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module Cucumber
|
2
2
|
module CucumberExpressions
|
3
3
|
class Argument
|
4
|
-
attr_reader :offset, :value
|
4
|
+
attr_reader :offset, :value
|
5
5
|
|
6
|
-
def initialize(offset, value,
|
7
|
-
@offset, @value, @
|
6
|
+
def initialize(offset, value, parameter)
|
7
|
+
@offset, @value, @parameter = offset, value, parameter
|
8
|
+
end
|
9
|
+
|
10
|
+
def transformed_value
|
11
|
+
@parameter.transform(@value)
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
@@ -9,8 +9,7 @@ module Cucumber
|
|
9
9
|
(1...m.length).map do |index|
|
10
10
|
value = m[index]
|
11
11
|
parameter = parameters[index-1]
|
12
|
-
|
13
|
-
Argument.new(m.offset(index)[0], value, transformed_value)
|
12
|
+
Argument.new(m.offset(index)[0], value, parameter)
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -3,8 +3,8 @@ require 'cucumber/cucumber_expressions/parameter'
|
|
3
3
|
module Cucumber
|
4
4
|
module CucumberExpressions
|
5
5
|
class ParameterRegistry
|
6
|
-
INTEGER_REGEXPS = [
|
7
|
-
|
6
|
+
INTEGER_REGEXPS = [/-?\d+/, /\d+/]
|
7
|
+
FLOAT_REGEXPS = [/-?\d*\.?\d+/]
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@parameters_by_type_name = {}
|
@@ -12,7 +12,7 @@ module Cucumber
|
|
12
12
|
@parameters_by_class = {}
|
13
13
|
|
14
14
|
add_parameter(Parameter.new('int', Integer, INTEGER_REGEXPS, lambda {|s| s.to_i}))
|
15
|
-
add_parameter(Parameter.new('float', Float,
|
15
|
+
add_parameter(Parameter.new('float', Float, FLOAT_REGEXPS, lambda {|s| s.to_f}))
|
16
16
|
end
|
17
17
|
|
18
18
|
def lookup_by_type(type)
|
@@ -20,66 +20,79 @@ module Cucumber
|
|
20
20
|
|
21
21
|
describe "Custom parameter" do
|
22
22
|
before do
|
23
|
-
@parameter_registry = ParameterRegistry.new
|
24
23
|
### [add-color-parameter]
|
25
|
-
|
24
|
+
parameter_registry = ParameterRegistry.new
|
25
|
+
parameter_registry.add_parameter(Parameter.new(
|
26
26
|
'color',
|
27
27
|
Color,
|
28
28
|
[/red|blue|yellow/, /(?:dark|light) (?:red|blue|yellow)/],
|
29
29
|
lambda { |s| Color.new(s) }
|
30
30
|
))
|
31
31
|
### [add-color-parameter]
|
32
|
+
@parameter_registry = parameter_registry
|
32
33
|
end
|
33
34
|
|
34
35
|
describe CucumberExpression do
|
35
36
|
it "matches typed parameters" do
|
36
37
|
expression = CucumberExpression.new("I have a {color} ball", [], @parameter_registry)
|
37
|
-
|
38
|
-
expect(
|
38
|
+
transformed_argument_value = expression.match("I have a red ball")[0].transformed_value
|
39
|
+
expect( transformed_argument_value ).to eq(Color.new('red'))
|
39
40
|
end
|
40
41
|
|
41
42
|
it "matches typed parameters with optional group" do
|
42
43
|
expression = CucumberExpression.new("I have a {color} ball", [], @parameter_registry)
|
43
|
-
|
44
|
-
expect(
|
44
|
+
transformed_argument_value = expression.match("I have a dark red ball")[0].transformed_value
|
45
|
+
expect( transformed_argument_value ).to eq(Color.new('dark red'))
|
45
46
|
end
|
46
47
|
|
47
48
|
it "matches untyped parameters with explicit type" do
|
48
49
|
expression = CucumberExpression.new("I have a {color} ball", [Color], @parameter_registry)
|
49
|
-
|
50
|
-
expect(
|
50
|
+
transformed_argument_value = expression.match("I have a red ball")[0].transformed_value
|
51
|
+
expect( transformed_argument_value ).to eq(Color.new('red'))
|
51
52
|
end
|
52
53
|
|
53
54
|
it "matches untyped parameters with same name as type" do
|
54
55
|
expression = CucumberExpression.new("I have a {color} ball", [], @parameter_registry)
|
55
|
-
|
56
|
-
expect(
|
56
|
+
transformed_argument_value = expression.match("I have a red ball")[0].transformed_value
|
57
|
+
expect( transformed_argument_value ).to eq(Color.new('red'))
|
57
58
|
end
|
58
59
|
|
59
60
|
it "matches parameters with explicit type that isn't registered" do
|
60
61
|
expression = CucumberExpression.new("I have a {color} ball", [Color], ParameterRegistry.new)
|
61
|
-
|
62
|
-
expect(
|
62
|
+
transformed_argument_value = expression.match("I have a red ball")[0].transformed_value
|
63
|
+
expect( transformed_argument_value ).to eq(Color.new('red'))
|
64
|
+
end
|
65
|
+
|
66
|
+
it("defers transformation until queried from argument") do
|
67
|
+
@parameter_registry.add_parameter(Parameter.new(
|
68
|
+
'throwing',
|
69
|
+
String,
|
70
|
+
/bad/,
|
71
|
+
lambda { |s| raise "Can't transform [#{s}]" }
|
72
|
+
))
|
73
|
+
expression = CucumberExpression.new("I have a {throwing} parameter", [], @parameter_registry)
|
74
|
+
args = expression.match("I have a bad parameter")
|
75
|
+
expect { args[0].transformed_value }.to raise_error("Can't transform [bad]")
|
63
76
|
end
|
64
77
|
end
|
65
78
|
|
66
79
|
describe RegularExpression do
|
67
80
|
it "matches parameters with explicit constructor" do
|
68
81
|
expression = RegularExpression.new(/I have a (red|blue|yellow) ball/, [Color], @parameter_registry)
|
69
|
-
|
70
|
-
expect(
|
82
|
+
transformed_argument_value = expression.match("I have a red ball")[0].transformed_value
|
83
|
+
expect( transformed_argument_value ).to eq(Color.new('red'))
|
71
84
|
end
|
72
85
|
|
73
86
|
it "matches parameters without explicit constructor" do
|
74
87
|
expression = RegularExpression.new(/I have a (red|blue|yellow) ball/, [], @parameter_registry)
|
75
|
-
|
76
|
-
expect(
|
88
|
+
transformed_argument_value = expression.match("I have a red ball")[0].transformed_value
|
89
|
+
expect( transformed_argument_value ).to eq(Color.new('red'))
|
77
90
|
end
|
78
91
|
|
79
92
|
it "matches parameters with explicit type that isn't registered" do
|
80
93
|
expression = RegularExpression.new(/I have a (red|blue|yellow) ball/, [Color], ParameterRegistry.new)
|
81
|
-
|
82
|
-
expect(
|
94
|
+
transformed_argument_value = expression.match("I have a red ball")[0].transformed_value
|
95
|
+
expect( transformed_argument_value ).to eq(Color.new('red'))
|
83
96
|
end
|
84
97
|
end
|
85
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-expressions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aslak Hellesøy
|
@@ -122,7 +122,7 @@ rubyforge_project:
|
|
122
122
|
rubygems_version: 2.5.2
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
|
-
summary: cucumber-expressions-2.0.
|
125
|
+
summary: cucumber-expressions-2.0.1
|
126
126
|
test_files:
|
127
127
|
- spec/capture_warnings.rb
|
128
128
|
- spec/coverage.rb
|