macros4cuke 0.2.07 → 0.2.08

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/HISTORY.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.2.08]
2
+ #### Changes:
3
+ * Class MacroStep: method validate_params is now private, the signature of expand method has changed.
4
+ * macro-step.rb: added a missing require 'exceptions'.
5
+ * macro-step_spec.rb: updated to taken into account the above change. Added test case when a macro is called with unknown argument.
6
+ * Class MacroCollection#render_steps updated for the above change.
7
+
1
8
  ## [0.2.07]
2
9
  #### Changes:
3
10
  * Editorial improvements in README.md, corrected one inaccurate sentence.
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Macros4Cuke # Module used as a namespace
5
5
  # This constant keeps the current version of the gem.
6
- Version = '0.2.07'
6
+ Version = '0.2.08'
7
7
 
8
8
  Description = "Macros for Cucumber"
9
9
 
@@ -30,7 +30,7 @@ end # class
30
30
  # that has an unknown name.
31
31
  class UnknownArgumentError < Macros4CukeError
32
32
  def initialize(argName)
33
- super("Unknown macro argument #{argName}.")
33
+ super("Unknown macro-ste argument '#{argName}'.")
34
34
  end
35
35
  end # class
36
36
 
@@ -40,7 +40,7 @@ public
40
40
  # An exception is raised if the phrase syntax of both macros are the
41
41
  raise DuplicateMacroError.new(aPhrase) if find_macro(aPhrase)
42
42
 
43
- @macro_steps[new_macro.name] = new_macro
43
+ @macro_steps[new_macro.key] = new_macro
44
44
 
45
45
  end
46
46
 
@@ -55,13 +55,9 @@ public
55
55
 
56
56
  macro = find_macro(aPhrase)
57
57
  raise UnknownMacroError.new(aPhrase) if macro.nil?
58
-
59
- # Retrieve macro argument names and their associated value from the table
60
- params = macro.validate_params(aPhrase, rawData)
61
58
 
62
59
  # Render the steps
63
- rendered_steps = macro.expand(params)
64
-
60
+ return macro.expand(aPhrase, rawData)
65
61
  end
66
62
 
67
63
  private
@@ -2,6 +2,7 @@
2
2
  # Purpose: Implementation of the MacroStep class.
3
3
 
4
4
 
5
+ require_relative 'exceptions'
5
6
  require_relative 'template-engine'
6
7
 
7
8
  module Macros4Cuke # Module used as a namespace
@@ -12,8 +13,8 @@ class MacroStep
12
13
  # A template engine that expands the substeps upon request.
13
14
  attr_reader(:renderer)
14
15
 
15
- # Name of the macro as derived from the macro phrase.
16
- attr_reader(:name)
16
+ # Unique key of the macro as derived from the macro phrase.
17
+ attr_reader(:key)
17
18
 
18
19
  # The list of macro arguments that appears in the macro phrase.
19
20
  attr_reader(:phrase_args)
@@ -26,7 +27,7 @@ class MacroStep
26
27
  # [aMacroPhrase] The text from the macro step definition that is between the square brackets.
27
28
  # [theSubsteps] The source text of the steps to be expanded upon macro invokation.
28
29
  def initialize(aMacroPhrase, theSubsteps)
29
- @name = self.class.macro_key(aMacroPhrase, :definition)
30
+ @key = self.class.macro_key(aMacroPhrase, :definition)
30
31
 
31
32
  # Retrieve the macro arguments embedded in the phrase.
32
33
  @phrase_args = scan_arguments(aMacroPhrase, :definition)
@@ -89,12 +90,16 @@ class MacroStep
89
90
 
90
91
  # Render the steps from the template, given the values
91
92
  # taken by the parameters
92
- # [macro_parameters] a Hash with pairs of the kind: macro argument name => value
93
- def expand(macro_parameters)
94
- return renderer.render(nil, macro_parameters)
93
+ # [aPhrase] an instance of the macro phrase.
94
+ # [rawData] An Array of couples.
95
+ # Each couple is of the form: argument name, a value.
96
+ # Multiple rows with same argument name are acceptable.
97
+ def expand(aPhrase, rawData)
98
+ params = validate_params(aPhrase, rawData)
99
+ return renderer.render(nil, params)
95
100
  end
96
101
 
97
-
102
+ private
98
103
  # Build a Hash from the given raw data.
99
104
  # [aPhrase] an instance of the macro phrase.
100
105
  # [rawData] An Array of couples.
@@ -104,23 +109,23 @@ class MacroStep
104
109
  macro_parameters = {}
105
110
 
106
111
  # Retrieve the value(s) per variable in the phrase.
107
- quoted_values = scan_arguments(aPhrase, :invokation)
112
+ quoted_values = scan_arguments(aPhrase, :invokation)
108
113
  quoted_values.each_with_index do |val, index|
109
114
  macro_parameters[phrase_args[index]] = val
110
115
  end
111
116
 
112
117
 
113
118
  unless rawData.nil?
114
- rawData.each do |(key, value)|
115
- raise UnknownArgumentError.new(key) unless @args.include? key
116
- if macro_parameters.include? key
117
- if macro_parameters[key].kind_of?(Array)
118
- macro_parameters[key] << value
119
+ rawData.each do |(a_key, value)|
120
+ raise UnknownArgumentError.new(a_key) unless @args.include? a_key
121
+ if macro_parameters.include? a_key
122
+ if macro_parameters[a_key].kind_of?(Array)
123
+ macro_parameters[a_key] << value
119
124
  else
120
- macro_parameters[key] = [macro_parameters[key], value]
125
+ macro_parameters[a_key] = [macro_parameters[a_key], value]
121
126
  end
122
127
  else
123
- macro_parameters[key] = value
128
+ macro_parameters[a_key] = value
124
129
  end
125
130
  end
126
131
  end
@@ -130,7 +135,7 @@ class MacroStep
130
135
 
131
136
 
132
137
 
133
- private
138
+
134
139
  # Retrieve from the macro phrase, all the text between <..> or double quotes.
135
140
  # Returns an array. Each of its elements corresponds to quoted text.
136
141
  # Example:
@@ -10,6 +10,7 @@ module Macros4Cuke # Open the module to avoid lengthy qualified names
10
10
 
11
11
  describe MacroStep do
12
12
  let(:sample_phrase) { "enter my credentials as <userid>]:" }
13
+
13
14
  let(:sample_template) do
14
15
  snippet = <<-SNIPPET
15
16
  Given I landed in the homepage
@@ -32,8 +33,8 @@ end
32
33
  end
33
34
 
34
35
 
35
- it "should know its key/name" do
36
- subject.name.should == "enter_my_credentials_as_X_T"
36
+ it "should know its key" do
37
+ subject.key.should == "enter_my_credentials_as_X_T"
37
38
  end
38
39
 
39
40
  it "should know the tags(placeholders) from its phrase" do
@@ -48,8 +49,11 @@ end
48
49
 
49
50
 
50
51
  context "Provided services" do
52
+
53
+ let(:phrase_instance) {%Q|enter my credentials as "nobody"]:|}
54
+
51
55
  it "should render the substeps" do
52
- text = subject.expand({'userid' => 'nobody', 'password' => 'no-secret'})
56
+ text = subject.expand(phrase_instance, [ ['password', 'no-secret'] ])
53
57
  expectation = <<-SNIPPET
54
58
  Given I landed in the homepage
55
59
  When I click "Sign in"
@@ -60,6 +64,27 @@ SNIPPET
60
64
 
61
65
  text.should == expectation
62
66
  end
67
+
68
+ it "should render steps even when one argument has no actual value" do
69
+ # Special case: password has no value...
70
+ text = subject.expand(phrase_instance, [ ])
71
+ expectation = <<-SNIPPET
72
+ Given I landed in the homepage
73
+ When I click "Sign in"
74
+ And I fill in "Username" with "nobody"
75
+ And I fill in "Password" with ""
76
+ And I click "Submit"
77
+ SNIPPET
78
+
79
+ text.should == expectation
80
+ end
81
+
82
+ it "should complain when an unknown variable is used" do
83
+ # Error case: there is no macro argument called <unknown>
84
+ error_message = "Unknown macro-ste argument 'unknown'."
85
+ lambda { subject.expand(phrase_instance, [ ['unknown', 'anything'] ]) }.should raise_error(UnknownArgumentError, error_message)
86
+ end
87
+
63
88
  end # context
64
89
 
65
90
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macros4cuke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.07
4
+ version: 0.2.08
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: