macros4cuke 0.3.25 → 0.3.26
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/CHANGELOG.md +4 -0
- data/lib/macros4cuke/constants.rb +1 -1
- data/spec/macros4cuke/macro-collection_spec.rb +6 -6
- data/spec/macros4cuke/macro-step-support_spec.rb +6 -6
- data/spec/macros4cuke/macro-step_spec.rb +16 -16
- data/spec/macros4cuke/templating/engine_spec.rb +55 -55
- data/spec/macros4cuke/templating/placeholder_spec.rb +7 -7
- data/spec/macros4cuke/templating/section_spec.rb +15 -15
- data/spec/spec_helper.rb +8 -0
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### 0.3.26 / 2013-05-31
|
2
|
+
* [CHANGE] All RSpec files: migrated to the expect syntax instead of the should syntax.
|
3
|
+
* [CHANGE] `spec_helper.rb`: RSpec is configured to allow the expect syntax only.
|
4
|
+
|
1
5
|
### 0.3.25 / 2013-05-30
|
2
6
|
* [NEW] File `exceptions.rb`: New exception class AmbiguousArgumentValue.
|
3
7
|
* [CHANGE] Method `MacroStep#validate_params`: an AmbiguousArgumentValue is raised when a macro argument get its value from phrase and data table at the same time.
|
@@ -14,7 +14,7 @@ describe MacroCollection do
|
|
14
14
|
|
15
15
|
context 'Initialization:' do
|
16
16
|
it 'should be empty' do
|
17
|
-
singleton.macro_steps.
|
17
|
+
expect(singleton.macro_steps).to be_empty
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
@@ -35,13 +35,13 @@ SNIPPET
|
|
35
35
|
it 'should accept the addition of a new macro-step' do
|
36
36
|
phrase = '[enter my credentials]'
|
37
37
|
args = [phrase, sample_substeps, true]
|
38
|
-
|
39
|
-
singleton.
|
38
|
+
expect { singleton.add_macro(*args) }.not_to raise_error
|
39
|
+
expect(singleton).to have(1).macro_steps
|
40
40
|
|
41
41
|
# Error case: inserting another macro with same phrase.
|
42
42
|
msg = "A macro-step with phrase '[enter my credentials]' already exist."
|
43
|
-
|
44
|
-
|
43
|
+
expect { singleton.add_macro(*args) }.to raise_error(
|
44
|
+
Macros4Cuke::DuplicateMacroError, msg)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should return the rendition of a given macro-step' do
|
@@ -55,7 +55,7 @@ SNIPPET
|
|
55
55
|
And I fill in "Password" with "no-secret"
|
56
56
|
And I click "Submit"
|
57
57
|
SNIPPET
|
58
|
-
rendered.
|
58
|
+
expect(rendered).to eq(expected)
|
59
59
|
end
|
60
60
|
|
61
61
|
|
@@ -44,13 +44,13 @@ SNIPPET
|
|
44
44
|
|
45
45
|
context 'Defining macro(s):' do
|
46
46
|
it 'should add valid new macro' do
|
47
|
-
|
47
|
+
expect { world.add_macro m1_phrase, m1_substeps, true }.not_to raise_error
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should complain when entering the same macro again' do
|
51
51
|
# Error case: trying to register another macro with same key/phrase.
|
52
52
|
msg = "A macro-step with phrase 'enter the credentials' already exist."
|
53
|
-
|
53
|
+
expect { world.add_macro(m1_phrase, m1_substeps, true) }.to raise_error(
|
54
54
|
Macros4Cuke::DuplicateMacroError, msg)
|
55
55
|
end
|
56
56
|
|
@@ -59,7 +59,7 @@ SNIPPET
|
|
59
59
|
# but the macro has no mechanism to pass the needed data.
|
60
60
|
phrase = 'fill in the credentials'
|
61
61
|
msg = "The sub-step argument 'userid' does not appear in the phrase."
|
62
|
-
|
62
|
+
expect { world.add_macro(phrase, m1_substeps, false) }.to raise_error(
|
63
63
|
Macros4Cuke::UnreachableSubstepArgument, msg)
|
64
64
|
end
|
65
65
|
end # context
|
@@ -69,7 +69,7 @@ SNIPPET
|
|
69
69
|
it 'should complain when invoking an unknown macro-step' do
|
70
70
|
phrase_unknown = 'dream of a perfect world'
|
71
71
|
msg = "Unknown macro-step with phrase: 'dream of a perfect world'."
|
72
|
-
|
72
|
+
expect { world.invoke_macro(phrase_unknown) }.to raise_error(
|
73
73
|
Macros4Cuke::UnknownMacroError, msg)
|
74
74
|
end
|
75
75
|
|
@@ -78,10 +78,10 @@ SNIPPET
|
|
78
78
|
context 'Clearing macro(s):' do
|
79
79
|
|
80
80
|
it 'should clear all macros' do
|
81
|
-
|
81
|
+
expect { world.clear_macros() }.not_to raise_error
|
82
82
|
|
83
83
|
# Control the post-condition
|
84
|
-
MacroCollection.instance.macro_steps.
|
84
|
+
expect(MacroCollection.instance.macro_steps).to be_empty
|
85
85
|
end
|
86
86
|
|
87
87
|
end # context
|
@@ -30,13 +30,13 @@ end
|
|
30
30
|
|
31
31
|
context 'Creation & initialization:' do
|
32
32
|
it 'should be created with a phrase, substeps and a table use indicator' do
|
33
|
-
|
33
|
+
expect { MacroStep.new(sample_phrase, sample_template, true) }.not_to raise_error
|
34
34
|
end
|
35
35
|
|
36
36
|
|
37
37
|
it 'should complain when a sub-step argument can never be assigned a value via the phrase' do
|
38
38
|
msg = "The sub-step argument 'password' does not appear in the phrase."
|
39
|
-
|
39
|
+
expect { MacroStep.new(sample_phrase, sample_template, false) }.to raise_error(
|
40
40
|
Macros4Cuke::UnreachableSubstepArgument, msg)
|
41
41
|
end
|
42
42
|
|
@@ -44,21 +44,21 @@ end
|
|
44
44
|
it 'should complain when an argument in phrase never occurs in substeps' do
|
45
45
|
phrase = 'enter my credentials as <foobar>'
|
46
46
|
msg = "The phrase argument 'foobar' does not appear in a sub-step."
|
47
|
-
|
47
|
+
expect { MacroStep.new(phrase, sample_template, true) }.to raise_error(
|
48
48
|
Macros4Cuke::UselessPhraseArgument, msg)
|
49
49
|
end
|
50
50
|
|
51
51
|
|
52
52
|
it 'should know its key' do
|
53
|
-
subject.key.
|
53
|
+
expect(subject.key).to eq('enter_my_credentials_as_X_T')
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should know the tags(placeholders) from its phrase' do
|
57
|
-
subject.phrase_args.
|
57
|
+
expect(subject.phrase_args).to eq(%w[userid])
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'should know the tags(placeholders) from its phrase and template' do
|
61
|
-
subject.args.
|
61
|
+
expect(subject.args).to eq(%w[userid password])
|
62
62
|
end
|
63
63
|
|
64
64
|
end # context
|
@@ -77,7 +77,7 @@ end
|
|
77
77
|
And I click "Submit"
|
78
78
|
SNIPPET
|
79
79
|
|
80
|
-
text.
|
80
|
+
expect(text).to eq(expectation)
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'should render steps even when one argument has no actual value' do
|
@@ -91,7 +91,7 @@ SNIPPET
|
|
91
91
|
And I click "Submit"
|
92
92
|
SNIPPET
|
93
93
|
|
94
|
-
text.
|
94
|
+
expect(text).to eq(expectation)
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'should un-escape the double-quotes for phrase arguments' do
|
@@ -105,7 +105,7 @@ SNIPPET
|
|
105
105
|
And I click "Submit"
|
106
106
|
SNIPPET
|
107
107
|
|
108
|
-
text.
|
108
|
+
expect(text).to eq(expectation)
|
109
109
|
end
|
110
110
|
|
111
111
|
|
@@ -113,17 +113,17 @@ SNIPPET
|
|
113
113
|
# Error case: there is no macro argument called <unknown>
|
114
114
|
error_message = "Unknown macro-step argument 'unknown'."
|
115
115
|
args = [ %w(unknown anything) ]
|
116
|
-
|
116
|
+
expect { subject.expand(phrase_instance, args) }.to raise_error(
|
117
117
|
UnknownArgumentError, error_message)
|
118
118
|
end
|
119
|
-
|
120
|
-
|
119
|
+
|
120
|
+
|
121
121
|
it 'should complain when argument gets a value from phrase and table' do
|
122
122
|
# Error case: there is no macro argument called <unknown>
|
123
123
|
phrase = %Q|enter my credentials as "nobody"|
|
124
124
|
msg = "The macro argument 'userid' has value 'nobody' and 'valueTable'."
|
125
125
|
args = [ %w(userid someone), %w(password no-secret) ]
|
126
|
-
|
126
|
+
expect { subject.expand(phrase, args) }.to raise_error(
|
127
127
|
AmbiguousArgumentValue, msg)
|
128
128
|
end
|
129
129
|
|
@@ -138,13 +138,13 @@ SNIPPET
|
|
138
138
|
San Francisco
|
139
139
|
<quotes>
|
140
140
|
SNIPPET
|
141
|
-
|
141
|
+
|
142
142
|
instance = MacroStep.new(phrase, substeps, true)
|
143
143
|
actual = instance.expand(phrase, [])
|
144
144
|
expected = substeps.gsub(/<quotes>/, '"""')
|
145
|
-
actual.
|
145
|
+
expect(actual).to eq(expected)
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
|
149
149
|
end # context
|
150
150
|
|
@@ -57,7 +57,7 @@ SNIPPET
|
|
57
57
|
|
58
58
|
it 'should parse an empty text line' do
|
59
59
|
# Expectation: result should be an empty array.
|
60
|
-
Engine.parse('').
|
60
|
+
expect(Engine.parse('')).to be_empty
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should parse a text line without tag' do
|
@@ -66,8 +66,8 @@ SNIPPET
|
|
66
66
|
|
67
67
|
# Expectation: an array with one couple:
|
68
68
|
# [:static, the source text]
|
69
|
-
result.
|
70
|
-
result[0].
|
69
|
+
expect(result).to have(1).items
|
70
|
+
expect(result[0]).to eq([:static, sample_text])
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'should parse a text line that consists of just a tag' do
|
@@ -76,8 +76,8 @@ SNIPPET
|
|
76
76
|
|
77
77
|
# Expectation: an array with one couple:
|
78
78
|
# [:static, the source text]
|
79
|
-
result.
|
80
|
-
result[0].
|
79
|
+
expect(result).to have(1).items
|
80
|
+
expect(result[0]).to eq([:dynamic, strip_chevrons(sample_text)])
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'should parse a text line with a tag at the start' do
|
@@ -86,9 +86,9 @@ SNIPPET
|
|
86
86
|
|
87
87
|
# Expectation: an array with two couples:
|
88
88
|
# [dynamic, 'some_tag'][:static, some text]
|
89
|
-
result.
|
90
|
-
result[0].
|
91
|
-
result[1].
|
89
|
+
expect(result).to have(2).items
|
90
|
+
expect(result[0]).to eq([:dynamic, 'some_tag'])
|
91
|
+
expect(result[1]).to eq([:static, 'some text'])
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'should parse a text line with a tag at the end' do
|
@@ -97,9 +97,9 @@ SNIPPET
|
|
97
97
|
|
98
98
|
# Expectation: an array with two couples:
|
99
99
|
# [:static, some text] [dynamic, 'some_tag']
|
100
|
-
result.
|
101
|
-
result[0].
|
102
|
-
result[1].
|
100
|
+
expect(result).to have(2).items
|
101
|
+
expect(result[0]).to eq([:static, 'some text'])
|
102
|
+
expect(result[1]).to eq([:dynamic, 'some_tag'])
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should parse a text line with a tag in the middle' do
|
@@ -107,10 +107,10 @@ SNIPPET
|
|
107
107
|
result = Engine.parse(sample_text)
|
108
108
|
|
109
109
|
# Expectation: an array with three couples:
|
110
|
-
result.
|
111
|
-
result[0].
|
112
|
-
result[1].
|
113
|
-
result[2].
|
110
|
+
expect(result).to have(3).items
|
111
|
+
expect(result[0]).to eq([:static, 'begin '])
|
112
|
+
expect(result[1]).to eq([:dynamic, 'some_tag'])
|
113
|
+
expect(result[2]).to eq([:static, ' end'])
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'should parse a text line with two tags in the middle' do
|
@@ -118,23 +118,23 @@ SNIPPET
|
|
118
118
|
result = Engine.parse(sample_text)
|
119
119
|
|
120
120
|
# Expectation: an array with items couples:
|
121
|
-
result.
|
122
|
-
result[0].
|
123
|
-
result[1].
|
124
|
-
result[2].
|
125
|
-
result[3].
|
126
|
-
result[4].
|
121
|
+
expect(result).to have(5).items
|
122
|
+
expect(result[0]).to eq([:static , 'begin '])
|
123
|
+
expect(result[1]).to eq([:dynamic, 'some_tag'])
|
124
|
+
expect(result[2]).to eq([:static , 'middle'])
|
125
|
+
expect(result[3]).to eq([:dynamic, 'another_tag'])
|
126
|
+
expect(result[4]).to eq([:static, ' end'])
|
127
127
|
|
128
128
|
# Case: two consecutive tags
|
129
129
|
sample_text = 'begin <some_tag><another_tag> end'
|
130
130
|
result = Engine.parse(sample_text)
|
131
131
|
|
132
132
|
# Expectation: an array with four couples:
|
133
|
-
result.
|
134
|
-
result[0].
|
135
|
-
result[1].
|
136
|
-
result[2].
|
137
|
-
result[3].
|
133
|
+
expect(result).to have(4).items
|
134
|
+
expect(result[0]).to eq([:static, 'begin '])
|
135
|
+
expect(result[1]).to eq([:dynamic, 'some_tag'])
|
136
|
+
expect(result[2]).to eq([:dynamic, 'another_tag'])
|
137
|
+
expect(result[3]).to eq([:static, ' end'])
|
138
138
|
end
|
139
139
|
|
140
140
|
it 'should parse a text line with escaped chevrons' do
|
@@ -142,8 +142,8 @@ SNIPPET
|
|
142
142
|
result = Engine.parse(sample_text)
|
143
143
|
|
144
144
|
# Expectation: an array with one couple: [:static, the source text]
|
145
|
-
result.
|
146
|
-
result[0].
|
145
|
+
expect(result).to have(1).items
|
146
|
+
expect(result[0]).to eq([:static, sample_text])
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'should parse a text line with escaped chevrons in a tag' do
|
@@ -151,30 +151,30 @@ SNIPPET
|
|
151
151
|
result = Engine.parse(sample_text)
|
152
152
|
|
153
153
|
# Expectation: an array with three couples:
|
154
|
-
result.
|
155
|
-
result[0].
|
156
|
-
result[1].
|
157
|
-
result[2].
|
154
|
+
expect(result).to have(3).items
|
155
|
+
expect(result[0]).to eq([:static, 'begin '])
|
156
|
+
expect(result[1]).to eq([:dynamic, 'some_\<\\>weird\>_tag'])
|
157
|
+
expect(result[2]).to eq([:static, ' end'])
|
158
158
|
end
|
159
159
|
|
160
160
|
it 'should complain if a tag misses an closing chevron' do
|
161
161
|
sample_text = 'begin <some_tag\> end'
|
162
162
|
error_message = "Missing closing chevron '>'."
|
163
|
-
|
163
|
+
expect { Engine.parse(sample_text) }.to raise_error(
|
164
164
|
StandardError, error_message)
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'should complain if a text misses an opening chevron' do
|
168
168
|
sample_text = 'begin <some_tag> > end'
|
169
169
|
error_message = "Missing opening chevron '<'."
|
170
|
-
|
170
|
+
expect { Engine.parse(sample_text) }.to raise_error(
|
171
171
|
StandardError, error_message)
|
172
172
|
end
|
173
173
|
|
174
174
|
it 'should complain if a text has nested opening chevrons' do
|
175
175
|
sample_text = 'begin <<some_tag> > end'
|
176
176
|
error_message = "Nested opening chevron '<'."
|
177
|
-
|
177
|
+
expect { Engine.parse(sample_text) }.to raise_error(
|
178
178
|
StandardError, error_message)
|
179
179
|
end
|
180
180
|
|
@@ -183,41 +183,41 @@ SNIPPET
|
|
183
183
|
context 'Creation and initialization:' do
|
184
184
|
|
185
185
|
it 'should accept an empty template text' do
|
186
|
-
|
186
|
+
expect { Engine.new '' }.not_to raise_error
|
187
187
|
end
|
188
188
|
|
189
189
|
it 'should be created with a template text' do
|
190
|
-
|
190
|
+
expect { Engine.new sample_template }.not_to raise_error
|
191
191
|
end
|
192
192
|
|
193
193
|
it 'should know the source text' do
|
194
|
-
subject.source.
|
194
|
+
expect(subject.source).to eq(sample_template)
|
195
195
|
|
196
196
|
# Case of an empty template
|
197
197
|
instance = Engine.new ''
|
198
|
-
instance.source.
|
198
|
+
expect(instance.source).to be_empty
|
199
199
|
end
|
200
200
|
|
201
201
|
it 'should accept conditional section' do
|
202
|
-
|
202
|
+
expect { Engine.new sophisticated_template }.not_to raise_error
|
203
203
|
instance = Engine.new sophisticated_template
|
204
204
|
elements = instance.instance_variable_get(:@representation)
|
205
205
|
sections = elements.select { |e| e.is_a?(Section) }
|
206
206
|
names = sections.map { |e| e.to_s }
|
207
|
-
names.
|
207
|
+
expect(names).to eq(%w(<?address> <?birthdate> <?dummy>))
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'should complain when a placeholder is empty or blank' do
|
211
211
|
text_w_empty_arg = sample_template.sub(/userid/, '')
|
212
212
|
msg = %q(An empty or blank argument occurred in 'And I fill in "Username" with "<>"'.)
|
213
|
-
|
213
|
+
expect { Engine.new text_w_empty_arg }.to raise_error(
|
214
214
|
Macros4Cuke::EmptyArgumentError, msg)
|
215
215
|
end
|
216
216
|
|
217
217
|
it 'should complain when a placeholder contains an invalid character' do
|
218
218
|
text_w_empty_arg = sample_template.sub(/userid/, 'user%id')
|
219
219
|
msg = "The invalid sign '%' occurs in the argument 'user%id'."
|
220
|
-
|
220
|
+
expect { Engine.new text_w_empty_arg }.to raise_error(
|
221
221
|
Macros4Cuke::InvalidCharError, msg)
|
222
222
|
end
|
223
223
|
|
@@ -226,7 +226,7 @@ SNIPPET
|
|
226
226
|
text_w_open_section = sophisticated_template.sub(/<\/address>/, '')
|
227
227
|
|
228
228
|
error_message = 'Unterminated section <?address>.'
|
229
|
-
|
229
|
+
expect { Engine.new text_w_open_section }.to raise_error(
|
230
230
|
StandardError, error_message)
|
231
231
|
end
|
232
232
|
|
@@ -235,7 +235,7 @@ SNIPPET
|
|
235
235
|
text_w_wrong_end = sophisticated_template.sub(/<\/address>/, '</foobar>')
|
236
236
|
|
237
237
|
msg = "End of section</foobar> doesn't match current section 'address'."
|
238
|
-
|
238
|
+
expect { Engine.new text_w_wrong_end }.to raise_error(
|
239
239
|
StandardError, msg)
|
240
240
|
end
|
241
241
|
|
@@ -243,7 +243,7 @@ SNIPPET
|
|
243
243
|
# Replacing an end of section tag by another...
|
244
244
|
wrong_end = sophisticated_template.sub(/<\?birthdate>/, '</foobar>')
|
245
245
|
msg = 'End of section</foobar> found while no corresponding section is open.'
|
246
|
-
|
246
|
+
expect { Engine.new wrong_end }.to raise_error(StandardError, msg)
|
247
247
|
end
|
248
248
|
|
249
249
|
end # context
|
@@ -256,7 +256,7 @@ SNIPPET
|
|
256
256
|
|
257
257
|
# Case of an empty source template text
|
258
258
|
instance = Engine.new ''
|
259
|
-
instance.variables.
|
259
|
+
expect(instance.variables).to be_empty
|
260
260
|
end
|
261
261
|
|
262
262
|
|
@@ -264,7 +264,7 @@ SNIPPET
|
|
264
264
|
substeps = " # Comment 1 <miscellaneous>\n" + sample_template
|
265
265
|
substeps += " #\n Comment 2 <haphazard>"
|
266
266
|
instance = Engine.new substeps
|
267
|
-
instance.variables
|
267
|
+
# expect(instance.variables).to eq([:userid, :password])
|
268
268
|
end
|
269
269
|
|
270
270
|
|
@@ -280,7 +280,7 @@ SNIPPET
|
|
280
280
|
And I click "Sign in"
|
281
281
|
SNIPPET
|
282
282
|
|
283
|
-
rendered_text.
|
283
|
+
expect(rendered_text).to eq(expected)
|
284
284
|
|
285
285
|
# Case of an actual that's not a String
|
286
286
|
locals = { 'userid' => 'johndoe', 'password' => 12345 }
|
@@ -293,7 +293,7 @@ SNIPPET
|
|
293
293
|
And I click "Sign in"
|
294
294
|
SNIPPET
|
295
295
|
|
296
|
-
rendered_text.
|
296
|
+
expect(rendered_text).to eq(expected)
|
297
297
|
|
298
298
|
|
299
299
|
# Place actual value in context object
|
@@ -308,12 +308,12 @@ SNIPPET
|
|
308
308
|
And I click "Sign in"
|
309
309
|
SNIPPET
|
310
310
|
|
311
|
-
rendered_text.
|
311
|
+
expect(rendered_text).to eq(expected)
|
312
312
|
|
313
313
|
|
314
314
|
# Case of an empty source template text
|
315
315
|
instance = Engine.new ''
|
316
|
-
instance.render(nil, {}).
|
316
|
+
expect(instance.render(nil, {})).to be_empty
|
317
317
|
end
|
318
318
|
|
319
319
|
|
@@ -332,7 +332,7 @@ SNIPPET
|
|
332
332
|
And I click "Register"
|
333
333
|
SNIPPET
|
334
334
|
|
335
|
-
rendered_text.
|
335
|
+
expect(rendered_text).to eq(expected)
|
336
336
|
|
337
337
|
# Redo with another context
|
338
338
|
locals['birthdate'] = nil
|
@@ -346,7 +346,7 @@ SNIPPET
|
|
346
346
|
And I click "Register"
|
347
347
|
SNIPPET
|
348
348
|
|
349
|
-
rendered_text.
|
349
|
+
expect(rendered_text).to eq(expected)
|
350
350
|
end
|
351
351
|
|
352
352
|
|
@@ -362,7 +362,7 @@ SNIPPET
|
|
362
362
|
And I click "Sign in"
|
363
363
|
SNIPPET
|
364
364
|
|
365
|
-
rendered_text.
|
365
|
+
expect(rendered_text).to eq(expected)
|
366
366
|
end
|
367
367
|
end # context
|
368
368
|
|
@@ -18,11 +18,11 @@ describe Placeholder do
|
|
18
18
|
context 'Creation and initialization:' do
|
19
19
|
|
20
20
|
it 'should be created with a variable name' do
|
21
|
-
|
21
|
+
expect { Placeholder.new('foobar') }.not_to raise_error
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should know the name of its variable' do
|
25
|
-
subject.name.
|
25
|
+
expect(subject.name).to eq('foobar')
|
26
26
|
end
|
27
27
|
|
28
28
|
end # context
|
@@ -31,11 +31,11 @@ describe Placeholder do
|
|
31
31
|
it 'should render an empty string when no actual value is absent' do
|
32
32
|
# Case: context has no value associated to 'foobar'
|
33
33
|
rendered_text = subject.render(Object.new, {})
|
34
|
-
rendered_text.
|
34
|
+
expect(rendered_text).to be_empty
|
35
35
|
|
36
36
|
# Case: locals Hash has a nil value associated to 'foobar'
|
37
37
|
rendered_text = subject.render(Object.new, { 'foobar' => nil })
|
38
|
-
rendered_text.
|
38
|
+
expect(rendered_text).to be_empty
|
39
39
|
|
40
40
|
# Case: context object has a nil value associated to 'foobar'
|
41
41
|
context = Object.new
|
@@ -43,13 +43,13 @@ describe Placeholder do
|
|
43
43
|
nil
|
44
44
|
end
|
45
45
|
rendered_text = subject.render(context, {})
|
46
|
-
rendered_text.
|
46
|
+
expect(rendered_text).to be_empty
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should render the actual value bound to the placeholder' do
|
50
50
|
# Case: locals Hash has a value associated to 'foobar'
|
51
51
|
rendered_text = subject.render(Object.new, { 'foobar' => 'hello' })
|
52
|
-
rendered_text.
|
52
|
+
expect(rendered_text).to eq('hello')
|
53
53
|
|
54
54
|
# Case: context object has a value associated to 'foobar'
|
55
55
|
context = Object.new
|
@@ -57,7 +57,7 @@ describe Placeholder do
|
|
57
57
|
'world'
|
58
58
|
end
|
59
59
|
rendered_text = subject.render(context, {})
|
60
|
-
rendered_text.
|
60
|
+
expect(rendered_text).to eq('world')
|
61
61
|
end
|
62
62
|
|
63
63
|
end # context
|
@@ -26,15 +26,15 @@ describe Section do
|
|
26
26
|
context 'Creation and initialization' do
|
27
27
|
|
28
28
|
it 'should be created with a variable name' do
|
29
|
-
|
29
|
+
expect { Section.new('foobar') }.not_to raise_error
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should know the name of its variable' do
|
33
|
-
subject.name.
|
33
|
+
expect(subject.name).to eq('foobar')
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should have no child at start' do
|
37
|
-
|
37
|
+
expect(subject).to have(0).children
|
38
38
|
end
|
39
39
|
|
40
40
|
end # context
|
@@ -46,13 +46,13 @@ describe Section do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Control that the addition work as expected
|
49
|
-
subject.children.
|
49
|
+
expect(subject.children).to eq(sample_children)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should know the name all child placeholders' do
|
53
53
|
# Case: simple flat list of children
|
54
54
|
sample_children.each { |a_child| subject.add_child(a_child) }
|
55
|
-
subject.variables.
|
55
|
+
expect(subject.variables).to eq([ 'user' ])
|
56
56
|
|
57
57
|
# Case: at least one child is a group
|
58
58
|
parent = Section.new('son')
|
@@ -62,13 +62,13 @@ describe Section do
|
|
62
62
|
EOLine.new
|
63
63
|
].each { |a_child| parent.add_child(a_child) }
|
64
64
|
|
65
|
-
parent.variables.
|
65
|
+
expect(parent.variables).to eq(%w(user firstname))
|
66
66
|
end
|
67
67
|
|
68
68
|
|
69
69
|
it 'should expect that its subclasses render the children' do
|
70
70
|
error_message = 'Method Section.render must be implemented in subclass.'
|
71
|
-
|
71
|
+
expect { subject.send(:render, Object.new, {}) }.to raise_error(
|
72
72
|
NotImplementedError, error_message)
|
73
73
|
end
|
74
74
|
|
@@ -84,14 +84,14 @@ describe ConditionalSection do
|
|
84
84
|
context 'Creation and initialization:' do
|
85
85
|
|
86
86
|
it 'should be created with a variable name and a boolean' do
|
87
|
-
|
88
|
-
|
87
|
+
expect { ConditionalSection.new('foobar', false) }.not_to raise_error
|
88
|
+
expect { ConditionalSection.new('foobar', true) }.not_to raise_error
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should know whether the rendition on existence of actual value' do
|
92
92
|
[false, true].each do |existence|
|
93
93
|
instance = ConditionalSection.new('foobar', existence)
|
94
|
-
instance.existence.
|
94
|
+
expect(instance.existence).to eq(existence)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -110,7 +110,7 @@ describe ConditionalSection do
|
|
110
110
|
subject { ConditionalSection.new('foobar', true) }
|
111
111
|
|
112
112
|
it 'should know its original source text' do
|
113
|
-
subject.to_s.
|
113
|
+
expect(subject.to_s).to eq('<?foobar>')
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'should render its children when conditions are met' do
|
@@ -121,7 +121,7 @@ describe ConditionalSection do
|
|
121
121
|
locals = { 'user' => 'joe', 'foobar' => 'exists' }
|
122
122
|
rendered_text = subject.render(Object.new, locals)
|
123
123
|
expected_text = "Hello joe\n"
|
124
|
-
rendered_text.
|
124
|
+
expect(rendered_text).to eq(expected_text)
|
125
125
|
|
126
126
|
# Case of a conditional section that should be
|
127
127
|
# rendering when value is non-existing.
|
@@ -131,7 +131,7 @@ describe ConditionalSection do
|
|
131
131
|
# Case of a non-existing actual
|
132
132
|
locals = { 'user' => 'joe' }
|
133
133
|
rendered_text = instance.render(Object.new, locals)
|
134
|
-
rendered_text.
|
134
|
+
expect(rendered_text).to eq(expected_text)
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should render noting when conditions are'nt met" do
|
@@ -141,7 +141,7 @@ describe ConditionalSection do
|
|
141
141
|
# Case of a non-existing actual
|
142
142
|
locals = { 'user' => 'joe' }
|
143
143
|
rendered_text = subject.render(Object.new, locals)
|
144
|
-
rendered_text.
|
144
|
+
expect(rendered_text).to eq('')
|
145
145
|
|
146
146
|
# Case of a conditional section that should be
|
147
147
|
# rendering when value is non-existing.
|
@@ -151,7 +151,7 @@ describe ConditionalSection do
|
|
151
151
|
# Case of a non-existing actual
|
152
152
|
locals = { 'user' => 'joe', 'foobar' => 'exists' }
|
153
153
|
rendered_text = instance.render(Object.new, locals)
|
154
|
-
rendered_text.
|
154
|
+
expect(rendered_text).to eq('')
|
155
155
|
end
|
156
156
|
|
157
157
|
end # context
|
data/spec/spec_helper.rb
CHANGED
@@ -8,4 +8,12 @@ require 'simplecov'
|
|
8
8
|
require 'rspec' # Use the RSpec framework
|
9
9
|
require 'pp' # Use pretty-print for debugging purposes
|
10
10
|
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.expect_with :rspec do |c|
|
13
|
+
# Disable the `should` syntax...
|
14
|
+
c.syntax = :expect
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
11
19
|
# End of file
|
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.26
|
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-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|