aruba 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c57ab964ee2b570039772b4c25a48e5c29ac7f3
4
- data.tar.gz: 2a3ae133538910c61a2abb9ec980fbe5a5ae03d8
3
+ metadata.gz: 7f0ef8ad9b9057dd75bbeb89727f93f569c84a63
4
+ data.tar.gz: d81765e3e79d77b131ab9385eab81acb329117fd
5
5
  SHA512:
6
- metadata.gz: 3f4e0203537678fb2341a3d0f880805c98acf094317c6b5ac63bf7f1b5f5baba6d4c05eb51698eb1ff8a2b61972780ff22dc06b5466d8e7ec0d535e54a3af2f1
7
- data.tar.gz: 1471f170b99a6569819d13b577f4178593a285c730e5cdf327e9d7d36bef3df96d6a07223962641e3158d7b454ca5b999b4aea42b4ed3569e6149bb2ded54593
6
+ metadata.gz: f4dd1b000f2356f5ba7f4e70a0c513aecdcfafecfdf0f15cb94703ae6ce608d858c43cf078f80c7fd8f2c91cdd800a3f11f6163e34a18389629759e9eea0af0c
7
+ data.tar.gz: 583fb0214abe43ce3976b1b124646b2ce5139bb439689b4d191458b13d44e6462d935e968c4ff3c5813473e79bd74a9c08f641e6a294f45993f012b3890e1820
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.1.2
3
4
  - 2.1.1
4
5
  - 2.1.0
5
6
  - 2.0.0
@@ -44,6 +44,8 @@ Now release it
44
44
  git commit -m "Release X.Y.Z"
45
45
  rake release
46
46
 
47
+ Now email cukes@googlegroups.com with details of the new release. Just a copy / paste from the History.md file is normally fine.
48
+
47
49
  ## Gaining Release Karma
48
50
 
49
51
  To become a release manager, create a pull request adding your name to the list below, and include your Rubygems email address in the ticket. One of the existing Release managers will then add you.
@@ -57,4 +59,3 @@ Current release managers:
57
59
  To grant release karma, issue the following command:
58
60
 
59
61
  gem owner cucumber --add <NEW OWNER RUBYGEMS EMAIL>
60
-
data/History.md CHANGED
@@ -1,8 +1,13 @@
1
- ## [master](https://github.com/cucumber/aruba/compare/v0.6.0...master)
1
+ ## [master](https://github.com/cucumber/aruba/compare/v0.6.1...master)
2
+
3
+ ## [master](https://github.com/cucumber/aruba/compare/v0.6.0...v0.6.1)
4
+ * Added support for ruby 2.1.2
5
+ * Added support for ~ expansion
6
+ * Added support for with_env
2
7
 
3
8
  ## [v0.6.0](https://github.com/cucumber/aruba/compare/v0.5.4...v0.6.0)
4
9
  * Dropped support for ruby 1.8
5
- * Added support for ruby 2.1.0
10
+ * Added support for ruby 2.1.0 and 2.1.1
6
11
  * Added rspec 3.0.0 support
7
12
 
8
13
  ## [v0.5.4](https://github.com/cucumber/aruba/compare/v0.5.3...v0.5.4)
data/README.md CHANGED
@@ -8,6 +8,8 @@ Aruba is Cucumber extension for testing command line applications written in any
8
8
 
9
9
  ## Usage
10
10
 
11
+ ### Cucumber
12
+
11
13
  If you have a `Gemfile`, add `aruba`. Otherwise, install it like this:
12
14
 
13
15
  gem install aruba
@@ -22,6 +24,38 @@ You now have a bunch of step definitions that you can use in your features. Look
22
24
  to see them all. Look at [`features/*.feature`](features/) for examples (which are also testing Aruba
23
25
  itself).
24
26
 
27
+ ### RSpec
28
+
29
+ Originally written for `cucumber`, `aruba` can be helpful in other contexts as
30
+ well. One might want to use it together with `rspec`.
31
+
32
+ 1. Create a directory named `spec/support`
33
+ 2. Create a file named `spec/support/aruba.rb` with:
34
+
35
+ ```
36
+ require 'aruba/api
37
+ require 'aruba/reporting'
38
+
39
+ RSpec.configure do |c|
40
+ c.include Aruba::Api
41
+ c.after(:each) do
42
+ restore_env
43
+ end
44
+ end
45
+ ```
46
+
47
+ ## API
48
+
49
+ `aruba` provides a wonderfull api to be used in your tests:
50
+
51
+ * Creating files/directories
52
+ * Deleting files/directories
53
+ * Checking file size
54
+ * Checking file existence/absence
55
+ * ...
56
+
57
+ A full documentation of the api can be found [here](http://www.rubydoc.info/github/cucumber/aruba/master/frames).
58
+
25
59
  ## Configuration
26
60
 
27
61
  Aruba has some default behaviour that you can change if you need to.
@@ -149,6 +183,17 @@ That's it! Everything will now run inside the same ruby process, making your sui
149
183
  a lot faster. Cucumber itself uses this approach to test itself, so check out the
150
184
  Cucumber source code for an example.
151
185
 
186
+ *Pros*:
187
+
188
+ * Very fast compared to spawning processes
189
+ * You can use libraries like
190
+ [simplecov](https://github.com/colszowka/simplecov) more easily, because
191
+ there is only one "process" which adds data to `simplecov`'s database
192
+
193
+ *Cons*:
194
+ * You might oversee some bugs: You might forget to require libraries in your
195
+ "production" code, because you have required them in your testing code
196
+
152
197
  ### JRuby Tips
153
198
 
154
199
  Improve startup time by disabling JIT and forcing client JVM mode. This can be accomplished by adding
@@ -247,16 +292,10 @@ Scenario: Make tea
247
292
  Given...
248
293
  ```
249
294
 
250
- ## Note on Patches/Pull Requests
251
-
252
- * Fork the project.
253
- * Make your feature addition or bug fix.
254
- * Add tests for it. This is important so I don't break it in a
255
- future version unintentionally. Note: the existing tests may fail
256
- * Commit, do not mess with Rakefile, gemspec or History.
257
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
258
- * Send me a pull request. Bonus points for topic branches.
295
+ ## Contributing
296
+
297
+ Please see the `CONTRIBUTING.md`.
259
298
 
260
299
  ## Copyright
261
300
 
262
- Copyright (c) 2010,2011,2012,2013 Aslak Hellesøy, David Chelimsky and Mike Sassak. See LICENSE for details.
301
+ Copyright (c) 2010,2011,2012,2013,2014 Aslak Hellesøy, David Chelimsky and Mike Sassak. See LICENSE for details.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'aruba'
5
- s.version = '0.6.0'
5
+ s.version = '0.6.1'
6
6
  s.authors = ["Aslak Hellesøy", "David Chelimsky", "Mike Sassak", "Matt Wynne"]
7
7
  s.description = 'CLI Steps for Cucumber, hand-crafted for you in Aruba'
8
8
  s.summary = "aruba-#{s.version}"
@@ -13,3 +13,19 @@ Feature: Command environment variables
13
13
  """
14
14
  long_value
15
15
  """
16
+
17
+ Scenario: Mocked home directory
18
+ Given a mocked home directory
19
+ When I run `/usr/bin/env`
20
+ Then the output should contain:
21
+ """
22
+ tmp/aruba
23
+ """
24
+
25
+ @mocked_home_directory
26
+ Scenario: Mocked home directory
27
+ When I run `/usr/bin/env`
28
+ Then the output should contain:
29
+ """
30
+ tmp/aruba
31
+ """
@@ -166,6 +166,11 @@ Feature: file system commands
166
166
  When I remove the file "foo"
167
167
  Then the file "foo" should not exist
168
168
 
169
+ Scenario: Remove directory
170
+ Given a directory named "foo"
171
+ When I remove the directory "foo"
172
+ Then a directory named "foo" should not exist
173
+
169
174
  Scenario: Just a dummy for reporting
170
175
  Given an empty file named "a/b.txt"
171
176
  Given an empty file named "a/b/c.txt"
@@ -10,99 +10,223 @@ module Aruba
10
10
  module Api
11
11
  include RSpec::Matchers
12
12
 
13
+ # Execute block in current directory
14
+ #
15
+ # @yield
16
+ # The block which should be run in current directory
13
17
  def in_current_dir(&block)
14
18
  _mkdir(current_dir)
15
19
  Dir.chdir(current_dir, &block)
16
20
  end
17
21
 
22
+ # Clean the current directory
18
23
  def clean_current_dir
19
24
  _rm_rf(current_dir)
20
25
  _mkdir(current_dir)
21
26
  end
22
27
 
28
+ # Get access to current dir
29
+ #
30
+ # @return
31
+ # Current directory
23
32
  def current_dir
24
33
  File.join(*dirs)
25
34
  end
26
35
 
36
+ # Switch to directory
37
+ #
38
+ # @param [String] dir
39
+ # The directory
27
40
  def cd(dir)
28
41
  dirs << dir
29
42
  raise "#{current_dir} is not a directory." unless File.directory?(current_dir)
30
43
  end
31
44
 
45
+ # The path to the directory which should contain all your test data
46
+ # You might want to overwrite this method to place your data else where.
47
+ #
48
+ # @return [Array]
49
+ # The directory path: Each subdirectory is a member of an array
32
50
  def dirs
33
51
  @dirs ||= ['tmp', 'aruba']
34
52
  end
35
53
 
54
+ # Create a file with given content
55
+ #
56
+ # The method does not check if file already exists. If the file name is a
57
+ # path the method will create all neccessary directories.
58
+ #
59
+ # @param [String] file_name
60
+ # The name of the file
61
+ #
62
+ # @param [String] file_content
63
+ # The content which should be written to the file
36
64
  def write_file(file_name, file_content)
37
65
  _create_file(file_name, file_content, false)
38
66
  end
39
67
 
68
+ # Create a file with the given size
69
+ #
70
+ # The method does not check if file already exists. If the file name is a
71
+ # path the method will create all neccessary directories.
72
+ #
73
+ # @param [String] file_name
74
+ # The name of the file
75
+ #
76
+ # @param [Integer] file_size
77
+ # The size of the file
40
78
  def write_fixed_size_file(file_name, file_size)
41
79
  _create_fixed_size_file(file_name, file_size, false)
42
80
  end
43
81
 
82
+ # Create a file with given content
83
+ #
84
+ # The method does check if file already exists and fails if the file is
85
+ # missing. If the file name is a path the method will create all neccessary
86
+ # directories.
44
87
  def overwrite_file(file_name, file_content)
45
88
  _create_file(file_name, file_content, true)
46
89
  end
47
90
 
48
91
  def _create_file(file_name, file_content, check_presence)
49
92
  in_current_dir do
93
+ file_name = File.expand_path(file_name)
94
+
50
95
  raise "expected #{file_name} to be present" if check_presence && !File.file?(file_name)
96
+
51
97
  _mkdir(File.dirname(file_name))
52
98
  File.open(file_name, 'w') { |f| f << file_content }
53
99
  end
54
100
  end
55
101
 
56
- def chmod(mode, name)
102
+ # Change file system permissions of file
103
+ #
104
+ # @param [Octal] mode
105
+ # File system mode, eg. 0755
106
+ #
107
+ # @param [String] file_name
108
+ # Name of file to be modified. This file needs to be present to succeed
109
+ def filesystem_permissions(mode, file_name)
57
110
  in_current_dir do
58
- raise "expected #{name} to be present" unless FileTest.exists?(name)
111
+ file_name = File.expand_path(file_name)
112
+
113
+ raise "expected #{file_name} to be present" unless FileTest.exists?(file_name)
59
114
  if mode.kind_of? String
60
- FileUtils.chmod(mode.to_i(8),name)
115
+ FileUtils.chmod(mode.to_i(8),file_name)
61
116
  else
62
- FileUtils.chmod(mode,name)
117
+ FileUtils.chmod(mode, file_name)
63
118
  end
64
119
  end
65
120
  end
66
121
 
67
- def mod?(mode, name)
122
+ def chmod(*args, &block)
123
+ warn('The use of "chmod" is deprecated. Use "filesystem_permissions" instead')
124
+
125
+ filesystem_permissions(*args, &block)
126
+ end
127
+
128
+ # Check file system permissions of file
129
+ #
130
+ # @param [Octal] mode
131
+ # Expected file system permissions, e.g. 0755
132
+ # @param [String] file_name
133
+ # Expected file system permissions, e.g. 0755
134
+ # @param [Boolean] expect_permissions
135
+ # Are the permissions expected to be mode or are they expected not to be mode?
136
+ def check_filesystem_permissions(mode, file_name, expect_permissions)
68
137
  in_current_dir do
69
- mode == sprintf( "%o", File::Stat.new(name).mode )[-4,4].to_i(8)
138
+ file_name = File.expand_path(file_name)
139
+
140
+ raise "expected #{file_name} to be present" unless FileTest.exists?(file_name)
141
+ if mode.kind_of? Integer
142
+ expected_mode = mode.to_s(8)
143
+ else
144
+ expected_mode = mode.gsub(/^0*/, '')
145
+ end
146
+
147
+ file_mode = sprintf( "%o", File::Stat.new(file_name).mode )[-4,4].gsub(/^0*/, '')
148
+
149
+ if expect_permissions
150
+ expect(file_mode).to eq expected_mode
151
+ else
152
+ expect(file_mode).not_to eq expected_mode
153
+ end
70
154
  end
71
155
  end
72
156
 
157
+ def mod?(*args, &block)
158
+ warn('The use of "mod?" is deprecated. Use "check_filesystem_permissions" instead')
159
+
160
+ check_filesystem_permissions(*args, &block)
161
+ end
162
+
73
163
  def _create_fixed_size_file(file_name, file_size, check_presence)
74
164
  in_current_dir do
165
+ file_name = File.expand_path(file_name)
166
+
75
167
  raise "expected #{file_name} to be present" if check_presence && !File.file?(file_name)
76
168
  _mkdir(File.dirname(file_name))
77
169
  File.open(file_name, "wb"){ |f| f.seek(file_size - 1); f.write("\0") }
78
170
  end
79
171
  end
80
172
 
173
+ # Remove file
174
+ #
175
+ # @param [String] file_name
176
+ # The file which should be deleted in current directory
81
177
  def remove_file(file_name)
82
178
  in_current_dir do
179
+ file_name = File.expand_path(file_name)
180
+
83
181
  FileUtils.rm(file_name)
84
182
  end
85
183
  end
86
184
 
185
+ # Append data to file
186
+ #
187
+ # @param [String] file_name
188
+ # The name of the file to be used
189
+ #
190
+ # @param [String] file_content
191
+ # The content which should be appended to file
87
192
  def append_to_file(file_name, file_content)
88
193
  in_current_dir do
194
+ file_name = File.expand_path(file_name)
195
+
89
196
  _mkdir(File.dirname(file_name))
90
197
  File.open(file_name, 'a') { |f| f << file_content }
91
198
  end
92
199
  end
93
200
 
94
- def create_dir(dir_name)
201
+ # Create a directory in current directory
202
+ #
203
+ # @param [String] directory_name
204
+ # The name of the directory which should be created
205
+ def create_dir(directory_name)
95
206
  in_current_dir do
96
- _mkdir(dir_name)
207
+ _mkdir(directory_name)
97
208
  end
98
209
  end
99
210
 
211
+ # Remove directory
212
+ #
213
+ # @param [String] directory_name
214
+ # The name of the directory which should be removed
100
215
  def remove_dir(directory_name)
101
216
  in_current_dir do
217
+ directory_name = File.expand_path(directory_name)
218
+
102
219
  FileUtils.rmdir(directory_name)
103
220
  end
104
221
  end
105
222
 
223
+ # Check if paths are present
224
+ #
225
+ # @param [#each] paths
226
+ # The paths which should be checked
227
+ #
228
+ # @param [true,false] expect_presence
229
+ # Should the given paths be present (true) or absent (false)
106
230
  def check_file_presence(paths, expect_presence)
107
231
  prep_for_fs_check do
108
232
  paths.each do |path|
@@ -113,6 +237,8 @@ module Aruba
113
237
  expect(Dir.glob('**/*')).not_to include_regexp(path)
114
238
  end
115
239
  else
240
+ path = File.expand_path(path)
241
+
116
242
  if expect_presence
117
243
  expect(File).to be_file(path)
118
244
  else
@@ -123,33 +249,78 @@ module Aruba
123
249
  end
124
250
  end
125
251
 
126
- def pipe_in_file(file)
252
+ # Pipe data in file
253
+ #
254
+ # @param [String] file_name
255
+ # The file which should be used to pipe in data
256
+ def pipe_in_file(file_name)
127
257
  in_current_dir do
128
- File.open(file, 'r').each_line do |line|
258
+ file_name = File.expand_path(file_name)
259
+
260
+ File.open(file_name, 'r').each_line do |line|
129
261
  _write_interactive(line)
130
262
  end
131
263
  end
132
264
  end
133
265
 
266
+ # Check the file size of paths
267
+ #
268
+ # @params [Hash] paths_and_sizes
269
+ # A hash containing the path (key) and the expected size (value)
270
+ #
271
+ # @example
272
+ #
273
+ # paths_and_sizes = {
274
+ # 'file' => 10
275
+ # }
276
+ #
277
+ # check_file_size(paths_and_sizes)
278
+ #
134
279
  def check_file_size(paths_and_sizes)
135
280
  prep_for_fs_check do
136
281
  paths_and_sizes.each do |path, size|
282
+ path = File.expand_path(path)
283
+
137
284
  expect(File.size(path)).to eq size
138
285
  end
139
286
  end
140
287
  end
141
288
 
289
+ # Read content of file and yield the content to block
290
+ #
291
+ # @param [String) file
292
+ # The name of file which should be read from
293
+ #
294
+ # @yield
295
+ # Pass the content of the given file to this block
142
296
  def with_file_content(file, &block)
143
297
  prep_for_fs_check do
298
+ file = File.expand_path(file)
299
+
144
300
  content = IO.read(file)
145
301
  yield(content)
146
302
  end
147
303
  end
148
304
 
305
+ # Check the content of file
306
+ #
307
+ # It supports partial content as well. And it is up to you to decided if
308
+ # the content must be there or not.
309
+ #
310
+ # @param [String] file
311
+ # The file to be checked
312
+ #
313
+ # @param [String] partial_content
314
+ # The content which must/must not be in the file
315
+ #
316
+ # @param [true, false] expect_match
317
+ # Must the content be in the file or not
149
318
  def check_file_content(file, partial_content, expect_match)
150
319
  regexp = regexp(partial_content)
151
320
  prep_for_fs_check do
321
+ file = File.expand_path(file)
152
322
  content = IO.read(file)
323
+
153
324
  if expect_match
154
325
  expect(content).to match regexp
155
326
  else
@@ -158,13 +329,29 @@ module Aruba
158
329
  end
159
330
  end
160
331
 
332
+ # Check if the exact content can be found in file
333
+ #
334
+ # @param [String] file
335
+ # The file to be checked
336
+ #
337
+ # @param [String] exact_content
338
+ # The content of the file
161
339
  def check_exact_file_content(file, exact_content)
162
340
  prep_for_fs_check { expect(IO.read(file)).to eq exact_content }
163
341
  end
164
342
 
343
+ # Check presence of a directory
344
+ #
345
+ # @param [Array] paths
346
+ # The paths to be checked
347
+ #
348
+ # @param [true, false] expect_presence
349
+ # Should the directory be there or should the directory not be there
165
350
  def check_directory_presence(paths, expect_presence)
166
351
  prep_for_fs_check do
167
352
  paths.each do |path|
353
+ path = File.expand_path(path)
354
+
168
355
  if expect_presence
169
356
  expect(File).to be_directory(path)
170
357
  else
@@ -180,13 +367,24 @@ module Aruba
180
367
  end
181
368
 
182
369
  def _mkdir(dir_name)
370
+ dir_name = File.expand_path(dir_name)
371
+
183
372
  FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
184
373
  end
185
374
 
186
375
  def _rm_rf(dir_name)
376
+ dir_name = File.expand_path(dir_name)
377
+
187
378
  FileUtils.rm_rf(dir_name)
188
379
  end
189
380
 
381
+ # Unescape string
382
+ #
383
+ # @param [String] string
384
+ # The string which should be unescaped, e.g. the output of a command
385
+ #
386
+ # @return
387
+ # The string stripped from escape sequences
190
388
  def unescape(string)
191
389
  string = string.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e")
192
390
  string = string.gsub(/\e\[\d+(?>(;\d+)*)m/, '') unless @aruba_keep_ansi
@@ -197,16 +395,28 @@ module Aruba
197
395
  Regexp === string_or_regexp ? string_or_regexp : Regexp.compile(Regexp.escape(string_or_regexp))
198
396
  end
199
397
 
398
+ # Fetch output (stdout, stderr) from command
399
+ #
400
+ # @param [String] cmd
401
+ # The comand
200
402
  def output_from(cmd)
201
403
  cmd = detect_ruby(cmd)
202
404
  get_process(cmd).output
203
405
  end
204
406
 
407
+ # Fetch stdout from command
408
+ #
409
+ # @param [String] cmd
410
+ # The comand
205
411
  def stdout_from(cmd)
206
412
  cmd = detect_ruby(cmd)
207
413
  get_process(cmd).stdout
208
414
  end
209
415
 
416
+ # Fetch stderr from command
417
+ #
418
+ # @param [String] cmd
419
+ # The comand
210
420
  def stderr_from(cmd)
211
421
  cmd = detect_ruby(cmd)
212
422
  get_process(cmd).stderr
@@ -331,6 +541,13 @@ module Aruba
331
541
  processes.collect{ |_, process| process }
332
542
  end
333
543
 
544
+ # Run given command and stop it if timeout is reached
545
+ #
546
+ # @param [String] cmd
547
+ # The command which should be executed
548
+ #
549
+ # @param [Integer] timeout
550
+ # If the timeout is reached the command will be killed
334
551
  def run(cmd, timeout = nil)
335
552
  timeout ||= exit_timeout
336
553
  @commands ||= []
@@ -372,15 +589,24 @@ module Aruba
372
589
  assert_exit_status(0) if fail_on_error
373
590
  end
374
591
 
592
+ # Run a command interactively
593
+ #
594
+ # @param [String] cmd
595
+ # The command to by run
375
596
  def run_interactive(cmd)
376
597
  @interactive = run(cmd)
377
598
  end
378
599
 
600
+ # Provide data to command via stdin
601
+ #
602
+ # @param [String] input
603
+ # The input for the command
379
604
  def type(input)
380
605
  return close_input if "" == input
381
606
  _write_interactive(_ensure_newline(input))
382
607
  end
383
608
 
609
+ # Close stdin
384
610
  def close_input
385
611
  @interactive.stdin.close
386
612
  end
@@ -447,15 +673,27 @@ module Aruba
447
673
  end
448
674
  end
449
675
 
676
+ # Set environment variable
677
+ #
678
+ # @param [String] key
679
+ # The name of the environment variable as string, e.g. 'HOME'
680
+ #
681
+ # @param [String] value
682
+ # The value of the environment variable. Needs to be a string.
450
683
  def set_env(key, value)
451
684
  announcer.env(key, value)
452
- original_env[key] = ENV.delete(key)
685
+ original_env[key] = ENV.delete(key) unless original_env.key? key
453
686
  ENV[key] = value
454
687
  end
455
688
 
689
+ # Restore original process environment
456
690
  def restore_env
457
691
  original_env.each do |key, value|
458
- ENV[key] = value
692
+ if value
693
+ ENV[key] = value
694
+ else
695
+ ENV.delete key
696
+ end
459
697
  end
460
698
  end
461
699
 
@@ -463,6 +701,14 @@ module Aruba
463
701
  @original_env ||= {}
464
702
  end
465
703
 
704
+ def with_env(env = {}, &block)
705
+ env.each do |k,v|
706
+ set_env k, v
707
+ block.call
708
+ restore_env
709
+ end
710
+ end
711
+
466
712
  # TODO: move some more methods under here!
467
713
  private
468
714
 
@@ -23,7 +23,7 @@ end
23
23
 
24
24
  Given /^a directory named "([^"]*)" with mode "([^"]*)"$/ do |dir_name, dir_mode|
25
25
  create_dir(dir_name)
26
- chmod(dir_mode, dir_name)
26
+ filesystem_permissions(dir_mode, dir_name)
27
27
  end
28
28
 
29
29
  Given /^a file named "([^"]*)" with:$/ do |file_name, file_content|
@@ -32,7 +32,7 @@ end
32
32
 
33
33
  Given /^a file named "([^"]*)" with mode "([^"]*)" and with:$/ do |file_name, file_mode, file_content|
34
34
  write_file(file_name, file_content)
35
- chmod(file_mode, file_name)
35
+ filesystem_permissions(file_mode, file_name)
36
36
  end
37
37
 
38
38
  Given /^a (\d+) byte file named "([^"]*)"$/ do |file_size, file_name|
@@ -45,7 +45,7 @@ end
45
45
 
46
46
  Given /^an empty file named "([^"]*)" with mode "([^"]*)"$/ do |file_name, file_mode|
47
47
  write_file(file_name, "")
48
- chmod(file_mode, file_name)
48
+ filesystem_permissions(file_mode, file_name)
49
49
  end
50
50
 
51
51
  When /^I write to "([^"]*)" with:$/ do |file_name, file_content|
@@ -68,6 +68,10 @@ When /^I remove the file "([^"]*)"$/ do |file_name|
68
68
  remove_file(file_name)
69
69
  end
70
70
 
71
+ When(/^I remove the directory "(.*?)"$/) do |directory_name|
72
+ remove_dir(directory_name)
73
+ end
74
+
71
75
  When /^I cd to "([^"]*)"$/ do |dir|
72
76
  cd(dir)
73
77
  end
@@ -360,6 +364,18 @@ Then /^the file "([^"]*)" should not match \/([^\/]*)\/$/ do |file, partial_cont
360
364
  check_file_content(file, /#{partial_content}/, false)
361
365
  end
362
366
 
363
- Then /^the mode of filesystem object "([^"]*)" should match "([^"]*)"$/ do |name, mode|
364
- mod?(mode, name)
367
+ Then /^the mode of filesystem object "([^"]*)" should match "([^"]*)"$/ do |file, mode|
368
+ check_filesystem_permissions(mode, file, true)
369
+ end
370
+
371
+ Given /^a mocked home directory$/ do
372
+ set_env 'HOME', File.expand_path(current_dir)
373
+ end
374
+
375
+ Before '@mocked_home_directory' do
376
+ set_env 'HOME', File.expand_path(current_dir)
377
+ end
378
+
379
+ After do
380
+ restore_env
365
381
  end
@@ -1,7 +1,12 @@
1
1
  require 'spec_helper'
2
+ require 'securerandom'
2
3
 
3
4
  describe Aruba::Api do
4
5
 
6
+ def random_string(options = {})
7
+ options[:prefix].to_s + SecureRandom.hex + options[:suffix].to_s
8
+ end
9
+
5
10
  before(:each) do
6
11
  klass = Class.new {
7
12
  include Aruba::Api
@@ -51,27 +56,51 @@ describe Aruba::Api do
51
56
  end
52
57
 
53
58
  describe 'directories' do
54
- context 'delete directory' do
59
+ context '#remove_dir' do
55
60
  before(:each) do
56
61
  @directory_name = 'test_dir'
57
62
  @directory_path = File.join(@aruba.current_dir, @directory_name)
58
63
  Dir.mkdir(@directory_path)
59
64
  end
65
+
60
66
  it 'should delete directory' do
61
67
  @aruba.remove_dir(@directory_name)
62
68
  expect(File.exist?(@directory_path)).to eq false
63
69
  end
70
+
71
+ it "works with ~ in path name" do
72
+ directory_path = File.join('~', random_string)
73
+
74
+ with_env 'HOME' => File.expand_path(current_dir) do
75
+ Dir.mkdir(File.expand_path(directory_path))
76
+ @aruba.remove_dir(directory_path)
77
+
78
+ expect(File.exist?(File.expand_path(directory_path))).to eq false
79
+ end
80
+ end
64
81
  end
65
82
  end
66
83
 
67
84
  describe 'files' do
68
- context 'fixed size' do
85
+ context '#write_fixed_size_file' do
69
86
  it "should write a fixed sized file" do
70
87
  @aruba.write_fixed_size_file(@file_name, @file_size)
71
88
  expect(File.exist?(@file_path)).to eq true
72
89
  expect(File.size(@file_path)).to eq @file_size
73
90
  end
74
91
 
92
+ it "works with ~ in path name" do
93
+ file_path = File.join('~', random_string)
94
+
95
+ with_env 'HOME' => File.expand_path(current_dir) do
96
+ @aruba.write_fixed_size_file(file_path, @file_size)
97
+
98
+ expect(File.exist?(File.expand_path(file_path))).to eq true
99
+ expect(File.size(File.expand_path(file_path))).to eq @file_size
100
+ end
101
+ end
102
+ end
103
+ context '#check_file_size' do
75
104
  it "should check an existing file size" do
76
105
  @aruba.write_fixed_size_file(@file_name, @file_size)
77
106
  @aruba.check_file_size([[@file_name, @file_size]])
@@ -81,33 +110,100 @@ describe Aruba::Api do
81
110
  @aruba.write_fixed_size_file(@file_name, @file_size)
82
111
  expect { @aruba.check_file_size([[@file_name, @file_size + 1]]) }.to raise_error
83
112
  end
113
+
114
+ it "works with ~ in path name" do
115
+ file_path = File.join('~', random_string)
116
+
117
+ with_env 'HOME' => File.expand_path(current_dir) do
118
+ @aruba.write_fixed_size_file(file_path, @file_size)
119
+ @aruba.check_file_size([[file_path, @file_size]])
120
+ end
121
+ end
122
+
123
+ it "should check an existing file size and fail" do
124
+ @aruba.write_fixed_size_file(@file_name, @file_size)
125
+ expect { @aruba.check_file_size([[@file_name, @file_size + 1]]) }.to raise_error
126
+ end
84
127
  end
85
- context 'existing' do
128
+ context '#filesystem_permissions' do
86
129
  before(:each) { File.open(@file_path, 'w') { |f| f << "" } }
87
- it "should delete file" do
88
- @aruba.remove_file(@file_name)
89
- expect(File.exist?(@file_path)).to eq false
90
- end
91
130
 
92
131
  it "should change a file's mode" do
93
- @aruba.chmod(0644, @file_name)
132
+ @aruba.filesystem_permissions(0644, @file_name)
94
133
  result = sprintf( "%o" , File::Stat.new(@file_path).mode )[-4,4]
95
134
  expect(result).to eq('0644')
96
135
 
97
- @aruba.chmod(0655, @file_name)
136
+ @aruba.filesystem_permissions(0655, @file_name)
98
137
  result = sprintf( "%o" , File::Stat.new(@file_path).mode )[-4,4]
99
138
  expect(result).to eq('0655')
100
139
 
101
- @aruba.chmod("0655", @file_name)
140
+ @aruba.filesystem_permissions("0655", @file_name)
102
141
  result = sprintf( "%o" , File::Stat.new(@file_path).mode )[-4,4]
103
142
  expect(result).to eq('0655')
104
143
  end
105
144
 
106
- it "should check the mode of a file" do
107
- @aruba.chmod(0666, @file_name)
108
- expect(@aruba.mod?(0666, @file_name) ).to eq(true)
145
+ it "supports a string representation of permission as well" do
146
+ @aruba.filesystem_permissions(0666, @file_name)
147
+ @aruba.check_filesystem_permissions('0666', @file_name, true)
148
+ end
149
+
150
+ it "should succeed if mode does not match but is expected to be different" do
151
+ @aruba.filesystem_permissions(0666, @file_name)
152
+ @aruba.check_filesystem_permissions(0755, @file_name, false)
153
+ end
154
+
155
+ it "should fail if mode matches and is expected to be different" do
156
+ @aruba.filesystem_permissions(0666, @file_name)
157
+ expect {
158
+ @aruba.check_filesystem_permissions(0666, @file_name, false)
159
+ }.to raise_error
109
160
  end
110
161
 
162
+ it "should fail if mode does not match but is expected to be equal" do
163
+ @aruba.filesystem_permissions(0666, @file_name)
164
+ expect {
165
+ @aruba.check_filesystem_permissions(0755, @file_name, true)
166
+ }.to raise_error
167
+ end
168
+
169
+ it "should succeed if mode matches and is expected to be equal" do
170
+ @aruba.filesystem_permissions(0666, @file_name)
171
+ @aruba.check_filesystem_permissions(0666, @file_name, true)
172
+ end
173
+
174
+ it "works with ~ in path name" do
175
+ file_name = "~/test_file"
176
+
177
+ with_env 'HOME' => File.expand_path(current_dir) do
178
+ File.open(File.expand_path(file_name), 'w') { |f| f << "" }
179
+
180
+ @aruba.filesystem_permissions(0666, file_name)
181
+ expect(@aruba.check_filesystem_permissions(0666, file_name, true) ).to eq(true)
182
+ end
183
+ end
184
+ end
185
+ context '#remove_file' do
186
+ before(:each) { File.open(@file_path, 'w') { |f| f << "" } }
187
+
188
+ it "should delete file" do
189
+ @aruba.remove_file(@file_name)
190
+ expect(File.exist?(@file_path)).to eq false
191
+ end
192
+
193
+ it "works with ~ in path name" do
194
+ file_path = File.join('~', random_string)
195
+
196
+ with_env 'HOME' => File.expand_path(current_dir) do
197
+ File.open(File.expand_path(file_path), 'w') { |f| f << "" }
198
+ @aruba.remove_file(file_path)
199
+ expect(File.exist?(file_path)).to eq false
200
+ end
201
+ end
202
+ end
203
+
204
+ context '#check_file_presence' do
205
+ before(:each) { File.open(@file_path, 'w') { |f| f << "" } }
206
+
111
207
  it "should check existence using plain match" do
112
208
  file_name = 'nested/dir/hello_world.txt'
113
209
  file_path = File.join(@aruba.current_dir, file_name)
@@ -143,6 +239,98 @@ describe Aruba::Api do
143
239
  @aruba.check_file_presence([ /test123/, 'asdf' ], false )
144
240
  end
145
241
 
242
+ it "works with ~ in path name" do
243
+ file_path = File.join('~', random_string)
244
+
245
+ with_env 'HOME' => File.expand_path(current_dir) do
246
+ FileUtils.mkdir_p File.dirname(File.expand_path(file_path))
247
+ File.open(File.expand_path(file_path), 'w') { |f| f << "" }
248
+
249
+ @aruba.check_file_presence( [ file_path ], true )
250
+ end
251
+ end
252
+ end
253
+
254
+ context "#check_file_content" do
255
+ before :each do
256
+ @aruba.write_file(@file_name, "foo bar baz")
257
+ end
258
+
259
+ it "succeeds if file content matches" do
260
+ @aruba.check_file_content(@file_name, "foo bar baz", true)
261
+ end
262
+
263
+ it "succeeds if file content does not match" do
264
+ @aruba.check_file_content(@file_name, "hello world", false)
265
+ end
266
+
267
+ it "works with ~ in path name" do
268
+ file_path = File.join('~', random_string)
269
+
270
+ with_env 'HOME' => File.expand_path(current_dir) do
271
+ @aruba.write_file(file_path, "foo bar baz")
272
+ @aruba.check_file_content(file_path, "hello world", false)
273
+ end
274
+ end
275
+ end
276
+
277
+ context "#with_file_content" do
278
+ before :each do
279
+ @aruba.write_file(@file_name, "foo bar baz")
280
+ end
281
+
282
+ it "checks the given file's full content against the expectations in the passed block" do
283
+ @aruba.with_file_content @file_name do |full_content|
284
+ expect(full_content).to eq "foo bar baz"
285
+ end
286
+ end
287
+
288
+ it "works with ~ in path name" do
289
+ file_path = File.join('~', random_string)
290
+
291
+ with_env 'HOME' => File.expand_path(current_dir) do
292
+ @aruba.write_file(file_path, "foo bar baz")
293
+
294
+ @aruba.with_file_content file_path do |full_content|
295
+ expect(full_content).to eq "foo bar baz"
296
+ end
297
+ end
298
+ end
299
+
300
+ context "checking the file's content against the expectations in the block" do
301
+ it "is successful when the inner expectations match" do
302
+ expect do
303
+ @aruba.with_file_content @file_name do |full_content|
304
+ expect(full_content).to match /foo/
305
+ expect(full_content).not_to match /zoo/
306
+ end
307
+ end . not_to raise_error
308
+ end
309
+
310
+ it "raises RSpec::Expectations::ExpectationNotMetError when the inner expectations don't match" do
311
+ expect do
312
+ @aruba.with_file_content @file_name do |full_content|
313
+ expect(full_content).to match /zoo/
314
+ expect(full_content).not_to match /foo/
315
+ end
316
+ end . to raise_error RSpec::Expectations::ExpectationNotMetError
317
+ end
318
+ end
319
+ end #with_file_content
320
+ end
321
+
322
+ describe 'process environment' do
323
+ context '#with_env' do
324
+ it 'modifies env for block' do
325
+ variable = 'THIS_IS_A_ENV_VAR'
326
+ ENV[variable] = '1'
327
+
328
+ with_env variable => '0' do
329
+ expect(ENV[variable]).to eq '0'
330
+ end
331
+
332
+ expect(ENV[variable]).to eq '1'
333
+ end
146
334
  end
147
335
  end
148
336
 
@@ -169,39 +357,6 @@ describe Aruba::Api do
169
357
  end
170
358
  end
171
359
 
172
- describe "#with_file_content" do
173
- before :each do
174
- @aruba.write_file(@file_name, "foo bar baz")
175
- end
176
-
177
- it "checks the given file's full content against the expectations in the passed block" do
178
- @aruba.with_file_content @file_name do |full_content|
179
- expect(full_content).to eq "foo bar baz"
180
- end
181
- end
182
-
183
- context "checking the file's content against the expectations in the block" do
184
- it "is successful when the inner expectations match" do
185
- expect do
186
- @aruba.with_file_content @file_name do |full_content|
187
- expect(full_content).to match /foo/
188
- expect(full_content).not_to match /zoo/
189
- end
190
- end . not_to raise_error
191
- end
192
-
193
- it "raises RSpec::Expectations::ExpectationNotMetError when the inner expectations don't match" do
194
- expect do
195
- @aruba.with_file_content @file_name do |full_content|
196
- expect(full_content).to match /zoo/
197
- expect(full_content).not_to match /foo/
198
- end
199
- end . to raise_error RSpec::Expectations::ExpectationNotMetError
200
- end
201
- end
202
-
203
- end #with_file_content
204
-
205
360
  describe "#assert_not_matching_output" do
206
361
  before(:each){ @aruba.run_simple("echo foo", false) }
207
362
  after(:each){ @aruba.stop_processes! }
@@ -255,14 +410,39 @@ describe Aruba::Api do
255
410
  end
256
411
  end
257
412
 
258
- describe "#run_simple" do
259
- after(:each){@aruba.stop_processes!}
260
- it "runs with different env" do
413
+ describe "#set_env" do
414
+ after(:each) do
415
+ @aruba.stop_processes!
416
+ @aruba.restore_env
417
+ end
418
+ it "set environment variable" do
261
419
  @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
262
420
  @aruba.run "env"
263
- expect(@aruba.all_output).to include("LONG_LONG_ENV_VARIABLE")
421
+ expect(@aruba.all_output).to include("LONG_LONG_ENV_VARIABLE=true")
264
422
  end
423
+ it "overwrites environment variable" do
424
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
425
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'false'
426
+ @aruba.run "env"
427
+ expect(@aruba.all_output).to include("LONG_LONG_ENV_VARIABLE=false")
428
+ end
429
+ end
265
430
 
431
+ describe "#restore_env" do
432
+ after(:each){@aruba.stop_processes!}
433
+ it "restores environment variable" do
434
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
435
+ @aruba.restore_env
436
+ @aruba.run "env"
437
+ expect(@aruba.all_output).not_to include("LONG_LONG_ENV_VARIABLE")
438
+ end
439
+ it "restores environment variable that has been set multiple times" do
440
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
441
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'false'
442
+ @aruba.restore_env
443
+ @aruba.run "env"
444
+ expect(@aruba.all_output).not_to include("LONG_LONG_ENV_VARIABLE")
445
+ end
266
446
  end
267
447
 
268
448
  end # Aruba::Api
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aruba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslak Hellesøy
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-06-30 00:00:00.000000000 Z
14
+ date: 2014-08-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: cucumber
@@ -226,24 +226,5 @@ rubyforge_project:
226
226
  rubygems_version: 2.2.2
227
227
  signing_key:
228
228
  specification_version: 4
229
- summary: aruba-0.6.0
230
- test_files:
231
- - features/before_cmd_hooks.feature
232
- - features/command_environment_variables.feature
233
- - features/custom_ruby_process.feature
234
- - features/exit_statuses.feature
235
- - features/file_system_commands.feature
236
- - features/flushing.feature
237
- - features/interactive.feature
238
- - features/no_clobber.feature
239
- - features/output.feature
240
- - features/step_definitions/aruba_dev_steps.rb
241
- - features/support/custom_main.rb
242
- - features/support/env.rb
243
- - features/support/jruby.rb
244
- - features/utf-8.feature
245
- - spec/aruba/api_spec.rb
246
- - spec/aruba/hooks_spec.rb
247
- - spec/aruba/jruby_spec.rb
248
- - spec/aruba/spawn_process_spec.rb
249
- - spec/spec_helper.rb
229
+ summary: aruba-0.6.1
230
+ test_files: []