aruba 0.9.0 → 0.10.0.pre

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -0
  3. data/Gemfile +2 -0
  4. data/History.md +23 -1
  5. data/README.md +2 -2
  6. data/aruba.gemspec +1 -1
  7. data/cucumber.yml +4 -0
  8. data/features/api/command/run.feature +18 -0
  9. data/features/api/environment/remove_environment_variable.feature +63 -0
  10. data/features/api/environment/set_environment_variable.feature +47 -10
  11. data/features/api/{command → text}/extract_text.feature +4 -24
  12. data/features/api/text/sanitize_text.feature +228 -0
  13. data/features/api/{command → text}/unescape_text.feature +9 -13
  14. data/features/cli/init.feature +79 -0
  15. data/features/commands/output/all_output.feature +1 -0
  16. data/features/getting_started/supported_testing_frameworks.feature +104 -0
  17. data/features/output.feature +3 -2
  18. data/features/step_definitions/aruba_dev_steps.rb +1 -60
  19. data/features/step_definitions/hooks.rb +6 -0
  20. data/fixtures/empty-app/README.md +1 -11
  21. data/lib/aruba/api.rb +2 -0
  22. data/lib/aruba/api/command.rb +0 -19
  23. data/lib/aruba/api/deprecated.rb +6 -3
  24. data/lib/aruba/api/environment.rb +18 -0
  25. data/lib/aruba/api/filesystem.rb +1 -1
  26. data/lib/aruba/api/text.rb +41 -0
  27. data/lib/aruba/cli.rb +11 -0
  28. data/lib/aruba/console.rb +3 -2
  29. data/lib/aruba/cucumber.rb +1 -0
  30. data/lib/aruba/cucumber/command.rb +44 -88
  31. data/lib/aruba/cucumber/environment.rb +7 -3
  32. data/lib/aruba/cucumber/file.rb +14 -17
  33. data/lib/aruba/cucumber/hooks.rb +1 -0
  34. data/lib/aruba/cucumber/testing_frameworks.rb +95 -0
  35. data/lib/aruba/initializer.rb +185 -0
  36. data/lib/aruba/matchers/collection/all.rb +9 -0
  37. data/lib/aruba/matchers/command/have_output.rb +1 -2
  38. data/lib/aruba/matchers/command/have_output_on_stderr.rb +1 -2
  39. data/lib/aruba/matchers/command/have_output_on_stdout.rb +1 -2
  40. data/lib/aruba/matchers/string.rb +1 -0
  41. data/lib/aruba/matchers/string/include_output_string.rb +36 -0
  42. data/lib/aruba/matchers/string/match_output_string.rb +37 -0
  43. data/lib/aruba/matchers/string/output_string_eq.rb +35 -0
  44. data/lib/aruba/platforms/local_environment.rb +2 -0
  45. data/lib/aruba/platforms/unix_environment_variables.rb +10 -0
  46. data/lib/aruba/platforms/unix_platform.rb +3 -1
  47. data/lib/aruba/platforms/windows_environment_variables.rb +4 -0
  48. data/lib/aruba/processes/spawn_process.rb +6 -2
  49. data/lib/aruba/version.rb +1 -1
  50. metadata +28 -16
  51. data/fixtures/empty-app/bin/cli +0 -6
  52. data/fixtures/empty-app/script/console +0 -14
  53. data/fixtures/empty-app/spec/spec_helper.rb +0 -9
  54. data/lib/aruba/matchers/collection/all_objects.rb +0 -2
@@ -58,6 +58,24 @@ module Aruba
58
58
 
59
59
  self
60
60
  end
61
+
62
+ # Remove existing environment variable
63
+ #
64
+ # @param [String] key
65
+ # The name of the environment variable as string, e.g. 'HOME'
66
+ #
67
+ # @param [String] value
68
+ # The value of the environment variable. Needs to be a string.
69
+ def delete_environment_variable(name)
70
+ name = name.to_s
71
+
72
+ announcer.announce(:environment, name, '')
73
+ announcer.announce(:modified_environment, name, '')
74
+
75
+ aruba.environment.delete name
76
+
77
+ self
78
+ end
61
79
  end
62
80
  end
63
81
  end
@@ -360,7 +360,7 @@ module Aruba
360
360
  # @result [FileSize]
361
361
  # Bytes on disk
362
362
  def disk_usage(*paths)
363
- expect(paths.flatten).to all_objects be_an_existing_path
363
+ expect(paths.flatten).to Aruba::Matchers.all be_an_existing_path
364
364
 
365
365
  Aruba.platform.determine_disk_usage paths.flatten.map { |p| ArubaPath.new(expand_path(p)) }, aruba.config.physical_block_size
366
366
  end
@@ -0,0 +1,41 @@
1
+ module Aruba
2
+ module Api
3
+ module Text
4
+ # Unescape text
5
+ #
6
+ # '\n' => "\n"
7
+ # '\e' => "\e"
8
+ # '\033' => "\e"
9
+ # '\"' => '"'
10
+ #
11
+ # @param [#to_s] text
12
+ # Input
13
+ def unescape_text(text)
14
+ text.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e").gsub('\033', "\e").gsub('\016', "\016").gsub('\017', "\017").gsub('\t', "\t")
15
+ end
16
+
17
+ # Remove ansi characters from text
18
+ #
19
+ # @param [#to_s] text
20
+ # Input
21
+ def extract_text(text)
22
+ if Aruba::VERSION < '1'
23
+ text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '')
24
+ else
25
+ text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '').gsub(/\\\[|\\\]/, '').gsub(/\007|\016|\017/, '')
26
+ end
27
+ end
28
+
29
+ # Unescape special characters and remove ANSI characters
30
+ #
31
+ # @param [#to_s] text
32
+ # The text to sanitize
33
+ def sanitize_text(text)
34
+ text = unescape_text(text)
35
+ text = extract_text(text) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
36
+
37
+ text.chomp
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/aruba/cli.rb CHANGED
@@ -1,11 +1,22 @@
1
1
  require 'thor'
2
2
  require 'aruba/console'
3
+ require 'aruba/initializer'
3
4
 
4
5
  module Aruba
5
6
  class Cli < Thor
7
+ def self.exit_on_failure?
8
+ true
9
+ end
10
+
6
11
  desc 'console', "Start aruba's console"
7
12
  def console
8
13
  Aruba::Console.new.start
9
14
  end
15
+
16
+ desc 'init', 'Initialize aruba'
17
+ option :test_framework, :default => 'cucumber', :enum => %w(cucumber rspec minitest), :desc => 'Choose which test framework to use'
18
+ def init
19
+ Aruba::Initializer.new.call(options[:test_framework])
20
+ end
10
21
  end
11
22
  end
data/lib/aruba/console.rb CHANGED
@@ -12,8 +12,9 @@ module Aruba
12
12
  ARGV.clear
13
13
  IRB.setup nil
14
14
 
15
- IRB.conf[:PROMPT] = {}
16
15
  IRB.conf[:IRB_NAME] = 'aruba'
16
+
17
+ IRB.conf[:PROMPT] = {}
17
18
  IRB.conf[:PROMPT][:ARUBA] = {
18
19
  :PROMPT_I => '%N:%03n:%i> ',
19
20
  :PROMPT_N => '%N:%03n:%i> ',
@@ -50,7 +51,7 @@ module Aruba
50
51
  IRB.conf[:MAIN_CONTEXT] = irb.context
51
52
 
52
53
  trap("SIGINT") do
53
- IRB.irb.signal_handle
54
+ irb.signal_handle
54
55
  end
55
56
 
56
57
  begin
@@ -8,5 +8,6 @@ require 'aruba/cucumber/command'
8
8
  require 'aruba/cucumber/core'
9
9
  require 'aruba/cucumber/environment'
10
10
  require 'aruba/cucumber/file'
11
+ require 'aruba/cucumber/testing_frameworks'
11
12
  require 'aruba/cucumber/rvm'
12
13
  require 'aruba/reporting'
@@ -1,34 +1,26 @@
1
1
  When(/^I run "(.*)"$/)do |cmd|
2
2
  warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
3
3
 
4
- cmd = unescape_text(cmd)
5
- cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
6
-
4
+ cmd = sanitize_text(cmd)
7
5
  run_simple(cmd, false)
8
6
  end
9
7
 
10
8
  When(/^I run `([^`]*)`$/)do |cmd|
11
- cmd = unescape_text(cmd)
12
- cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
13
-
9
+ cmd = sanitize_text(cmd)
14
10
  run_simple(cmd, false)
15
11
  end
16
12
 
17
13
  When(/^I successfully run "(.*)"$/)do |cmd|
18
14
  warn(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
19
15
 
20
- cmd = unescape_text(cmd)
21
- cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
22
-
16
+ cmd = sanitize_text(cmd)
23
17
  run_simple(cmd)
24
18
  end
25
19
 
26
20
  ## I successfully run `echo -n "Hello"`
27
21
  ## I successfully run `sleep 29` for up to 30 seconds
28
22
  When(/^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/)do |cmd, secs|
29
- cmd = unescape_text(cmd)
30
- cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
31
-
23
+ cmd = sanitize_text(cmd)
32
24
  run_simple(cmd, true, secs && secs.to_i)
33
25
  end
34
26
 
@@ -39,9 +31,7 @@ When(/^I run "([^"]*)" interactively$/) do |cmd|
39
31
  end
40
32
 
41
33
  When(/^I run `([^`]*)` interactively$/)do |cmd|
42
- cmd = unescape_text(cmd)
43
- cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
44
-
34
+ cmd = sanitize_text(cmd)
45
35
  @interactive = run(cmd)
46
36
  end
47
37
 
@@ -71,11 +61,8 @@ When(/^I stop the command(?: started last)? if (output|stdout|stderr) contains:$
71
61
  last_command_started.public_send channel.to_sym, :wait_for_io => 0
72
62
  end
73
63
 
74
- output = unescape_text(output)
75
- output = extract_text(output) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
76
-
77
- expected = unescape_text(expected)
78
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
64
+ output = sanitize_text(output)
65
+ expected = sanitize_text(expected)
79
66
 
80
67
  if output.include? expected
81
68
  last_command_started.terminate
@@ -98,10 +85,7 @@ When(/^I wait for (?:output|stdout) to contain:$/) do |expected|
98
85
  Timeout.timeout(exit_timeout) do
99
86
  loop do
100
87
  begin
101
- expected = unescape_text(expected)
102
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
103
-
104
- expect(last_command_started).to have_output Regexp.new(expected)
88
+ expect(last_command_started).to have_output an_output_string_including(expected)
105
89
  rescue ExpectationError
106
90
  sleep 0.1
107
91
  retry
@@ -116,10 +100,7 @@ When(/^I wait for (?:output|stdout) to contain "([^"]*)"$/) do |expected|
116
100
  Timeout.timeout(exit_timeout) do
117
101
  loop do
118
102
  begin
119
- expected = unescape_text(expected)
120
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
121
-
122
- expect(last_command_started).to have_output Regexp.new(expected)
103
+ expect(last_command_started).to have_output an_output_string_including(expected)
123
104
  rescue ExpectationError
124
105
  sleep 0.1
125
106
  retry
@@ -150,14 +131,11 @@ Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain
150
131
  all_commands
151
132
  end
152
133
 
153
- expected = unescape_text(expected).chomp
154
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
155
-
156
- expected = if exactly
157
- expected
158
- else
159
- Regexp.new(Regexp.escape(expected))
160
- end
134
+ output_string_matcher = if exactly
135
+ :an_output_string_being_eq
136
+ else
137
+ :an_output_string_including
138
+ end
161
139
 
162
140
  if Aruba::VERSION < '1.0'
163
141
  combined_output = commands.map do |c|
@@ -166,15 +144,15 @@ Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain
166
144
  end.join("\n")
167
145
 
168
146
  if negated
169
- expect(combined_output).not_to match expected
147
+ expect(combined_output).not_to send(output_string_matcher, expected)
170
148
  else
171
- expect(combined_output).to match expected
149
+ expect(combined_output).to send(output_string_matcher, expected)
172
150
  end
173
151
  else
174
152
  if negated
175
- expect(commands).not_to include_an_object send(matcher, expected)
153
+ expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected))
176
154
  else
177
- expect(commands).to include_an_object send(matcher, expected)
155
+ expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected))
178
156
  end
179
157
  end
180
158
  end
@@ -201,14 +179,11 @@ Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain
201
179
  all_commands
202
180
  end
203
181
 
204
- expected = unescape_text(expected).chomp
205
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
206
-
207
- expected = if exactly
208
- expected
209
- else
210
- Regexp.new(Regexp.escape(expected))
211
- end
182
+ output_string_matcher = if exactly
183
+ :an_output_string_being_eq
184
+ else
185
+ :an_output_string_including
186
+ end
212
187
 
213
188
  if Aruba::VERSION < '1.0'
214
189
  combined_output = commands.map do |c|
@@ -217,15 +192,15 @@ Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain
217
192
  end.join("\n")
218
193
 
219
194
  if negated
220
- expect(combined_output).not_to match expected
195
+ expect(combined_output).not_to send(output_string_matcher, expected)
221
196
  else
222
- expect(combined_output).to match expected
197
+ expect(combined_output).to send(output_string_matcher, expected)
223
198
  end
224
199
  else
225
200
  if negated
226
- expect(commands).not_to include_an_object send(matcher, expected)
201
+ expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected))
227
202
  else
228
- expect(commands).to include_an_object send(matcher, expected)
203
+ expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected))
229
204
  end
230
205
  end
231
206
  end
@@ -236,25 +211,25 @@ end
236
211
  # appear naturally in the output
237
212
  Then(/^the output should( not)? match \/([^\/]*)\/$/) do |negated, expected|
238
213
  if negated
239
- expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE)
214
+ expect(all_commands).not_to include_an_object have_output an_output_string_matching(expected)
240
215
  else
241
- expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE)
216
+ expect(all_commands).to include_an_object have_output an_output_string_matching(expected)
242
217
  end
243
218
  end
244
219
 
245
220
  Then(/^the output should( not)? match %r<([^>]*)>$/) do |negated, expected|
246
221
  if negated
247
- expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE)
222
+ expect(all_commands).not_to include_an_object have_output an_output_string_matching(expected)
248
223
  else
249
- expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE)
224
+ expect(all_commands).to include_an_object have_output an_output_string_matching(expected)
250
225
  end
251
226
  end
252
227
 
253
228
  Then(/^the output should( not)? match:$/) do |negated, expected|
254
229
  if negated
255
- expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE)
230
+ expect(all_commands).not_to include_an_object have_output an_output_string_matching(expected)
256
231
  else
257
- expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE)
232
+ expect(all_commands).to include_an_object have_output an_output_string_matching(expected)
258
233
  end
259
234
  end
260
235
 
@@ -267,10 +242,6 @@ Then(/^the exit status should( not)? be (\d+)$/) do |negated, exit_status|
267
242
  end
268
243
 
269
244
  Then(/^it should( not)? (pass|fail) with "(.*?)"$/) do |negated, pass_fail, expected|
270
- expected = unescape_text(expected).chomp
271
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
272
- expected = Regexp.new(Regexp.escape(expected))
273
-
274
245
  if pass_fail == 'pass'
275
246
  expect(last_command_stopped).to be_successfully_executed
276
247
  else
@@ -278,17 +249,13 @@ Then(/^it should( not)? (pass|fail) with "(.*?)"$/) do |negated, pass_fail, expe
278
249
  end
279
250
 
280
251
  if negated
281
- expect(last_command_stopped).not_to have_output expected
252
+ expect(last_command_stopped).not_to have_output an_output_string_including(expected)
282
253
  else
283
- expect(last_command_stopped).to have_output expected
254
+ expect(last_command_stopped).to have_output an_output_string_including(expected)
284
255
  end
285
256
  end
286
257
 
287
258
  Then(/^it should( not)? (pass|fail) with:$/) do |negated, pass_fail, expected|
288
- expected = unescape_text(expected).chomp
289
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
290
- expected = Regexp.new(Regexp.escape(expected))
291
-
292
259
  if pass_fail == 'pass'
293
260
  expect(last_command_stopped).to be_successfully_executed
294
261
  else
@@ -296,16 +263,13 @@ Then(/^it should( not)? (pass|fail) with:$/) do |negated, pass_fail, expected|
296
263
  end
297
264
 
298
265
  if negated
299
- expect(last_command_stopped).not_to have_output expected
266
+ expect(last_command_stopped).not_to have_output an_output_string_including(expected)
300
267
  else
301
- expect(last_command_stopped).to have_output expected
268
+ expect(last_command_stopped).to have_output an_output_string_including(expected)
302
269
  end
303
270
  end
304
271
 
305
272
  Then(/^it should( not)? (pass|fail) with exactly:$/) do |negated, pass_fail, expected|
306
- expected = unescape_text(expected).chomp
307
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
308
-
309
273
  if pass_fail == 'pass'
310
274
  expect(last_command_stopped).to be_successfully_executed
311
275
  else
@@ -313,17 +277,13 @@ Then(/^it should( not)? (pass|fail) with exactly:$/) do |negated, pass_fail, exp
313
277
  end
314
278
 
315
279
  if negated
316
- expect(last_command_stopped).not_to have_output expected
280
+ expect(last_command_stopped).not_to have_output an_output_string_eq(expected)
317
281
  else
318
- expect(last_command_stopped).to have_output expected
282
+ expect(last_command_stopped).to have_output an_output_string_being_eq(expected)
319
283
  end
320
284
  end
321
285
 
322
- Then(/^it should( not)? (pass|fail) with regexp?:$/) do |negated, pass_fail, expected|
323
- expected = unescape_text(expected).chomp
324
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
325
- expected = Regexp.new(expected, Regexp::MULTILINE)
326
-
286
+ Then(/^it should( not)? (pass|fail) (?:with regexp?|matching):$/) do |negated, pass_fail, expected|
327
287
  if pass_fail == 'pass'
328
288
  expect(last_command_stopped).to be_successfully_executed
329
289
  else
@@ -331,9 +291,9 @@ Then(/^it should( not)? (pass|fail) with regexp?:$/) do |negated, pass_fail, exp
331
291
  end
332
292
 
333
293
  if negated
334
- expect(last_command_stopped).not_to have_output expected
294
+ expect(last_command_stopped).not_to have_output an_output_string_matching(expected)
335
295
  else
336
- expect(last_command_stopped).to have_output expected
296
+ expect(last_command_stopped).to have_output an_output_string_matching(expected)
337
297
  end
338
298
  end
339
299
 
@@ -354,10 +314,6 @@ end
354
314
 
355
315
  Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:$/) do |channel, negated, table|
356
316
  table.raw.flatten.each do |expected|
357
- expected = unescape_text(expected).chomp
358
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
359
- expected = Regexp.new(Regexp.escape(expected))
360
-
361
317
  matcher = case channel.to_sym
362
318
  when :output
363
319
  :have_output
@@ -370,9 +326,9 @@ Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:
370
326
  end
371
327
 
372
328
  if negated
373
- expect(all_commands).not_to include_an_object send(matcher, expected)
329
+ expect(all_commands).not_to include_an_object have_output an_output_string_including(expected)
374
330
  else
375
- expect(all_commands).to include_an_object send(matcher, expected)
331
+ expect(all_commands).to include_an_object have_output an_output_string_including(expected)
376
332
  end
377
333
  end
378
334
  end
@@ -2,9 +2,13 @@ Given(/^a mocked home directory$/)do
2
2
  set_environment_variable 'HOME', expand_path('.')
3
3
  end
4
4
 
5
+ Given(/^I set the environment variable "(.*)" to "(.*)"/) do |variable, value|
6
+ set_environment_variable(variable.to_s, value.to_s)
7
+ end
8
+
5
9
  Given(/^I set the environment variables? to:/) do |table|
6
10
  table.hashes.each do |row|
7
- variable = row['variable'].to_s.upcase
11
+ variable = row['variable'].to_s
8
12
  value = row['value'].to_s
9
13
 
10
14
  set_environment_variable(variable, value)
@@ -13,7 +17,7 @@ end
13
17
 
14
18
  Given(/^I append the values? to the environment variables?:/) do |table|
15
19
  table.hashes.each do |row|
16
- variable = row['variable'].to_s.upcase
20
+ variable = row['variable'].to_s
17
21
  value = row['value'].to_s
18
22
 
19
23
  append_environment_variable(variable, value)
@@ -22,7 +26,7 @@ end
22
26
 
23
27
  Given(/^I prepend the values? to the environment variables?:/) do |table|
24
28
  table.hashes.each do |row|
25
- variable = row['variable'].to_s.upcase
29
+ variable = row['variable'].to_s
26
30
  value = row['value'].to_s
27
31
 
28
32
  prepend_environment_variable(variable, value)