macros4cuke 0.2.11 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 0.2.12 / 2013-05-01
|
2
|
+
* [CHANGE] Method `Macros4Cuke#compile` raise an `EmptyArgumentError` exception when a line contains an empty or blank argument.
|
3
|
+
* [CHANGE] File `template-engine_spec.rb`: Added an example for error case mentioned in previous line.
|
4
|
+
|
1
5
|
## 0.2.11 / 2013-05-01
|
2
6
|
* [CHANGE] File `macros4cuke.gemspec`: Removed dependency on Rake.
|
3
7
|
|
@@ -34,6 +34,15 @@ class UnreachableSubstepArgument < Macros4CukeError
|
|
34
34
|
end # class
|
35
35
|
|
36
36
|
|
37
|
+
|
38
|
+
# Raised when a sub-step has an empty or blank argument name.
|
39
|
+
class EmptyArgumentError < Macros4CukeError
|
40
|
+
def initialize(aText)
|
41
|
+
super("An empty or blank argument occurred in '#{aText}'.")
|
42
|
+
end
|
43
|
+
end # class
|
44
|
+
|
45
|
+
|
37
46
|
# Raised when one invokes a macro-step with an unknown phrase.
|
38
47
|
class UnknownMacroError < Macros4CukeError
|
39
48
|
def initialize(aPhrase)
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# Purpose: Implementation of the MacroStep class.
|
3
3
|
|
4
4
|
require 'strscan' # Use the StringScanner for lexical analysis.
|
5
|
+
require_relative 'exceptions' # Load the
|
5
6
|
|
6
7
|
module Macros4Cuke # Module used as a namespace
|
7
8
|
|
@@ -52,18 +53,21 @@ public
|
|
52
53
|
end # class
|
53
54
|
|
54
55
|
|
56
|
+
# A very simple implementation of a templating engine.
|
55
57
|
class TemplateEngine
|
56
58
|
# The original text of the template is kept here.
|
57
59
|
attr_reader(:source)
|
58
60
|
|
59
61
|
# Constructor.
|
60
|
-
# [aSourceTemplate]
|
62
|
+
# [aSourceTemplate] the template source text. It may contain zero or tags enclosed between chevrons <...>.
|
61
63
|
def initialize(aSourceTemplate)
|
62
64
|
@source = aSourceTemplate
|
63
65
|
@representation = compile(aSourceTemplate)
|
64
66
|
end
|
65
67
|
|
66
68
|
public
|
69
|
+
# [aContextObject] context object to get actual values (when not present in the Hash parameter).
|
70
|
+
# [theLocals] a Hash with pairs of the form: argument name => actual value.
|
67
71
|
def render(aContextObject = nil, theLocals)
|
68
72
|
return '' if @representation.empty?
|
69
73
|
context = aContextObject.nil? ? Object.new : aContextObject
|
@@ -88,6 +92,8 @@ public
|
|
88
92
|
|
89
93
|
# Class method. Parse the given line text.
|
90
94
|
# Returns an array of couples.
|
95
|
+
# Couples are of the form:
|
96
|
+
# [:static, text] or [:dynamic, text]
|
91
97
|
def self.parse(aTextLine)
|
92
98
|
scanner = StringScanner.new(aTextLine)
|
93
99
|
result = []
|
@@ -134,13 +140,21 @@ private
|
|
134
140
|
input_lines = aSourceTemplate.split(/\r\n?|\n/)
|
135
141
|
|
136
142
|
# Parse the input text into raw data.
|
137
|
-
raw_lines = input_lines.map
|
143
|
+
raw_lines = input_lines.map do |line|
|
144
|
+
line_items = self.class.parse(line)
|
145
|
+
line_items.each do |(kind, text)|
|
146
|
+
# A tag text cannot be empty nor blank
|
147
|
+
raise EmptyArgumentError.new(line.strip) if (kind == :dynamic) && text.strip.empty?
|
148
|
+
end
|
149
|
+
|
150
|
+
line_items
|
151
|
+
end
|
138
152
|
|
139
153
|
compiled_lines = raw_lines.map { |line| compile_line(line) }
|
140
154
|
return compiled_lines.flatten()
|
141
155
|
end
|
142
156
|
|
143
|
-
|
157
|
+
# Convert the array of raw entries into full-fledged template elements.
|
144
158
|
def compile_line(aRawLine)
|
145
159
|
line_rep = aRawLine.map { |couple| compile_couple(couple) }
|
146
160
|
line_rep << EOLRep.new
|
@@ -155,6 +155,13 @@ SNIPPET
|
|
155
155
|
instance = TemplateEngine.new ''
|
156
156
|
instance.source.should be_empty
|
157
157
|
end
|
158
|
+
|
159
|
+
it "should complain when a placeholder is empty or blank" do
|
160
|
+
text_w_empty_arg = sample_template.sub(/userid/, '')
|
161
|
+
error_message = %Q|An empty or blank argument occurred in 'And I fill in "Username" with "<>"'.|
|
162
|
+
lambda { TemplateEngine.new text_w_empty_arg }.should raise_error(Macros4Cuke::EmptyArgumentError, error_message)
|
163
|
+
|
164
|
+
end
|
158
165
|
end
|
159
166
|
|
160
167
|
context "Provided services" do
|