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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 882d05ea05136cc6af4f3bc4ef6bccfe42531645
4
- data.tar.gz: 42c7abf6782587c48aa8e264598637a459bbdc86
3
+ metadata.gz: c8c5e8a795eb6fea91f46e61cc01985a8af0572d
4
+ data.tar.gz: 92fa95001cddb0f9d931a02602c0e2d793678d53
5
5
  SHA512:
6
- metadata.gz: 598ce9757f1518d1e9eae317a3f9718efb6339001fa36a5dea1e03fd690f44abd34524652f7b195c271c8b5128082676ffbd2dfef8b2a9aa2ee4bc6cd71ba3c7
7
- data.tar.gz: 38121b06c1d4ca408a28f407cb0ae3b0f47de3464fe20128de05667ab34fdd93b5f369dbb2d24b26b4f9f742a93744e1dbccbb0d930478c8de3633b305fa8891
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.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, :transformed_value
4
+ attr_reader :offset, :value
5
5
 
6
- def initialize(offset, value, transformed_value)
7
- @offset, @value, @transformed_value = offset, value, transformed_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
- transformed_value = parameter.transform(value)
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 = ['-?\d+', '\d+']
7
- FLOATING_POINT_REGEXPS = ['-?\d*\.?\d+']
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, FLOATING_POINT_REGEXPS, lambda {|s| s.to_f}))
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
- @parameter_registry.add_parameter(Parameter.new(
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
- parametered_argument_value = expression.match("I have a red ball")[0].transformed_value
38
- expect( parametered_argument_value ).to eq(Color.new('red'))
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
- parametered_argument_value = expression.match("I have a dark red ball")[0].transformed_value
44
- expect( parametered_argument_value ).to eq(Color.new('dark red'))
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
- parametered_argument_value = expression.match("I have a red ball")[0].transformed_value
50
- expect( parametered_argument_value ).to eq(Color.new('red'))
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
- parametered_argument_value = expression.match("I have a red ball")[0].transformed_value
56
- expect( parametered_argument_value ).to eq(Color.new('red'))
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
- parametered_argument_value = expression.match("I have a red ball")[0].transformed_value
62
- expect( parametered_argument_value ).to eq(Color.new('red'))
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
- parametered_argument_value = expression.match("I have a red ball")[0].transformed_value
70
- expect( parametered_argument_value ).to eq(Color.new('red'))
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
- parametered_argument_value = expression.match("I have a red ball")[0].transformed_value
76
- expect( parametered_argument_value ).to eq(Color.new('red'))
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
- parametered_argument_value = expression.match("I have a red ball")[0].transformed_value
82
- expect( parametered_argument_value ).to eq(Color.new('red'))
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.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.0
125
+ summary: cucumber-expressions-2.0.1
126
126
  test_files:
127
127
  - spec/capture_warnings.rb
128
128
  - spec/coverage.rb