forked from cucumber/aruba
/
cucumber.rb
360 lines (284 loc) · 10.9 KB
/
cucumber.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
require 'aruba/api'
require 'aruba/cucumber/hooks'
require 'aruba/reporting'
World(Aruba::Api)
Given /The default aruba timeout is (\d+) seconds/ do |seconds|
@aruba_timeout_seconds = seconds.to_i
end
Given /^I'm using a clean gemset "([^"]*)"$/ do |gemset|
use_clean_gemset(gemset)
end
Given /^a directory named "([^"]*)"$/ do |dir_name|
create_dir(dir_name)
end
Given /^a directory named "([^"]*)" with mode "([^"]*)"$/ do |dir_name, dir_mode|
create_dir(dir_name)
chmod(dir_mode, dir_name)
end
Given /^a file named "([^"]*)" with:$/ do |file_name, file_content|
write_file(file_name, file_content)
end
Given /^a file named "([^"]*)" with mode "([^"]*)" and with:$/ do |file_name, file_mode, file_content|
write_file(file_name, file_content)
chmod(file_mode, file_name)
end
Given /^a (\d+) byte file named "([^"]*)"$/ do |file_size, file_name|
write_fixed_size_file(file_name, file_size.to_i)
end
Given /^an empty file named "([^"]*)"$/ do |file_name|
write_file(file_name, "")
end
Given /^an empty file named "([^"]*)" with mode "([^"]*)"$/ do |file_name, file_mode|
write_file(file_name, "")
chmod(file_mode, file_name)
end
When /^I write to "([^"]*)" with:$/ do |file_name, file_content|
write_file(file_name, file_content)
end
When /^I overwrite "([^"]*)" with:$/ do |file_name, file_content|
overwrite_file(file_name, file_content)
end
When /^I append to "([^"]*)" with:$/ do |file_name, file_content|
append_to_file(file_name, file_content)
end
When /^I append to "([^"]*)" with "([^"]*)"$/ do |file_name, file_content|
append_to_file(file_name, file_content)
end
When /^I remove the file "([^"]*)"$/ do |file_name|
remove_file(file_name)
end
When /^I cd to "([^"]*)"$/ do |dir|
cd(dir)
end
Given /^I set the environment variables to:/ do |table|
table.hashes.each do |row|
variable = row['variable'].to_s.upcase
value = row['value'].to_s
set_env(variable, value)
end
end
When /^I run "(.*)"$/ do |cmd|
warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
run_simple(unescape(cmd), false)
end
When /^I run `([^`]*)`$/ do |cmd|
run_simple(unescape(cmd), false)
end
When /^I successfully run "(.*)"$/ do |cmd|
warn(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
run_simple(unescape(cmd))
end
## I successfully run `echo -n "Hello"`
## I successfully run `sleep 29` for up to 30 seconds
When /^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/ do |cmd, secs|
run_simple(unescape(cmd), true, secs && secs.to_i)
end
When /^I run "([^"]*)" interactively$/ do |cmd|
warn(%{\e[35m The /^I run "([^"]*)" interactively$/ step definition is deprecated. Please use the `backticks` version\e[0m})
run_interactive(unescape(cmd))
end
When /^I run `([^`]*)` interactively$/ do |cmd|
run_interactive(unescape(cmd))
end
When /^I type "([^"]*)"$/ do |input|
type(input)
end
When /^I close the stdin stream$/ do
close_input
end
When /^I pipe in the file "([^"]*)"$/ do |file|
pipe_in_file(file)
close_input
end
When /^I wait for (?:output|stdout) to contain "([^"]*)"$/ do |expected|
Timeout::timeout(exit_timeout) do
loop do
break if assert_partial_output_interactive(expected)
sleep 0.1
end
end
end
Then /^the output should contain "([^"]*)"$/ do |expected|
assert_partial_output(expected, all_output)
end
Then /^the output from "([^"]*)" should contain "([^"]*)"$/ do |cmd, expected|
assert_partial_output(expected, output_from(cmd))
end
Then /^the output from "([^"]*)" should not contain "([^"]*)"$/ do |cmd, unexpected|
assert_no_partial_output(unexpected, output_from(cmd))
end
Then /^the output should not contain "([^"]*)"$/ do |unexpected|
assert_no_partial_output(unexpected, all_output)
end
Then /^the output should contain:$/ do |expected|
assert_partial_output(expected, all_output)
end
Then /^the output should not contain:$/ do |unexpected|
assert_no_partial_output(unexpected, all_output)
end
## the output should contain exactly "output"
## the output from `echo -n "Hello"` should contain exactly "Hello"
Then /^the output(?: from "(.*?)")? should contain exactly "(.*?)"$/ do |cmd, expected|
assert_exact_output(expected, cmd ? output_from(cmd) : all_output)
end
## the output should contain exactly:
## the output from `echo -n "Hello"` should contain exactly:
Then /^the output(?: from "(.*?)")? should contain exactly:$/ do |cmd, expected|
assert_exact_output(expected, cmd ? output_from(cmd) : all_output)
end
# "the output should match" allows regex in the partial_output, if
# you don't need regex, use "the output should contain" instead since
# that way, you don't have to escape regex characters that
# appear naturally in the output
Then /^the output should match \/([^\/]*)\/$/ do |expected|
assert_matching_output(expected, all_output)
end
Then /^the output should match:$/ do |expected|
assert_matching_output(expected, all_output)
end
# The previous two steps antagonists
Then /^the output should not match \/([^\/]*)\/$/ do |expected|
assert_not_matching_output(expected, all_output)
end
Then /^the output should not match:$/ do |expected|
assert_not_matching_output(expected, all_output)
end
Then /^the exit status should be (\d+)$/ do |exit_status|
assert_exit_status(exit_status.to_i)
end
Then /^the exit status should not be (\d+)$/ do |exit_status|
assert_not_exit_status(exit_status.to_i)
end
Then /^it should (pass|fail) with:$/ do |pass_fail, partial_output|
self.__send__("assert_#{pass_fail}ing_with", partial_output)
end
Then /^it should (pass|fail) with exactly:$/ do |pass_fail, exact_output|
assert_exit_status_and_output(pass_fail == "pass", exact_output, true)
end
Then /^it should (pass|fail) with regexp?:$/ do |pass_fail, expected|
assert_matching_output(expected, all_output)
assert_success(pass_fail == 'pass')
end
## the stderr should contain "hello"
## the stderr from "echo -n 'Hello'" should contain "hello"
## the stderr should contain exactly:
## the stderr from "echo -n 'Hello'" should contain exactly:
Then /^the stderr(?: from "(.*?)")? should contain( exactly)? "(.*?)"$/ do |cmd, exact, expected|
if exact
assert_exact_output(expected, cmd ? stderr_from(cmd) : all_stderr)
else
assert_partial_output(expected, cmd ? stderr_from(cmd) : all_stderr)
end
end
## the stderr should contain:
## the stderr from "echo -n 'Hello'" should contain:
## the stderr should contain exactly:
## the stderr from "echo -n 'Hello'" should contain exactly:
Then /^the stderr(?: from "(.*?)")? should contain( exactly)?:$/ do |cmd, exact, expected|
if exact
assert_exact_output(expected, cmd ? stderr_from(cmd) : all_stderr)
else
assert_partial_output(expected, cmd ? stderr_from(cmd) : all_stderr)
end
end
## the stdout should contain "hello"
## the stdout from "echo -n 'Hello'" should contain "hello"
## the stdout should contain exactly:
## the stdout from "echo -n 'Hello'" should contain exactly:
Then /^the stdout(?: from "(.*?)")? should contain( exactly)? "(.*?)"$/ do |cmd, exact, expected|
if exact
assert_exact_output(expected, cmd ? stdout_from(cmd) : all_stdout)
else
assert_partial_output(expected, cmd ? stdout_from(cmd) : all_stdout)
end
end
## the stdout should contain:
## the stdout from "echo -n 'Hello'" should contain:
## the stdout should contain exactly:
## the stdout from "echo -n 'Hello'" should contain exactly:
Then /^the stdout(?: from "(.*?)")? should contain( exactly)?:$/ do |cmd, exact, expected|
if exact
assert_exact_output(expected, cmd ? stdout_from(cmd) : all_stdout)
else
assert_partial_output(expected, cmd ? stdout_from(cmd) : all_stdout)
end
end
Then /^the stderr should not contain "([^"]*)"$/ do |unexpected|
assert_no_partial_output(unexpected, all_stderr)
end
Then /^the stderr should not contain:$/ do |unexpected|
assert_no_partial_output(unexpected, all_stderr)
end
Then /^the (stderr|stdout) should not contain anything$/ do |stream_name|
stream = self.send("all_#{stream_name}")
stream.should be_empty
end
Then /^the stdout should not contain "([^"]*)"$/ do |unexpected|
assert_no_partial_output(unexpected, all_stdout)
end
Then /^the stdout should not contain:$/ do |unexpected|
assert_no_partial_output(unexpected, all_stdout)
end
Then /^the stdout from "([^"]*)" should not contain "([^"]*)"$/ do |cmd, unexpected|
assert_no_partial_output(unexpected, stdout_from(cmd))
end
Then /^the stderr from "([^"]*)" should not contain "([^"]*)"$/ do |cmd, unexpected|
assert_no_partial_output(unexpected, stderr_from(cmd))
end
Then /^the file "([^"]*)" should not exist$/ do |file_name|
check_file_presence([file_name], false)
end
Then /^the following files should exist:$/ do |files|
check_file_presence(files.raw.map{|file_row| file_row[0]}, true)
end
Then /^the following files should not exist:$/ do |files|
check_file_presence(files.raw.map{|file_row| file_row[0]}, false)
end
Then /^a file named "([^"]*)" should exist$/ do |file|
check_file_presence([file], true)
end
Then /^a file named "([^"]*)" should not exist$/ do |file|
check_file_presence([file], false)
end
Then /^a file matching %r<(.*?)> should exist$/ do |regex|
check_file_presence([ Regexp.new( regex ) ], true )
end
Then /^a file matching %r<(.*?)> should not exist$/ do |regex|
check_file_presence([ Regexp.new( regex ) ], false )
end
Then /^a (\d+) byte file named "([^"]*)" should exist$/ do |file_size, file_name|
check_file_size([[file_name, file_size.to_i]])
end
Then /^the following directories should exist:$/ do |directories|
check_directory_presence(directories.raw.map{|directory_row| directory_row[0]}, true)
end
Then /^the following directories should not exist:$/ do |directories|
check_directory_presence(directories.raw.map{|directory_row| directory_row[0]}, false)
end
Then /^a directory named "([^"]*)" should exist$/ do |directory|
check_directory_presence([directory], true)
end
Then /^a directory named "([^"]*)" should not exist$/ do |directory|
check_directory_presence([directory], false)
end
Then /^the file "([^"]*)" should contain "([^"]*)"$/ do |file, partial_content|
check_file_content(file, partial_content, true)
end
Then /^the file "([^"]*)" should not contain "([^"]*)"$/ do |file, partial_content|
check_file_content(file, partial_content, false)
end
Then /^the file "([^"]*)" should contain:$/ do |file, partial_content|
check_file_content(file, partial_content, true)
end
Then /^the file "([^"]*)" should contain exactly:$/ do |file, exact_content|
check_exact_file_content(file, exact_content)
end
Then /^the file "([^"]*)" should match \/([^\/]*)\/$/ do |file, partial_content|
check_file_content(file, /#{partial_content}/, true)
end
Then /^the file "([^"]*)" should not match \/([^\/]*)\/$/ do |file, partial_content|
check_file_content(file, /#{partial_content}/, false)
end
Then /^the mode of filesystem object "([^"]*)" should match "([^"]*)"$/ do |name, mode|
mod?(mode, name)
end