aruba-jbb 0.2.6.7 → 0.2.6.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.2.6.8 jbb
2
+ * added some api method documentation
3
+
1
4
  == 0.2.6.7 msassak
2
5
 
3
6
  === Bug fixes
data/aruba-jbb.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{aruba-jbb}
5
- s.version = "0.2.6.7"
5
+ s.version = "0.2.6.8"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aslak Hellesøy", "David Chelimsky", "James B. Byrne", "Mike Sassak"]
data/lib/aruba/api.rb CHANGED
@@ -5,6 +5,9 @@ require 'background_process'
5
5
  module Aruba
6
6
  module Api
7
7
 
8
+ # announce_or_puts(msg) is an internal helper method for
9
+ # reproduccing test process output in the Aruba run.
10
+ #
8
11
  def announce_or_puts(msg)
9
12
  if(@puts)
10
13
  puts(msg)
@@ -13,19 +16,35 @@ module Aruba
13
16
  end
14
17
  end
15
18
 
16
-
19
+ # append_to_file is used to add data to the end of a
20
+ # file in a step definition. The data is of course
21
+ # a string obtained from the feature. A typical invocation
22
+ # looks like:
23
+ #
24
+ # Given I do have a file named "foo/bar/example.rb" with:
25
+ # """
26
+ # puts "hello world"
27
+ # """
28
+ #
17
29
  def append_to_file(file_name, file_content)
18
30
  in_current_dir do
19
31
  File.open(file_name, 'a') { |f| f << file_content }
20
32
  end
21
33
  end
22
34
 
35
+ # aruba_working_dir simple returns the value of the current
36
+ # directory that aruba is running its features in. This is
37
+ # set using the aruba_working_dir_set method from within the
38
+ # step definitions or through the environment variable
39
+ # ARUBA_WORKING_DIR
40
+ #
23
41
  def aruba_working_dir
24
42
  @aruba_working_dir
25
43
  end
26
44
 
27
- # This allows before hooks to set aruba's working directory
28
- # relative to user's cwd
45
+ # aruba_working_dir_set allows before hooks to set aruba's
46
+ # working directory relative to user's cwd.
47
+ #
29
48
  def aruba_working_dir_set(dir)
30
49
  @aruba_working_dir = dir
31
50
  dirs_init
@@ -33,8 +52,17 @@ module Aruba
33
52
 
34
53
  # You can override the default working directory by setting
35
54
  # the environment variable ARUBA_WORKING_DIR
55
+ #
36
56
  ARUBA_WORKING_DIR_DEFAULT = 'tmp/aruba'
37
57
 
58
+ # aruba_working_dir_init initializes the aruba_working_dir to
59
+ # either the default value specified in ARUBA_WORKING_DIR_DEFAULT
60
+ # or the value of the the environment variable ARUBA_WORKING_DIR
61
+ # if present.
62
+ #
63
+ # This method also rebases the list of comma delimited directories
64
+ # contained in the ARUBA_REBASE environmental variable, if found.
65
+ #
38
66
  def aruba_working_dir_init
39
67
 
40
68
  @aruba_working_dir = [ARUBA_WORKING_DIR_DEFAULT]
@@ -52,7 +80,9 @@ module Aruba
52
80
  end
53
81
  end
54
82
 
55
-
83
+ # assert_exit_status_and_partial_output(pass_or_fail, output) is an
84
+ # internal helper method not really should not be used in a step definition.
85
+ #
56
86
  def assert_exit_status_and_partial_output(expect_to_pass, partial_output)
57
87
  assert_partial_output(partial_output)
58
88
  if expect_to_pass
@@ -62,29 +92,48 @@ module Aruba
62
92
  end
63
93
  end
64
94
 
65
-
95
+ # assert_failing_with(output) uses assert_exit_status_and_partial_output.
96
+ # It passes the exit status expectation as false (fail) and the text
97
+ # expected in the output to that method.
98
+ #
66
99
  def assert_failing_with(partial_output)
67
100
  assert_exit_status_and_partial_output(false, partial_output)
68
101
  end
69
102
 
70
-
103
+ # assert_partial_output(partial_output)
71
104
  def assert_partial_output(partial_output)
72
105
  combined_output.should =~ regexp(partial_output)
73
106
  end
74
107
 
75
-
108
+ # assert_passing_with(output) uses assert_exit_status_and_partial_output.
109
+ # It passes the exit status expectation as true (pass) and the text
110
+ # expected in the output to that method.
111
+ #
76
112
  def assert_passing_with(partial_output)
77
113
  assert_exit_status_and_partial_output(true, partial_output)
78
114
  end
79
115
 
80
-
116
+ # cd(path) changes aruba's working directory (awd) to path.
117
+ #
118
+ # Usage:
119
+ # When I cd to "foo/nonexistant" step"
120
+ #
81
121
  def cd(dir)
82
122
  dirs << dir
83
123
  raise "#{current_dir} is not a directory." \
84
124
  unless File.directory?(current_dir)
85
125
  end
86
126
 
87
-
127
+ # check_directory_presence(paths, expect_presence) operates on
128
+ # an enumable collection of paths and determines if each exits
129
+ # passes if they do when expect_presence = true and
130
+ # passes if they do not when expect_presence = false.
131
+ #
132
+ # Usage:
133
+ # Then the following directories should exist:
134
+ # | foo/bar |
135
+ # | foo/bla |
136
+ #
88
137
  def check_directory_presence(paths, expect_presence)
89
138
  in_current_dir do
90
139
  paths.each do |path|
@@ -97,14 +146,28 @@ module Aruba
97
146
  end
98
147
  end
99
148
 
100
-
149
+ # check_exact_file_content(file, exact_content) veries that
150
+ # the specified file contains exactly the provided text.
151
+ #
152
+ # Usage:
153
+ # Then the file "foo" should contain exactly:
154
+ # """
155
+ # My file should have this.
156
+ # And this
157
+ # """
158
+ #
101
159
  def check_exact_file_content(file, exact_content)
102
160
  in_current_dir do
103
161
  IO.read(file).should == exact_content
104
162
  end
105
163
  end
106
164
 
107
-
165
+ # check_file_content(file, partial_content, expect_match) veries that
166
+ # the specified file contains at least the provided text.
167
+ #
168
+ # Usage:
169
+ # Then I do have the file named "foo" with "blah"
170
+ #
108
171
  def check_file_content(file, partial_content, expect_match)
109
172
  regexp = regexp(partial_content)
110
173
  in_current_dir do
@@ -117,7 +180,11 @@ module Aruba
117
180
  end
118
181
  end
119
182
 
120
-
183
+ # check_file_presence(paths, expect_presence) operates on files in
184
+ # a fashion similare to check_directory_presence. it enumerates
185
+ # of a collection fo file names and passes or fails on the
186
+ # existance of each according to the expect_presence setting.
187
+ #
121
188
  def check_file_presence(paths, expect_presence)
122
189
  in_current_dir do
123
190
  paths.each do |path|
@@ -129,8 +196,14 @@ module Aruba
129
196
  end
130
197
  end
131
198
  end
132
-
133
-
199
+
200
+ # clean_up(dir = current_dir) is an internal helper method that empties
201
+ # the current working directory of all content. It is used in the
202
+ # Aruba before hook to clear out the awd at the start of each scenario.
203
+ #
204
+ # It will not clear any directory that does not contain the directory
205
+ # <tt>/tmp/</tt> somewhare in its path.
206
+ #
134
207
  def clean_up(dir = current_dir)
135
208
  check_tmp_dir = File.expand_path(dir)
136
209
  if File.fnmatch('**/tmp/**',check_tmp_dir)
@@ -141,13 +214,17 @@ module Aruba
141
214
  end
142
215
  end
143
216
 
144
-
217
+ # clean_up!(dir = current_dir). Internal helper method. Does not check
218
+ # for tmp directory path.
219
+ #
145
220
  def clean_up!(dir = current_dir)
146
221
  FileUtils.rm_rf(dir)
147
222
  _mkdir(dir)
148
223
  end
149
224
 
150
-
225
+ # combined_output is an internal helper methiod that concatenates the
226
+ # contents of $stdout with $stderr.
227
+ #
151
228
  def combined_output
152
229
  if @interactive
153
230
  interactive_output
@@ -156,14 +233,29 @@ module Aruba
156
233
  end
157
234
  end
158
235
 
159
-
236
+ # create_dir(dir_name) creates the given directory name within the awd
237
+ # subject to normal filesystem restrictions.
238
+ #
239
+ # `Usage:
240
+ # Given I do have a directory named "foobar"$
241
+ #
160
242
  def create_dir(dir_name)
161
243
  in_current_dir do
162
244
  _mkdir(dir_name)
163
245
  end
164
246
  end
165
247
 
166
-
248
+ # create_file(file_name, file_content, check_presence = false) creates
249
+ # the given file name in the awd and fills it with the provided content,
250
+ # optionally checking first to see if the file exists.
251
+ #
252
+ # Usage:
253
+ # When we do have a file named "foo" containing:
254
+ # """
255
+ # This is in my new file.
256
+ # And so is this
257
+ # """
258
+ #
167
259
  def create_file(file_name, file_content, check_presence = false)
168
260
  in_current_dir do
169
261
  raise "expected #{file_name} to be present" if check_presence && !File.file?(file_name)
@@ -172,32 +264,26 @@ module Aruba
172
264
  end
173
265
  end
174
266
 
175
-
176
- def create_rvm_gemset(rvm_gemset)
177
- raise "You haven't specified what ruby version rvm should use." \
178
- if @rvm_ruby_version.nil?
179
- run "rvm --create #{@rvm_ruby_version}@#{rvm_gemset}"
180
- end
181
-
182
-
267
+ # current_dir is an internal helper method that returns the current awd
268
+ # as a path.
269
+ #
183
270
  def current_dir
184
271
  File.join(*dirs)
185
272
  end
186
273
 
187
-
274
+ # current_ruby is an internal helper method that returns the
275
+ # path to the currently active Ruby VM.
276
+ #
188
277
  def current_ruby
189
278
  File.join(RbConfig::CONFIG['bindir'],
190
279
  RbConfig::CONFIG['ruby_install_name'])
191
280
  end
192
281
 
193
-
194
- def delete_rvm_gemset(rvm_gemset)
195
- raise "You haven't specified what ruby version rvm should use." \
196
- if @rvm_ruby_version.nil?
197
- run "rvm --force gemset delete #{@rvm_ruby_version}@#{rvm_gemset}"
198
- end
199
-
200
-
282
+ # detect_ruby(cmd) is an internal helper method that checks to see
283
+ # if the Aruba test cli command is ruby itself and returns the
284
+ # value of current_ruby to the <tt>run</tt> method and the value
285
+ # of cmd otherwise.
286
+ #
201
287
  def detect_ruby(cmd)
202
288
  if cmd =~ /^ruby\s/
203
289
  cmd.gsub(/^ruby\s/, "#{current_ruby} ")
@@ -206,42 +292,59 @@ module Aruba
206
292
  end
207
293
  end
208
294
 
209
-
295
+ # This provides a regexp of commonly encountered Ruby scripts
296
+ # for use in testing Aruba itself.
297
+ #
210
298
  COMMON_RUBY_SCRIPTS = \
211
- /^(?:bundle|cucumber|gem|jeweler|rails|rake|rspec|spec)\s/
212
-
299
+ /^(?:bundle|cucumber|gem|jeweler|rails|rake|rspec|spec)\s/
213
300
 
301
+ # detect_ruby_script is an internal helper script used in testing
302
+ # Aruba itself.
303
+ #
214
304
  def detect_ruby_script(cmd)
215
305
  if cmd =~ COMMON_RUBY_SCRIPTS
216
306
  "ruby -S #{cmd}"
217
307
  else
218
308
  cmd
309
+
219
310
  end
220
311
  end
221
312
 
222
-
313
+ # dirs is an internal helper method that returns the current
314
+ # directory components as an array.
315
+ #
223
316
  def dirs
224
317
  @dirs ||= dirs_init
225
318
  end
226
319
 
227
-
320
+ # dirs_init is an internal helper method that intializes the
321
+ # content of the dirs to the value of aruba_working_dir.
322
+ #
228
323
  def dirs_init
229
324
  @dirs = []
230
325
  @dirs << aruba_working_dir
231
326
  end
232
327
 
233
-
328
+ # ensure_newline(str) is an internal helper method used to test interactive
329
+ # CLI programs with Aruba.
330
+ #
234
331
  def ensure_newline(str)
235
332
  str.chomp << "\n"
236
333
  end
237
334
 
238
-
335
+ # in_current_dir(&block) is an internal helper method wherein all the magic
336
+ # of Aruba takes place. It uses the value of current_dir to determine
337
+ # what directory to change to before running Aruba steps.
338
+ #
239
339
  def in_current_dir(&block)
240
340
  _mkdir(current_dir)
241
341
  Dir.chdir(current_dir, &block)
242
342
  end
243
343
 
244
-
344
+ # install_gems(gemfile) internal helper method that uses Bundler to
345
+ # install the gems specified int he given Gemfile name into the
346
+ # current Ruby VM.
347
+ #
245
348
  def install_gems(gemfile)
246
349
  create_file("Gemfile", gemfile)
247
350
  if ENV['GOTGEMS'].nil?
@@ -250,7 +353,9 @@ module Aruba
250
353
  end
251
354
  end
252
355
 
253
-
356
+ # interactive_output an internal helper method that provides the contents
357
+ # of $stdout from interactive Aruba processes.
358
+ #
254
359
  def interactive_output
255
360
  @_interactive ||= if @interactive
256
361
  @interactive.wait(1) || @interactive.kill('TERM')
@@ -260,22 +365,28 @@ module Aruba
260
365
  end
261
366
  end
262
367
 
263
-
368
+ # original_env is an internal helper method that returns a hash of the
369
+ # original env variables and their values for restore_original_env
370
+ #
264
371
  def original_env
265
372
  @original_env ||= {}
266
373
  end
267
374
 
268
-
269
- def pick_up
270
- @pick_up
271
- end
272
-
273
-
375
+ # _mkdir(dir_name) is an internal helper name that does exactly as its
376
+ # stem suggests, performs a mkdir using the provided name.
377
+ #
274
378
  def _mkdir(dir_name)
275
379
  FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
276
380
  end
277
381
 
278
-
382
+ # rebase(dirs=nil) creates a symbolic link in the awd to each directory
383
+ # contained in the passed array that are named relative to the user's
384
+ # cwd. It first checkes that the awd path contains a directory named
385
+ # <tt>/tmp/</tt> and fails if it does not.
386
+ #
387
+ # Usage:
388
+ # When I rebase the directory "bar/foo"$
389
+ #
279
390
  def rebase(dirs=nil)
280
391
 
281
392
  rebase_dirs_add(dirs) if dirs
@@ -292,12 +403,16 @@ module Aruba
292
403
  end
293
404
  end
294
405
 
295
-
406
+ # rebase_dirs is an internal helper mehtod that returns the
407
+ # array containing all the directories to be rebased.
408
+ #
296
409
  def rebase_dirs
297
410
  @aruba_rebase_dirs
298
411
  end
299
412
 
300
-
413
+ # rebase_dirs_add(dirs=nil) is an internal helper method that
414
+ # adds directory names to the rebase_dirs array.
415
+ #
301
416
  def rebase_dirs_add(dirs=nil)
302
417
  return unless dirs
303
418
  dirs = dirs.lines.to_a if dirs.respond_to?('lines')
@@ -306,23 +421,48 @@ module Aruba
306
421
  @aruba_rebase_dirs = (@aruba_rebase_dirs + dirs).uniq
307
422
  end
308
423
 
309
-
424
+ # rebase_dirs_clear is an internal helper method that empties
425
+ # the rebase_dirs array.
426
+ #
310
427
  def rebase_dirs_clear
311
428
  @aruba_rebase_dirs = []
312
429
  end
313
430
 
314
-
431
+ # regexp(string_or_regexp) is an internal helper method used to compile
432
+ # regexp for use in step definations.
433
+ #
434
+ # Usage:
435
+ # Then should (pass|fail) with regexp:
436
+ # """
437
+ # /^Better start with this/
438
+ # """
439
+ # Then stderr should contain "this"
440
+ # Then stdout should contain "this"
441
+ # Then stderr should not contain "this"
442
+ # Then stdout should not contain "this"
443
+ #
315
444
  def regexp(string_or_regexp)
316
445
  Regexp === string_or_regexp ? string_or_regexp : Regexp.compile(Regexp.escape(string_or_regexp))
317
446
  end
318
447
 
319
-
448
+ # restore_env is an internal helper method that restors the user's original
449
+ # environment at the completion of a scenario using Aruba.
450
+ #
320
451
  def restore_env
321
452
  original_env.each do |key, value|
322
453
  ENV[key] = value
323
454
  end
324
455
  end
325
456
 
457
+ # run(cmd, fail_on_error=true) is the internal helper method that actually
458
+ # runs the test executable, optionally failing if the exit status != 0.
459
+ #
460
+ # Usage:
461
+ # When I run "ruby -e 'puts "hello world"'
462
+ # When I run "ruby -e 'print "Name? "; my_name = gets'" interactively
463
+ # When I run "ruby -e 'fail' with errors
464
+ # When I run "ruby -e 'exit' without errors
465
+ #
326
466
  def run(cmd, fail_on_error=true)
327
467
  cmd = detect_ruby(cmd)
328
468
 
@@ -338,35 +478,19 @@ module Aruba
338
478
  @last_exit_status = ps.exitstatus # Waits for process to finish
339
479
  end
340
480
 
341
- =begin
342
- stderr_file = Tempfile.new('cucumber')
343
- stderr_file.close
344
- in_current_dir do
345
- announce_or_puts("$ cd #{Dir.pwd}") if @announce_dir
346
- announce_or_puts("$ #{cmd}") if @announce_cmd
347
-
348
- mode = RUBY_VERSION =~ /^1\.9/ ? {:external_encoding=>"UTF-8"} : 'r'
349
-
350
- IO.popen("unset BUNDLE_PATH && unset BUNDLE_BIN_PATH && unset BUNDLE_GEMFILE && #{cmd} 2> #{stderr_file.path}", mode) do |io|
351
- @last_stdout = io.read
352
- announce_or_puts(@last_stdout) if @announce_stdout
353
- end
354
-
355
- @last_exit_status = $?.exitstatus
356
- end
357
-
358
- @last_stderr = IO.read(stderr_file.path)
359
- announce_or_puts(@last_stderr) if @announce_stderr
360
- =end
361
-
362
481
  if(@last_exit_status != 0 && fail_on_error)
363
482
  fail("Exit status was #{@last_exit_status}. Output:\n#{combined_output}")
364
483
  end
365
484
 
366
485
  @last_stderr
367
486
  end
368
-
369
-
487
+
488
+ # run_interactive(cmd) is an internal helper method that runs CLI
489
+ # programs returning user input.
490
+ #
491
+ # Usage:
492
+ # When I run "ruby -e 'print "Name? "; my_name = gets'" interactively
493
+ #
370
494
  def run_interactive(cmd)
371
495
  cmd = detect_ruby(cmd)
372
496
 
@@ -375,26 +499,37 @@ module Aruba
375
499
  end
376
500
  end
377
501
 
378
-
502
+ # set_env(key, value) is an internal helper method that sets a hash of the
503
+ # original env variables and their values for restore_original_env
504
+ #
379
505
  def set_env(key, value)
380
506
  announce_or_puts(%{$ export #{key}="#{value}"}) if @announce_env
381
507
  original_env[key] = ENV.delete(key)
382
508
  ENV[key] = value
383
509
  end
384
510
 
385
-
511
+ # unescape(string) is an internal helper method that evals the passed
512
+ # string.
513
+ #
386
514
  def unescape(string)
387
515
  eval(%{"#{string}"})
388
516
  end
389
517
 
390
-
518
+ # unset_bundler_env_vars is an internal helper method that unsets
519
+ # enviromental variables used by the Bundler gem.
520
+ #
391
521
  def unset_bundler_env_vars
392
522
  %w[RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE].each do |key|
393
523
  set_env(key, nil)
394
524
  end
395
525
  end
396
526
 
397
-
527
+ # use_clean_gemset(gemset) takes a gemset name and creates it
528
+ # using gemset.
529
+ #
530
+ # Usage:
531
+ # When I am using a clean gemset "my_global*)"
532
+ #
398
533
  def use_clean_gemset(gemset)
399
534
  run(%{rvm gemset create "#{gemset}"}, true)
400
535
  if @last_stdout =~ /'#{gemset}' gemset created \((.*)\)\./
@@ -413,13 +548,19 @@ module Aruba
413
548
  end
414
549
  end
415
550
 
416
-
551
+ # user_working_dir is an internal helper method used by the rebase method
552
+ # that initially sets and then returns the user's pwd.
553
+ #
417
554
  def user_working_dir
418
555
  # This allows us to find the user's original working directory
419
556
  @user_working_dir ||= FileUtils.pwd
420
557
  end
421
558
 
422
-
559
+ # write_interactive(input) writes the provided string to $stdin of
560
+ # the interactive process run by Aruba.
561
+ # Usage
562
+ # When i type "the answwer is 42"
563
+ #
423
564
  def write_interactive(input)
424
565
  @interactive.stdin.write(input)
425
566
  end
@@ -256,3 +256,8 @@ end
256
256
  When /type "([^\"]*)"$/ do |input|
257
257
  write_interactive(ensure_newline(input))
258
258
  end
259
+
260
+
261
+ When /(?:use|using) a clean gemset "([^\"]*)"$/ do |gemset|
262
+ use_clean_gemset(gemset)
263
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aruba-jbb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 73
4
+ hash: 87
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 6
10
- - 7
11
- version: 0.2.6.7
10
+ - 8
11
+ version: 0.2.6.8
12
12
  platform: ruby
13
13
  authors:
14
14
  - "Aslak Helles\xC3\xB8y"