macros4cuke 0.3.14 → 0.3.15
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/.rubocop.yml +7 -0
- data/CHANGELOG.md +12 -8
- data/lib/macros4cuke/constants.rb +1 -1
- data/lib/macros4cuke/templating/engine.rb +1 -1
- data/spec/macros4cuke/macro-collection_spec.rb +9 -5
- data/spec/macros4cuke/macro-step-support_spec.rb +20 -13
- data/spec/macros4cuke/macro-step_spec.rb +16 -12
- data/spec/macros4cuke/templating/engine_spec.rb +62 -40
- data/spec/macros4cuke/templating/placeholder_spec.rb +23 -17
- data/spec/macros4cuke/templating/section_spec.rb +38 -35
- metadata +2 -2
data/.rubocop.yml
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# This is disabled because some demos use UTF-8
|
1
2
|
AsciiComments:
|
2
3
|
Enabled: false
|
3
4
|
|
@@ -9,7 +10,13 @@ DefWithParentheses:
|
|
9
10
|
|
10
11
|
EmptyLines:
|
11
12
|
Enabled: false
|
13
|
+
|
14
|
+
# Avoid methods longer than 40 lines of code
|
15
|
+
MethodLength:
|
16
|
+
Max: 40
|
12
17
|
|
18
|
+
SpaceInsideBrackets:
|
19
|
+
Enabled: false
|
13
20
|
|
14
21
|
StringLiterals:
|
15
22
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,31 @@
|
|
1
|
-
## 0.3.
|
2
|
-
* [FIX]
|
1
|
+
## 0.3.15 / 2013-05-20
|
2
|
+
* [FIX] File `.CHANGELOG.md` Date entries weren't incremented.
|
3
|
+
* [CHANGE] File `.rubocop.yml`: Added more configuration entries.
|
4
|
+
* [CHANGE] Spec files updated to better please Rubocop.
|
3
5
|
|
6
|
+
## 0.3.14 / 2013-05-18
|
7
|
+
* [FIX] lib/ folder in secondary local repository was messed up. Gem was OK.
|
4
8
|
|
5
|
-
## 0.3.13 / 2013-05-
|
9
|
+
## 0.3.13 / 2013-05-18
|
6
10
|
* [NEW] File `.rubocop.yml` Added.
|
7
11
|
* [CHANGE] Many source files changed to please Rubocop.
|
8
12
|
|
9
|
-
## 0.3.12 / 2013-05-
|
13
|
+
## 0.3.12 / 2013-05-17
|
10
14
|
* [NEW] File `.ruby-gemset` Added (for RVM users).
|
11
15
|
* [NEW] File `.ruby-version` Added (for RVM users).
|
12
16
|
|
13
|
-
## 0.3.11 / 2013-05-
|
17
|
+
## 0.3.11 / 2013-05-16
|
14
18
|
* [CHANGE] File `README.md`: Minor reformating.
|
15
19
|
* [CHANGE] File `basic.feature` (in examples/): Added one more macro-step example.
|
16
20
|
|
17
|
-
## 0.3.10 / 2013-05-
|
21
|
+
## 0.3.10 / 2013-05-15
|
18
22
|
* [CHANGE] File `README.md`: Expanded section on conditional section.
|
19
23
|
* [CHANGE] Method `Templating::Engine::parse` slightly refactored in order to decrease its complexity.
|
20
24
|
|
21
|
-
## 0.3.09 / 2013-05-
|
25
|
+
## 0.3.09 / 2013-05-14
|
22
26
|
* [CHANGE] File `.travis.yml`: Added jruby as a target Ruby
|
23
27
|
|
24
|
-
## 0.3.08 / 2013-05-
|
28
|
+
## 0.3.08 / 2013-05-13
|
25
29
|
* [CHANGE] File `README.md`: Added Gem Version badge
|
26
30
|
|
27
31
|
## 0.3.07 / 2013-05-12
|
@@ -155,7 +155,7 @@ public
|
|
155
155
|
# @return [String] The text value assigned to the placeholder.
|
156
156
|
# Returns an empty string when no value is assigned to the placeholder.
|
157
157
|
def render(aContextObject, theLocals)
|
158
|
-
raise NotImplementedError, "Method Section
|
158
|
+
raise NotImplementedError, "Method Section.#{__method__} must be implemented in subclass."
|
159
159
|
end
|
160
160
|
|
161
161
|
end # class
|
@@ -2,9 +2,11 @@
|
|
2
2
|
# File: macro-collection_spec.rb
|
3
3
|
|
4
4
|
require_relative '../spec_helper'
|
5
|
-
require_relative '../../lib/macros4cuke/macro-collection' # Load the class under test
|
6
5
|
|
7
|
-
|
6
|
+
# Load the class under test
|
7
|
+
require_relative '../../lib/macros4cuke/macro-collection'
|
8
|
+
|
9
|
+
module Macros4Cuke # Open this namespace to avoid module qualifier prefixes
|
8
10
|
|
9
11
|
describe MacroCollection do
|
10
12
|
|
@@ -32,12 +34,14 @@ SNIPPET
|
|
32
34
|
|
33
35
|
it "should accept the addition of a new macro-step" do
|
34
36
|
phrase = "[enter my credentials]"
|
35
|
-
|
37
|
+
args = [phrase, sample_substeps, true]
|
38
|
+
->() { singleton.add_macro(*args)}.should_not raise_error
|
36
39
|
singleton.should have(1).macro_steps
|
37
40
|
|
38
41
|
# Error case: inserting another macro with same phrase.
|
39
|
-
|
40
|
-
|
42
|
+
msg = "A macro-step with phrase '[enter my credentials]' already exist."
|
43
|
+
->(){ singleton.add_macro(*args) }.should
|
44
|
+
raise_error(Macros4Cuke::DuplicateMacroError, msg)
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# File: macro-step_spec.rb
|
2
3
|
|
3
4
|
require_relative '../spec_helper'
|
4
|
-
|
5
|
+
|
6
|
+
# The class under test
|
7
|
+
require_relative '../../lib/macros4cuke/macro-step-support'
|
5
8
|
|
6
9
|
|
7
10
|
module Macros4Cuke # Open the module to avoid lengthy qualified names
|
@@ -41,29 +44,33 @@ SNIPPET
|
|
41
44
|
|
42
45
|
context "Defining macro(s):" do
|
43
46
|
it "should add valid new macro" do
|
44
|
-
|
47
|
+
->(){ world.add_macro(m1_phrase, m1_substeps, true) }.should_not raise_error
|
45
48
|
end
|
46
49
|
|
47
50
|
it "should complain when entering the same macro again" do
|
48
51
|
# Error case: trying to register another macro with same key/phrase.
|
49
|
-
|
50
|
-
|
52
|
+
msg = "A macro-step with phrase 'enter the credentials' already exist."
|
53
|
+
-> { world.add_macro(m1_phrase, m1_substeps, true) }.should
|
54
|
+
raise_error(Macros4Cuke::DuplicateMacroError, msg)
|
51
55
|
end
|
52
56
|
|
53
57
|
it "should complain macro uses no table and phrase is parameterless" do
|
54
|
-
# Error case: substeps have arguments,
|
55
|
-
|
56
|
-
|
58
|
+
# Error case: substeps have arguments,
|
59
|
+
# but the macro has no mechanism to pass the needed data.
|
60
|
+
phrase = "fill in the credentials"
|
61
|
+
msg = "The sub-step argument 'userid' does not appear in the phrase."
|
62
|
+
->(){ world.add_macro(phrase, m1_substeps, false) }.should
|
63
|
+
raise_error(Macros4Cuke::UnreachableSubstepArgument, msg)
|
57
64
|
end
|
58
65
|
end # context
|
59
66
|
|
60
67
|
context "Invoking macro(s):" do
|
61
68
|
|
62
69
|
it "should complain when invoking an unknown macro-step" do
|
63
|
-
phrase_unknown = "dream of a perfect world"
|
64
|
-
|
65
|
-
|
66
|
-
|
70
|
+
phrase_unknown = "dream of a perfect world"
|
71
|
+
msg = "Unknown macro-step with phrase: 'dream of a perfect world'."
|
72
|
+
->(){ world.invoke_macro(phrase_unknown) }.should
|
73
|
+
raise_error(Macros4Cuke::UnknownMacroError, msg)
|
67
74
|
end
|
68
75
|
|
69
76
|
end # context
|
@@ -71,10 +78,10 @@ SNIPPET
|
|
71
78
|
context "Clearing macro(s):" do
|
72
79
|
|
73
80
|
it "should clear all macros" do
|
74
|
-
|
81
|
+
->(){ world.clear_macros() }.should_not raise_error
|
75
82
|
|
76
83
|
# Control the post-condition
|
77
|
-
MacroCollection
|
84
|
+
MacroCollection.instance.macro_steps.should be_empty
|
78
85
|
end
|
79
86
|
|
80
87
|
end # context
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# File: macro-step_spec.rb
|
2
3
|
|
3
4
|
|
@@ -29,20 +30,22 @@ end
|
|
29
30
|
|
30
31
|
context "Creation & initialization" do
|
31
32
|
it "should be created with a phrase, substeps and a table use indicator" do
|
32
|
-
|
33
|
+
->(){ MacroStep.new(sample_phrase, sample_template, true) }.should_not raise_error
|
33
34
|
end
|
34
35
|
|
35
36
|
|
36
37
|
it "should complain when a sub-step argument can never be assigned a value via the phrase" do
|
37
|
-
|
38
|
-
|
38
|
+
msg = "The sub-step argument 'password' does not appear in the phrase."
|
39
|
+
->(){ MacroStep.new(sample_phrase, sample_template, false) }.should
|
40
|
+
raise_error(Macros4Cuke::UnreachableSubstepArgument, msg)
|
39
41
|
end
|
40
42
|
|
41
43
|
|
42
|
-
it "should complain when an argument
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
it "should complain when an argument in phrase never occurs in substeps" do
|
45
|
+
phrase = "enter my credentials as <foobar>"
|
46
|
+
msg = "The phrase argument 'foobar' does not appear in a sub-step."
|
47
|
+
->(){ MacroStep.new(phrase, sample_template, true) }.should
|
48
|
+
raise_error(Macros4Cuke::UselessPhraseArgument, msg)
|
46
49
|
end
|
47
50
|
|
48
51
|
|
@@ -63,10 +66,10 @@ end
|
|
63
66
|
|
64
67
|
context "Provided services" do
|
65
68
|
|
66
|
-
let(:phrase_instance) {%Q|enter my credentials as "nobody"|}
|
69
|
+
let(:phrase_instance) { %Q|enter my credentials as "nobody"| }
|
67
70
|
|
68
71
|
it "should render the substeps" do
|
69
|
-
text = subject.expand(phrase_instance, [
|
72
|
+
text = subject.expand(phrase_instance, [ %w(password no-secret) ])
|
70
73
|
expectation = <<-SNIPPET
|
71
74
|
Given I landed in the homepage
|
72
75
|
When I click "Sign in"
|
@@ -94,7 +97,7 @@ SNIPPET
|
|
94
97
|
|
95
98
|
it "should un-escape the double-quotes for phrase arguments" do
|
96
99
|
specific_phrase = %q|enter my credentials as "quotable\""|
|
97
|
-
text = subject.expand(specific_phrase, [
|
100
|
+
text = subject.expand(specific_phrase, [ %w(password no-secret) ])
|
98
101
|
expectation = <<-SNIPPET
|
99
102
|
Given I landed in the homepage
|
100
103
|
When I click "Sign in"
|
@@ -110,12 +113,13 @@ SNIPPET
|
|
110
113
|
it "should complain when an unknown variable is used" do
|
111
114
|
# Error case: there is no macro argument called <unknown>
|
112
115
|
error_message = "Unknown macro-step argument 'unknown'."
|
113
|
-
|
116
|
+
args = [ %w(unknown anything) ]
|
117
|
+
->(){ subject.expand(phrase_instance, args) }.should
|
118
|
+
raise_error(UnknownArgumentError, error_message)
|
114
119
|
end
|
115
120
|
|
116
121
|
end # context
|
117
122
|
|
118
|
-
|
119
123
|
end # describe
|
120
124
|
|
121
125
|
end # module
|
@@ -2,7 +2,9 @@
|
|
2
2
|
# File: engine_spec.rb
|
3
3
|
|
4
4
|
require_relative '../../spec_helper'
|
5
|
-
|
5
|
+
|
6
|
+
# Load the class under test
|
7
|
+
require_relative '../../../lib/macros4cuke/templating/engine'
|
6
8
|
|
7
9
|
|
8
10
|
module Macros4Cuke
|
@@ -20,6 +22,8 @@ describe Engine do
|
|
20
22
|
And I fill in "Password" with "<password>"
|
21
23
|
And I click "Sign in"
|
22
24
|
SNIPPET
|
25
|
+
|
26
|
+
source
|
23
27
|
end
|
24
28
|
|
25
29
|
# Template containing two conditional sections
|
@@ -34,6 +38,8 @@ SNIPPET
|
|
34
38
|
<?dummy></dummy>
|
35
39
|
And I click "Register"
|
36
40
|
SNIPPET
|
41
|
+
|
42
|
+
source
|
37
43
|
end
|
38
44
|
|
39
45
|
|
@@ -51,32 +57,35 @@ SNIPPET
|
|
51
57
|
|
52
58
|
it "should parse an empty text line" do
|
53
59
|
# Expectation: result should be an empty array.
|
54
|
-
Engine
|
60
|
+
Engine.parse('').should be_empty
|
55
61
|
end
|
56
62
|
|
57
63
|
it "should parse a text line without tag" do
|
58
64
|
sample_text = 'Mary has a little lamb'
|
59
|
-
result = Engine
|
65
|
+
result = Engine.parse(sample_text)
|
60
66
|
|
61
|
-
# Expectation: an array with one couple:
|
67
|
+
# Expectation: an array with one couple:
|
68
|
+
# [:static, the source text]
|
62
69
|
result.should have(1).items
|
63
70
|
result[0].should == [:static, sample_text]
|
64
71
|
end
|
65
72
|
|
66
73
|
it "should parse a text line that consists of just a tag" do
|
67
74
|
sample_text = '<some_tag>'
|
68
|
-
result = Engine
|
75
|
+
result = Engine.parse(sample_text)
|
69
76
|
|
70
|
-
# Expectation: an array with one couple:
|
77
|
+
# Expectation: an array with one couple:
|
78
|
+
# [:static, the source text]
|
71
79
|
result.should have(1).items
|
72
80
|
result[0].should == [:dynamic, strip_chevrons(sample_text)]
|
73
81
|
end
|
74
82
|
|
75
83
|
it "should parse a text line with a tag at the start" do
|
76
84
|
sample_text = '<some_tag>some text'
|
77
|
-
result = Engine
|
85
|
+
result = Engine.parse(sample_text)
|
78
86
|
|
79
|
-
# Expectation: an array with two couples:
|
87
|
+
# Expectation: an array with two couples:
|
88
|
+
# [dynamic, 'some_tag'][:static, some text]
|
80
89
|
result.should have(2).items
|
81
90
|
result[0].should == [:dynamic, 'some_tag']
|
82
91
|
result[1].should == [:static, 'some text']
|
@@ -84,9 +93,10 @@ SNIPPET
|
|
84
93
|
|
85
94
|
it "should parse a text line with a tag at the end" do
|
86
95
|
sample_text = 'some text<some_tag>'
|
87
|
-
result = Engine
|
96
|
+
result = Engine.parse(sample_text)
|
88
97
|
|
89
|
-
# Expectation: an array with two couples:
|
98
|
+
# Expectation: an array with two couples:
|
99
|
+
# [:static, some text] [dynamic, 'some_tag']
|
90
100
|
result.should have(2).items
|
91
101
|
result[0].should == [:static, 'some text']
|
92
102
|
result[1].should == [:dynamic, 'some_tag']
|
@@ -94,7 +104,7 @@ SNIPPET
|
|
94
104
|
|
95
105
|
it "should parse a text line with a tag in the middle" do
|
96
106
|
sample_text = 'begin <some_tag> end'
|
97
|
-
result = Engine
|
107
|
+
result = Engine.parse(sample_text)
|
98
108
|
|
99
109
|
# Expectation: an array with three couples:
|
100
110
|
result.should have(3).items
|
@@ -105,7 +115,7 @@ SNIPPET
|
|
105
115
|
|
106
116
|
it "should parse a text line with two tags in the middle" do
|
107
117
|
sample_text = 'begin <some_tag>middle<another_tag> end'
|
108
|
-
result = Engine
|
118
|
+
result = Engine.parse(sample_text)
|
109
119
|
|
110
120
|
# Expectation: an array with items couples:
|
111
121
|
result.should have(5).items
|
@@ -117,7 +127,7 @@ SNIPPET
|
|
117
127
|
|
118
128
|
# Case: two consecutive tags
|
119
129
|
sample_text = 'begin <some_tag><another_tag> end'
|
120
|
-
result = Engine
|
130
|
+
result = Engine.parse(sample_text)
|
121
131
|
|
122
132
|
# Expectation: an array with four couples:
|
123
133
|
result.should have(4).items
|
@@ -129,7 +139,7 @@ SNIPPET
|
|
129
139
|
|
130
140
|
it "should parse a text line with escaped chevrons" do
|
131
141
|
sample_text = 'Mary has a \<little\> lamb'
|
132
|
-
result = Engine
|
142
|
+
result = Engine.parse(sample_text)
|
133
143
|
|
134
144
|
# Expectation: an array with one couple: [:static, the source text]
|
135
145
|
result.should have(1).items
|
@@ -138,7 +148,7 @@ SNIPPET
|
|
138
148
|
|
139
149
|
it "should parse a text line with escaped chevrons in a tag" do
|
140
150
|
sample_text = 'begin <some_\<\\>weird\>_tag> end'
|
141
|
-
result = Engine
|
151
|
+
result = Engine.parse(sample_text)
|
142
152
|
|
143
153
|
# Expectation: an array with three couples:
|
144
154
|
result.should have(3).items
|
@@ -150,19 +160,22 @@ SNIPPET
|
|
150
160
|
it "should complain if a tag misses an closing chevron" do
|
151
161
|
sample_text = 'begin <some_tag\> end'
|
152
162
|
error_message = "Missing closing chevron '>'."
|
153
|
-
|
163
|
+
->(){ Engine.parse(sample_text) }.should raise_error(
|
164
|
+
StandardError, error_message)
|
154
165
|
end
|
155
166
|
|
156
167
|
it "should complain if a text misses an opening chevron" do
|
157
168
|
sample_text = 'begin <some_tag> > end'
|
158
169
|
error_message = "Missing opening chevron '<'."
|
159
|
-
|
170
|
+
->(){ Engine.parse(sample_text) }.should raise_error(
|
171
|
+
StandardError, error_message)
|
160
172
|
end
|
161
173
|
|
162
174
|
it "should complain if a text has nested opening chevrons" do
|
163
175
|
sample_text = 'begin <<some_tag> > end'
|
164
176
|
error_message = "Nested opening chevron '<'."
|
165
|
-
|
177
|
+
->(){ Engine.parse(sample_text) }.should raise_error(
|
178
|
+
StandardError, error_message)
|
166
179
|
end
|
167
180
|
|
168
181
|
end # context
|
@@ -170,11 +183,11 @@ SNIPPET
|
|
170
183
|
context "Creation and initialization" do
|
171
184
|
|
172
185
|
it "should accept an empty template text" do
|
173
|
-
|
186
|
+
->(){ Engine.new '' }.should_not raise_error
|
174
187
|
end
|
175
188
|
|
176
189
|
it "should be created with a template text" do
|
177
|
-
|
190
|
+
->(){ Engine.new sample_template }.should_not raise_error
|
178
191
|
end
|
179
192
|
|
180
193
|
it "should know the source text" do
|
@@ -186,20 +199,26 @@ SNIPPET
|
|
186
199
|
end
|
187
200
|
|
188
201
|
it "should accept conditional section" do
|
189
|
-
|
202
|
+
->(){ Engine.new sophisticated_template }.should_not raise_error
|
190
203
|
instance = Engine.new sophisticated_template
|
204
|
+
elements = instance.instance_variable_get(:@representation)
|
205
|
+
sections = elements.select { |e| e.is_a?(Section) }
|
206
|
+
names = sections.map { |e| e.to_s }
|
207
|
+
names.should == %w(<?address> <?birthdate> <?dummy>)
|
191
208
|
end
|
192
209
|
|
193
210
|
it "should complain when a placeholder is empty or blank" do
|
194
211
|
text_w_empty_arg = sample_template.sub(/userid/, '')
|
195
|
-
|
196
|
-
|
212
|
+
msg = %q(An empty or blank argument occurred in 'And I fill in "Username" with "<>"'.)
|
213
|
+
->(){ Engine.new text_w_empty_arg }.should
|
214
|
+
raise_error(Macros4Cuke::EmptyArgumentError, msg)
|
197
215
|
end
|
198
216
|
|
199
217
|
it "should complain when a placeholder contains an invalid character" do
|
200
218
|
text_w_empty_arg = sample_template.sub(/userid/, 'user%id')
|
201
|
-
|
202
|
-
|
219
|
+
msg = "The invalid sign '%' occurs in the argument/tag 'user%id'."
|
220
|
+
->(){ Engine.new text_w_empty_arg }.should
|
221
|
+
raise_error(Macros4Cuke::InvalidCharError, msg)
|
203
222
|
end
|
204
223
|
|
205
224
|
it "should complain when a section has no closing tag" do
|
@@ -207,22 +226,25 @@ SNIPPET
|
|
207
226
|
text_w_open_section = sophisticated_template.sub(/<\/address>/, '')
|
208
227
|
|
209
228
|
error_message = "Unterminated section <?address>."
|
210
|
-
|
229
|
+
->(){ Engine.new text_w_open_section}.should
|
230
|
+
raise_error(StandardError, error_message)
|
211
231
|
end
|
212
232
|
|
213
|
-
it "should complain when a closing tag
|
233
|
+
it "should complain when a closing tag has no corresponding opening tag" do
|
214
234
|
# Replacing an end of section tag by another...
|
215
235
|
text_w_wrong_end = sophisticated_template.sub(/<\/address>/, '</foobar>')
|
216
236
|
|
217
|
-
|
218
|
-
|
237
|
+
msg = "End of section</foobar> doesn't match current section 'address'."
|
238
|
+
->(){ Engine.new text_w_wrong_end }.should
|
239
|
+
raise_error(StandardError, msg)
|
219
240
|
end
|
220
241
|
|
221
|
-
it "should complain when a closing tag is found
|
242
|
+
it "should complain when a closing tag is found without opening tag" do
|
222
243
|
# Replacing an end of section tag by another...
|
223
|
-
|
224
|
-
|
225
|
-
|
244
|
+
wrong_end = sophisticated_template.sub(/<\?birthdate>/, '</foobar>')
|
245
|
+
msg = "End of section</foobar> found while no corresponding section is open."
|
246
|
+
->(){ Engine.new wrong_end }.should
|
247
|
+
raise_error(StandardError, msg)
|
226
248
|
end
|
227
249
|
|
228
250
|
end # context
|
@@ -243,12 +265,12 @@ SNIPPET
|
|
243
265
|
substeps = " # Comment 1 <miscellaneous>\n" + sample_template
|
244
266
|
substeps += " #\n Comment 2 <haphazard>"
|
245
267
|
instance = Engine.new substeps
|
246
|
-
|
268
|
+
instance.variables == [:userid, :password]
|
247
269
|
end
|
248
270
|
|
249
271
|
|
250
272
|
it "should render the text given the actuals" do
|
251
|
-
locals = {'userid' => "johndoe"}
|
273
|
+
locals = { 'userid' => "johndoe" }
|
252
274
|
|
253
275
|
rendered_text = subject.render(Object.new, locals)
|
254
276
|
expected = <<-SNIPPET
|
@@ -262,13 +284,13 @@ SNIPPET
|
|
262
284
|
rendered_text.should == expected
|
263
285
|
|
264
286
|
# Case of an actual that's not a String
|
265
|
-
locals = {'userid' => "johndoe", "password" =>
|
287
|
+
locals = { 'userid' => "johndoe", "password" => 12345 }
|
266
288
|
rendered_text = subject.render(Object.new, locals)
|
267
289
|
expected = <<-SNIPPET
|
268
290
|
Given I landed in the homepage
|
269
291
|
# The credentials are entered here
|
270
292
|
And I fill in "Username" with "johndoe"
|
271
|
-
And I fill in "Password" with "
|
293
|
+
And I fill in "Password" with "12345"
|
272
294
|
And I click "Sign in"
|
273
295
|
SNIPPET
|
274
296
|
|
@@ -278,7 +300,7 @@ SNIPPET
|
|
278
300
|
# Place actual value in context object
|
279
301
|
Context = Struct.new(:userid, :password)
|
280
302
|
context = Context.new("sherlock", "holmes")
|
281
|
-
rendered_text = subject.render(context, {'userid' => 'susan'})
|
303
|
+
rendered_text = subject.render(context, { 'userid' => 'susan' })
|
282
304
|
expected = <<-SNIPPET
|
283
305
|
Given I landed in the homepage
|
284
306
|
# The credentials are entered here
|
@@ -299,7 +321,7 @@ SNIPPET
|
|
299
321
|
it "should render conditional sections" do
|
300
322
|
instance = Engine.new(sophisticated_template)
|
301
323
|
|
302
|
-
locals = {'firstname' => "Anon",
|
324
|
+
locals = { 'firstname' => "Anon",
|
303
325
|
"lastname" => "Eemoos" ,
|
304
326
|
"birthdate" => "1976-04-21"
|
305
327
|
}
|
@@ -330,7 +352,7 @@ SNIPPET
|
|
330
352
|
|
331
353
|
|
332
354
|
it "should render multivalued actuals" do
|
333
|
-
locals = {'userid' =>
|
355
|
+
locals = { 'userid' => %w(johndoe yeti) } # Silly case
|
334
356
|
|
335
357
|
rendered_text = subject.render(Object.new, locals)
|
336
358
|
expected = <<-SNIPPET
|
@@ -2,7 +2,9 @@
|
|
2
2
|
# File: section_spec.rb
|
3
3
|
|
4
4
|
require_relative '../../spec_helper'
|
5
|
-
|
5
|
+
|
6
|
+
# Load the classes under test
|
7
|
+
require_relative '../../../lib/macros4cuke/templating/engine'
|
6
8
|
|
7
9
|
module Macros4Cuke
|
8
10
|
|
@@ -16,44 +18,48 @@ describe Placeholder do
|
|
16
18
|
context "Creation and initialization:" do
|
17
19
|
|
18
20
|
it "should be created with a variable name" do
|
19
|
-
|
21
|
+
->() { Placeholder.new('foobar') }.should_not raise_error
|
20
22
|
end
|
21
|
-
|
22
|
-
it "should know the name of its variable" do
|
23
|
+
|
24
|
+
it "should know the name of its variable" do
|
23
25
|
subject.name.should == 'foobar'
|
24
|
-
end
|
26
|
+
end
|
25
27
|
|
26
|
-
end # context
|
28
|
+
end # context
|
27
29
|
|
28
|
-
context "Provided services:" do
|
29
|
-
it "should render an empty string when no actual value is
|
30
|
+
context "Provided services:" do
|
31
|
+
it "should render an empty string when no actual value is absent" do
|
30
32
|
# Case: context has no value associated to 'foobar'
|
31
33
|
rendered_text = subject.render(Object.new, {})
|
32
34
|
rendered_text.should be_empty
|
33
|
-
|
35
|
+
|
34
36
|
# Case: locals Hash has a nil value associated to 'foobar'
|
35
|
-
rendered_text = subject.render(Object.new, {'foobar' => nil})
|
37
|
+
rendered_text = subject.render(Object.new, { 'foobar' => nil })
|
36
38
|
rendered_text.should be_empty
|
37
39
|
|
38
40
|
# Case: context object has a nil value associated to 'foobar'
|
39
41
|
context = Object.new
|
40
|
-
def context.foobar
|
42
|
+
def context.foobar # Add singleton method foobar that returns nil
|
43
|
+
nil
|
44
|
+
end
|
41
45
|
rendered_text = subject.render(context, {})
|
42
|
-
rendered_text.should be_empty
|
46
|
+
rendered_text.should be_empty
|
43
47
|
end
|
44
|
-
|
48
|
+
|
45
49
|
it "should render the actual value bound to the placeholder" do
|
46
50
|
# Case: locals Hash has a value associated to 'foobar'
|
47
|
-
rendered_text = subject.render(Object.new, {'foobar' => 'hello'})
|
51
|
+
rendered_text = subject.render(Object.new, { 'foobar' => 'hello' })
|
48
52
|
rendered_text.should == 'hello'
|
49
53
|
|
50
54
|
# Case: context object has a value associated to 'foobar'
|
51
55
|
context = Object.new
|
52
|
-
def context.foobar
|
56
|
+
def context.foobar # Add singleton method foobar that returns 'world'
|
57
|
+
'world'
|
58
|
+
end
|
53
59
|
rendered_text = subject.render(context, {})
|
54
|
-
rendered_text.should == 'world'
|
60
|
+
rendered_text.should == 'world'
|
55
61
|
end
|
56
|
-
|
62
|
+
|
57
63
|
end # context
|
58
64
|
|
59
65
|
end # describe
|
@@ -2,7 +2,9 @@
|
|
2
2
|
# File: section_spec.rb
|
3
3
|
|
4
4
|
require_relative '../../spec_helper'
|
5
|
-
|
5
|
+
|
6
|
+
# Load the classes under test
|
7
|
+
require_relative '../../../lib/macros4cuke/templating/engine'
|
6
8
|
|
7
9
|
module Macros4Cuke
|
8
10
|
|
@@ -11,33 +13,33 @@ module Templating # Open this namespace to get rid of module qualifier prefixes
|
|
11
13
|
# Spec for abstract class Section.
|
12
14
|
describe Section do
|
13
15
|
# Default instantiation rule
|
14
|
-
subject { Section.new('foobar') }
|
15
|
-
|
16
|
+
subject { Section.new('foobar') }
|
17
|
+
|
16
18
|
# Return a list of possible child elements
|
17
19
|
let(:sample_children) do
|
18
20
|
[ StaticText.new("Hello "),
|
19
21
|
Placeholder.new("user"),
|
20
22
|
EOLine.new
|
21
23
|
]
|
22
|
-
end
|
24
|
+
end
|
23
25
|
|
24
26
|
context "Creation and initialization" do
|
25
|
-
|
27
|
+
|
26
28
|
it "should be created with a variable name" do
|
27
|
-
|
29
|
+
->() { Section.new('foobar') }.should_not raise_error
|
28
30
|
end
|
29
|
-
|
30
|
-
it "should know the name of its variable" do
|
31
|
+
|
32
|
+
it "should know the name of its variable" do
|
31
33
|
subject.name.should == 'foobar'
|
32
34
|
end
|
33
35
|
|
34
36
|
it "should have no child at start" do
|
35
37
|
subject.should have(0).children
|
36
|
-
end
|
37
|
-
|
38
|
+
end
|
39
|
+
|
38
40
|
end # context
|
39
|
-
|
40
|
-
context "Provided services:" do
|
41
|
+
|
42
|
+
context "Provided services:" do
|
41
43
|
it "should add child element(s)" do
|
42
44
|
sample_children.each do |a_child|
|
43
45
|
subject.add_child(a_child)
|
@@ -46,31 +48,30 @@ describe Section do
|
|
46
48
|
# Control that the addition work as expected
|
47
49
|
subject.children.should == sample_children
|
48
50
|
end
|
49
|
-
|
51
|
+
|
50
52
|
it "should know the name all child placeholders" do
|
51
53
|
# Case: simple flat list of children
|
52
54
|
sample_children.each { |a_child| subject.add_child(a_child) }
|
53
55
|
subject.variables.should == [ 'user' ]
|
54
|
-
|
55
|
-
# Case: at least one child is a group
|
56
|
+
|
57
|
+
# Case: at least one child is a group
|
56
58
|
parent = Section.new('son')
|
57
|
-
[
|
58
|
-
subject,
|
59
|
+
[ subject,
|
59
60
|
StaticText.new("Bye "),
|
60
61
|
Placeholder.new("firstname"),
|
61
62
|
EOLine.new
|
62
|
-
].each { |a_child| parent.add_child(a_child) }
|
63
|
+
].each { |a_child| parent.add_child(a_child) }
|
63
64
|
|
64
|
-
parent.variables.should ==
|
65
|
-
|
65
|
+
parent.variables.should == %w(user firstname)
|
66
66
|
end
|
67
|
-
|
68
|
-
|
67
|
+
|
68
|
+
|
69
69
|
it "should expect that its subclasses render the children" do
|
70
|
-
error_message = "Method Section
|
71
|
-
|
70
|
+
error_message = "Method Section.render must be implemented in subclass."
|
71
|
+
->(){ subject.send(:render, Object.new, {}) }.should raise_error(
|
72
|
+
NotImplementedError, error_message)
|
72
73
|
end
|
73
|
-
|
74
|
+
|
74
75
|
end # context
|
75
76
|
|
76
77
|
end # describe
|
@@ -83,11 +84,11 @@ describe ConditionalSection do
|
|
83
84
|
context "Creation and initialization:" do
|
84
85
|
|
85
86
|
it "should be created with a variable name and a boolean" do
|
86
|
-
|
87
|
-
|
87
|
+
->(){ ConditionalSection.new('foobar', false) }.should_not raise_error
|
88
|
+
->(){ ConditionalSection.new('foobar', true) }.should_not raise_error
|
88
89
|
end
|
89
90
|
|
90
|
-
it "should know whether the rendition on existence of actual value
|
91
|
+
it "should know whether the rendition on existence of actual value" do
|
91
92
|
[false, true].each do |existence|
|
92
93
|
instance = ConditionalSection.new('foobar', existence)
|
93
94
|
instance.existence.should == existence
|
@@ -107,7 +108,7 @@ describe ConditionalSection do
|
|
107
108
|
|
108
109
|
# Default instantiation rule
|
109
110
|
subject { ConditionalSection.new('foobar', true) }
|
110
|
-
|
111
|
+
|
111
112
|
it "should know its original source text" do
|
112
113
|
subject.to_s.should == '<?foobar>'
|
113
114
|
end
|
@@ -117,17 +118,18 @@ describe ConditionalSection do
|
|
117
118
|
sample_children.each { |a_child| subject.add_child(a_child) }
|
118
119
|
|
119
120
|
# Case of an existing actual
|
120
|
-
locals = {'user' => "joe", "foobar" => 'exists' }
|
121
|
+
locals = { 'user' => "joe", "foobar" => 'exists' }
|
121
122
|
rendered_text = subject.render(Object.new, locals)
|
122
123
|
expected_text = "Hello joe\n"
|
123
124
|
rendered_text.should == expected_text
|
124
125
|
|
125
|
-
# Case of a conditional section that should be
|
126
|
+
# Case of a conditional section that should be
|
127
|
+
# rendering when value is non-existing.
|
126
128
|
instance = ConditionalSection.new('foobar', false)
|
127
129
|
sample_children.each { |a_child| instance.add_child(a_child) }
|
128
130
|
|
129
131
|
# Case of a non-existing actual
|
130
|
-
locals = {'user' => "joe" }
|
132
|
+
locals = { 'user' => "joe" }
|
131
133
|
rendered_text = instance.render(Object.new, locals)
|
132
134
|
rendered_text.should == expected_text
|
133
135
|
end
|
@@ -137,16 +139,17 @@ describe ConditionalSection do
|
|
137
139
|
sample_children.each { |a_child| subject.add_child(a_child) }
|
138
140
|
|
139
141
|
# Case of a non-existing actual
|
140
|
-
locals = {'user' => "joe"}
|
142
|
+
locals = { 'user' => "joe" }
|
141
143
|
rendered_text = subject.render(Object.new, locals)
|
142
144
|
rendered_text.should == ""
|
143
145
|
|
144
|
-
# Case of a conditional section that should be
|
146
|
+
# Case of a conditional section that should be
|
147
|
+
# rendering when value is non-existing.
|
145
148
|
instance = ConditionalSection.new('foobar', false)
|
146
149
|
sample_children.each { |a_child| instance.add_child(a_child) }
|
147
150
|
|
148
151
|
# Case of a non-existing actual
|
149
|
-
locals = {'user' => "joe", "foobar" => 'exists' }
|
152
|
+
locals = { 'user' => "joe", "foobar" => 'exists' }
|
150
153
|
rendered_text = instance.render(Object.new, locals)
|
151
154
|
rendered_text.should == ""
|
152
155
|
end
|
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.3.
|
4
|
+
version: 0.3.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|