@@ -6,6 +6,7 @@ module CucumberJsMappings
6
6
WORLD_FUNCTION_LOG_FILE = "world_function.log"
7
7
DATA_TABLE_LOG_FILE = "data_table.log"
8
8
CYCLE_LOG_FILE = "cycle.log"
9
+ CYCLE_SEQUENCE_SEPARATOR = " -> "
9
10
10
11
attr_accessor :support_code
11
12
@@ -135,23 +136,34 @@ def write_world_function
135
136
EOF
136
137
end
137
138
138
- def write_passing_hook hook_type
139
+ def write_passing_hook options = { }
140
+ log_string = options [ :log_cycle_event_as ]
141
+ if options [ :type ]
142
+ hook_type = options [ :type ]
143
+ log_string ||= hook_type
144
+ else
145
+ hook_type = "before"
146
+ log_string ||= "hook"
147
+ end
148
+ tags = options [ :tags ] || [ ]
139
149
provide_cycle_logging_facilities
140
150
define_hook = hook_type . capitalize
151
+ params = tags . any? ? "'#{ tags . join ( "', '" ) } ', " : ""
152
+
141
153
if hook_type == "around"
142
154
append_support_code <<-EOF
143
- this.#{ define_hook } (function(runScenario) {
144
- this.logCycleEvent('#{ hook_type } -pre');
155
+ this.#{ define_hook } (#{ params } function(runScenario) {
156
+ this.logCycleEvent('#{ log_string } -pre');
145
157
runScenario(function(callback) {
146
- this.logCycleEvent('#{ hook_type } -post');
158
+ this.logCycleEvent('#{ log_string } -post');
147
159
callback();
148
160
});
149
161
});
150
162
EOF
151
163
else
152
164
append_support_code <<-EOF
153
- this.#{ define_hook } (function(callback) {
154
- this.logCycleEvent('#{ hook_type } ');
165
+ this.#{ define_hook } (#{ params } function(callback) {
166
+ this.logCycleEvent('#{ log_string } ');
155
167
callback();
156
168
});
157
169
EOF
@@ -178,7 +190,7 @@ def provide_cycle_logging_facilities
178
190
append_support_code <<-EOF
179
191
this.World.prototype.logCycleEvent = function logCycleEvent(name) {
180
192
fd = fs.openSync('#{ CYCLE_LOG_FILE } ', 'a');
181
- fs.writeSync(fd, " -> " + name, null);
193
+ fs.writeSync(fd, "#{ CYCLE_SEQUENCE_SEPARATOR } " + name, null);
182
194
fs.closeSync(fd);
183
195
};
184
196
EOF
@@ -224,12 +236,18 @@ def assert_world_function_called
224
236
end
225
237
226
238
def assert_cycle_sequence *args
227
- expected_string = args . join " -> "
239
+ expected_string = args . join CYCLE_SEQUENCE_SEPARATOR
228
240
check_file_content ( CucumberJsMappings ::CYCLE_LOG_FILE , expected_string , true )
229
241
end
230
242
243
+ def assert_cycle_sequence_excluding *args
244
+ args . each do |unexpected_string |
245
+ check_file_content ( CucumberJsMappings ::CYCLE_LOG_FILE , unexpected_string , false )
246
+ end
247
+ end
248
+
231
249
def assert_complete_cycle_sequence *args
232
- expected_string = args . join " -> "
250
+ expected_string = " #{ CYCLE_SEQUENCE_SEPARATOR } #{ args . join ( CYCLE_SEQUENCE_SEPARATOR ) } "
233
251
check_exact_file_content ( CucumberJsMappings ::CYCLE_LOG_FILE , expected_string )
234
252
end
235
253
@@ -259,10 +277,10 @@ def assert_suggested_step_definition_snippet(stepdef_keyword, stepdef_pattern, p
259
277
end
260
278
261
279
def assert_executed_scenarios *scenario_offsets
262
- sequence = scenario_offsets . inject ( '' ) do |sequence , scenario_offset |
263
- " #{ sequence } -> #{ nth_step_name ( scenario_offset ) } "
280
+ sequence = scenario_offsets . inject ( [ ] ) do |sequence , scenario_offset |
281
+ sequence << nth_step_name ( scenario_offset )
264
282
end
265
- assert_complete_cycle_sequence sequence
283
+ assert_complete_cycle_sequence * sequence
266
284
end
267
285
268
286
def failed_output
0 commit comments