aruba 0.6.1 → 0.6.2

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.
@@ -1,17 +1,17 @@
1
1
  module Aruba
2
2
  class Config
3
3
  attr_reader :hooks
4
-
4
+
5
5
  def initialize
6
6
  @hooks = Hooks.new
7
7
  end
8
-
8
+
9
9
  # Register a hook to be called before Aruba runs a command
10
10
  def before_cmd(&block)
11
11
  @hooks.append(:before_cmd, block)
12
12
  end
13
13
  end
14
-
14
+
15
15
  #nodoc
16
16
  class Hooks
17
17
  def initialize
@@ -19,26 +19,26 @@ module Aruba
19
19
  hash[key] = []
20
20
  end
21
21
  end
22
-
22
+
23
23
  def append(label, block)
24
24
  @store[label] << block
25
25
  end
26
-
26
+
27
27
  def execute(label, context, *args)
28
28
  @store[label].each do |block|
29
29
  context.instance_exec(*args, &block)
30
30
  end
31
31
  end
32
32
  end
33
-
33
+
34
34
  class << self
35
35
  attr_accessor :config
36
36
 
37
37
  def configure
38
38
  yield config
39
39
  end
40
-
40
+
41
41
  end
42
-
42
+
43
43
  self.config = Config.new
44
44
  end
@@ -129,7 +129,7 @@ When /^I pipe in the file "([^"]*)"$/ do |file|
129
129
  end
130
130
 
131
131
  When /^I wait for (?:output|stdout) to contain "([^"]*)"$/ do |expected|
132
- Timeout::timeout(exit_timeout) do
132
+ Timeout.timeout(exit_timeout) do
133
133
  loop do
134
134
  break if assert_partial_output_interactive(expected)
135
135
  sleep 0.1
@@ -332,36 +332,28 @@ Then /^the following directories should not exist:$/ do |directories|
332
332
  check_directory_presence(directories.raw.map{|directory_row| directory_row[0]}, false)
333
333
  end
334
334
 
335
- Then /^a directory named "([^"]*)" should exist$/ do |directory|
336
- check_directory_presence([directory], true)
335
+ Then /^a directory named "([^"]*)" should (not )?exist$/ do |directory, expect_match|
336
+ check_directory_presence([directory], !expect_match)
337
337
  end
338
338
 
339
- Then /^a directory named "([^"]*)" should not exist$/ do |directory|
340
- check_directory_presence([directory], false)
339
+ Then /^the file "([^"]*)" should (not )?contain "([^"]*)"$/ do |file, expect_match, partial_content|
340
+ check_file_content(file, Regexp.compile(Regexp.escape(partial_content)), !expect_match)
341
341
  end
342
342
 
343
- Then /^the file "([^"]*)" should contain "([^"]*)"$/ do |file, partial_content|
344
- check_file_content(file, partial_content, true)
343
+ Then /^the file "([^"]*)" should (not )?contain:$/ do |file, expect_match, partial_content|
344
+ check_file_content(file, Regexp.compile(Regexp.escape(partial_content)), !expect_match)
345
345
  end
346
346
 
347
- Then /^the file "([^"]*)" should not contain "([^"]*)"$/ do |file, partial_content|
348
- check_file_content(file, partial_content, false)
347
+ Then /^the file "([^"]*)" should (not )?contain exactly:$/ do |file, expect_match, exact_content|
348
+ check_file_content(file, exact_content, !expect_match)
349
349
  end
350
350
 
351
- Then /^the file "([^"]*)" should contain:$/ do |file, partial_content|
352
- check_file_content(file, partial_content, true)
351
+ Then /^the file "([^"]*)" should (not )?match \/([^\/]*)\/$/ do |file, expect_match, partial_content|
352
+ check_file_content(file, /#{partial_content}/, !expect_match)
353
353
  end
354
354
 
355
- Then /^the file "([^"]*)" should contain exactly:$/ do |file, exact_content|
356
- check_exact_file_content(file, exact_content)
357
- end
358
-
359
- Then /^the file "([^"]*)" should match \/([^\/]*)\/$/ do |file, partial_content|
360
- check_file_content(file, /#{partial_content}/, true)
361
- end
362
-
363
- Then /^the file "([^"]*)" should not match \/([^\/]*)\/$/ do |file, partial_content|
364
- check_file_content(file, /#{partial_content}/, false)
355
+ Then /^the file "([^"]*)" should (not )?be equal to file "([^"]*)"/ do |file, expect_match, reference_file|
356
+ check_binary_file_content(file, reference_file, !expect_match)
365
357
  end
366
358
 
367
359
  Then /^the mode of filesystem object "([^"]*)" should match "([^"]*)"$/ do |file, mode|
@@ -48,4 +48,4 @@ module Aruba
48
48
  @stderr.string
49
49
  end
50
50
  end
51
- end
51
+ end
@@ -2,7 +2,7 @@
2
2
  Aruba.configure do |config|
3
3
  config.before_cmd do
4
4
  # disable JIT since these processes are so short lived
5
- set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}")
5
+ set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}")
6
6
  # force jRuby to use client JVM for faster startup times
7
7
  set_env('JAVA_OPTS', "-d32 #{ENV['JAVA_OPTS']}") if RbConfig::CONFIG['host_os'] =~ /solaris|sunos/i
8
8
  end
@@ -1,6 +1,6 @@
1
1
  if(ENV['ARUBA_REPORT_DIR'])
2
2
  ENV['ARUBA_REPORT_TEMPLATES'] ||= File.dirname(__FILE__) + '/../../templates'
3
-
3
+
4
4
  require 'fileutils'
5
5
  require 'erb'
6
6
  require 'cgi'
@@ -17,7 +17,7 @@ if(ENV['ARUBA_REPORT_DIR'])
17
17
  end
18
18
  end
19
19
  end
20
-
20
+
21
21
  def pygmentize(file)
22
22
  pygmentize = SpawnProcess.new(%{pygmentize -f html -O encoding=utf-8 "#{file}"}, 3, 0.5)
23
23
  pygmentize.run! do |p|
@@ -28,7 +28,7 @@ if(ENV['ARUBA_REPORT_DIR'])
28
28
  IO.read(file)
29
29
  else
30
30
  STDERR.puts "\e[31m#{p.stderr} - is pygments installed?\e[0m"
31
- exit $?.exitstatus
31
+ exit $CHILD_STATUS.exitstatus
32
32
  end
33
33
  end
34
34
  end
@@ -61,15 +61,15 @@ if(ENV['ARUBA_REPORT_DIR'])
61
61
  erb = ERB.new(template('main.erb'), nil, '-')
62
62
  erb.result(binding)
63
63
  end
64
-
64
+
65
65
  def files
66
66
  erb = ERB.new(template('files.erb'), nil, '-')
67
67
  file = current_dir
68
68
  erb.result(binding)
69
69
  end
70
-
71
- def again(erb, _erbout, file)
72
- _erbout.concat(erb.result(binding))
70
+
71
+ def again(erb, erbout, file)
72
+ erbout.concat(erb.result(binding))
73
73
  end
74
74
 
75
75
  def children(dir)
@@ -119,4 +119,3 @@ if(ENV['ARUBA_REPORT_DIR'])
119
119
  end
120
120
  end
121
121
  end
122
-
@@ -12,7 +12,7 @@ describe Aruba::Api do
12
12
  include Aruba::Api
13
13
 
14
14
  def set_tag(tag_name, value)
15
- self.instance_variable_set "@#{tag_name.to_s}", value
15
+ self.instance_variable_set "@#{tag_name}", value
16
16
  end
17
17
 
18
18
  def announce_or_puts(*args)
@@ -25,7 +25,7 @@ describe Aruba::Api do
25
25
  @file_size = 256
26
26
  @file_path = File.join(@aruba.current_dir, @file_name)
27
27
 
28
- (@aruba.dirs.length-1).times do |depth| #Ensure all parent dirs exists
28
+ (@aruba.dirs.length - 1).times do |depth| #Ensure all parent dirs exists
29
29
  dir = File.join(*@aruba.dirs[0..depth])
30
30
  Dir.mkdir(dir) unless File.exist?(dir)
31
31
  end
@@ -40,26 +40,36 @@ describe Aruba::Api do
40
40
  end
41
41
 
42
42
  it "can be cleared" do
43
- write_file( 'test', 'test test test' )
43
+ write_file('test', 'test test test')
44
44
 
45
45
  in_current_dir do
46
- expect( File.exist? 'test' ).to be_truthy
46
+ expect(File.exist?('test')).to be_truthy
47
47
  end
48
48
 
49
49
  clean_current_dir
50
50
 
51
51
  in_current_dir do
52
- expect( File.exist? 'test' ).to be_falsey
52
+ expect(File.exist?('test')).to be_falsey
53
53
  end
54
54
 
55
55
  end
56
56
  end
57
57
 
58
58
  describe 'directories' do
59
+ before(:each) do
60
+ @directory_name = 'test_dir'
61
+ @directory_path = File.join(@aruba.current_dir, @directory_name)
62
+ end
63
+
64
+ context '#create_dir' do
65
+ it 'creates a directory' do
66
+ @aruba.create_dir @directory_name
67
+ expect(File.exist?(File.expand_path(@directory_path))).to be_truthy
68
+ end
69
+ end
70
+
59
71
  context '#remove_dir' do
60
- before(:each) do
61
- @directory_name = 'test_dir'
62
- @directory_path = File.join(@aruba.current_dir, @directory_name)
72
+ before :each do
63
73
  Dir.mkdir(@directory_path)
64
74
  end
65
75
 
@@ -82,6 +92,57 @@ describe Aruba::Api do
82
92
  end
83
93
 
84
94
  describe 'files' do
95
+ context '#touch_file' do
96
+ it 'creates an empty file' do
97
+ @aruba.touch_file(@file_name)
98
+ expect(File.exist?(@file_path)).to eq true
99
+ expect(File.size(@file_path)).to eq 0
100
+ end
101
+
102
+ it 'supports an unexisting directory in path' do
103
+ path = 'directory/test'
104
+ full_path = File.join(@aruba.current_dir, path)
105
+ @aruba.touch_file(path)
106
+
107
+ expect(File.exist?(full_path)).to eq true
108
+ end
109
+
110
+ it "works with ~ in path name" do
111
+ file_path = File.join('~', random_string)
112
+
113
+ with_env 'HOME' => File.expand_path(current_dir) do
114
+ @aruba.touch_file(file_path)
115
+ expect(File.exist?(File.expand_path(file_path))).to eq true
116
+ end
117
+ end
118
+ end
119
+
120
+ context '#absolute_path' do
121
+ it 'expands and returns path' do
122
+ expect(@aruba.absolute_path(@file_name)).to eq File.expand_path(@file_path)
123
+ end
124
+
125
+ it 'removes "."' do
126
+ expect(@aruba.absolute_path('.')).to eq File.expand_path(current_dir)
127
+ end
128
+
129
+ it 'removes ".."' do
130
+ expect(@aruba.absolute_path('..')).to eq File.expand_path(File.join(current_dir, '..'))
131
+ end
132
+
133
+ it 'joins multiple arguments' do
134
+ expect(@aruba.absolute_path('path', @file_name)).to eq File.expand_path(File.join(current_dir, 'path', @file_name))
135
+ end
136
+ end
137
+
138
+ context '#write_file' do
139
+ it 'writes file' do
140
+ @aruba.write_file(@file_name, '')
141
+
142
+ expect(File.exist?(@file_path)).to eq true
143
+ end
144
+ end
145
+
85
146
  context '#write_fixed_size_file' do
86
147
  it "should write a fixed sized file" do
87
148
  @aruba.write_fixed_size_file(@file_name, @file_size)
@@ -100,6 +161,7 @@ describe Aruba::Api do
100
161
  end
101
162
  end
102
163
  end
164
+
103
165
  context '#check_file_size' do
104
166
  it "should check an existing file size" do
105
167
  @aruba.write_fixed_size_file(@file_name, @file_size)
@@ -125,6 +187,7 @@ describe Aruba::Api do
125
187
  expect { @aruba.check_file_size([[@file_name, @file_size + 1]]) }.to raise_error
126
188
  end
127
189
  end
190
+
128
191
  context '#filesystem_permissions' do
129
192
  before(:each) { File.open(@file_path, 'w') { |f| f << "" } }
130
193
 
@@ -211,8 +274,10 @@ describe Aruba::Api do
211
274
  FileUtils.mkdir_p File.dirname( file_path )
212
275
  File.open(file_path, 'w') { |f| f << "" }
213
276
 
214
- @aruba.check_file_presence( [ file_name ], true )
215
- @aruba.check_file_presence( [ 'asdf' ] , false )
277
+ @aruba.check_file_presence(file_name)
278
+ @aruba.check_file_presence([file_name])
279
+ @aruba.check_file_presence([file_name], true)
280
+ @aruba.check_file_presence(['asdf'], false)
216
281
  end
217
282
 
218
283
  it "should check existence using regex" do
@@ -251,25 +316,70 @@ describe Aruba::Api do
251
316
  end
252
317
  end
253
318
 
254
- context "#check_file_content" do
255
- before :each do
319
+ context "check file content" do
320
+ before :example do
256
321
  @aruba.write_file(@file_name, "foo bar baz")
257
322
  end
258
323
 
259
- it "succeeds if file content matches" do
260
- @aruba.check_file_content(@file_name, "foo bar baz", true)
261
- end
324
+ context "#check_binary_file_content" do
325
+ it "succeeds if file content matches" do
326
+ @aruba.write_file("fixture", "foo bar baz")
327
+ @aruba.check_binary_file_content(@file_name, "fixture")
328
+ @aruba.check_binary_file_content(@file_name, "fixture", true)
329
+ end
330
+
331
+ it "succeeds if file content does not match" do
332
+ @aruba.write_file("wrong_fixture", "bar")
333
+ @aruba.check_binary_file_content(@file_name, "wrong_fixture", false)
334
+ end
262
335
 
263
- it "succeeds if file content does not match" do
264
- @aruba.check_file_content(@file_name, "hello world", false)
336
+ it "raises if file does not exist" do
337
+ expect{@aruba.check_binary_file_content(@file_name, "non_existing", false)}.to raise_error
338
+ end
265
339
  end
266
340
 
267
- it "works with ~ in path name" do
268
- file_path = File.join('~', random_string)
341
+ context "#check_file_content" do
342
+ context "with regexp" do
343
+ let(:matching_content){/bar/}
344
+ let(:non_matching_content){/nothing/}
345
+ it "succeeds if file content matches" do
346
+ @aruba.check_file_content(@file_name, matching_content)
347
+ @aruba.check_file_content(@file_name, matching_content, true)
348
+ end
269
349
 
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)
350
+ it "succeeds if file content does not match" do
351
+ @aruba.check_file_content(@file_name, non_matching_content, false)
352
+ end
353
+
354
+ it "works with ~ in path name" do
355
+ file_path = File.join('~', random_string)
356
+
357
+ with_env 'HOME' => File.expand_path(current_dir) do
358
+ @aruba.write_file(file_path, "foo bar baz")
359
+ @aruba.check_file_content(file_path, non_matching_content, false)
360
+ end
361
+ end
362
+ end
363
+ context "with string" do
364
+ let(:matching_content){"foo bar baz"}
365
+ let(:non_matching_content){"bar"}
366
+ it "succeeds if file content matches" do
367
+ @aruba.check_file_content(@file_name, matching_content)
368
+ @aruba.check_file_content(@file_name, matching_content, true)
369
+ end
370
+
371
+ it "succeeds if file content does not match" do
372
+ @aruba.check_file_content(@file_name, non_matching_content, false)
373
+ end
374
+
375
+ it "works with ~ in path name" do
376
+ file_path = File.join('~', random_string)
377
+
378
+ with_env 'HOME' => File.expand_path(current_dir) do
379
+ @aruba.write_file(file_path, "foo bar baz")
380
+ @aruba.check_file_content(file_path, non_matching_content, false)
381
+ end
382
+ end
273
383
  end
274
384
  end
275
385
  end
@@ -301,8 +411,8 @@ describe Aruba::Api do
301
411
  it "is successful when the inner expectations match" do
302
412
  expect do
303
413
  @aruba.with_file_content @file_name do |full_content|
304
- expect(full_content).to match /foo/
305
- expect(full_content).not_to match /zoo/
414
+ expect(full_content).to match(/foo/)
415
+ expect(full_content).not_to match(/zoo/)
306
416
  end
307
417
  end . not_to raise_error
308
418
  end
@@ -310,8 +420,8 @@ describe Aruba::Api do
310
420
  it "raises RSpec::Expectations::ExpectationNotMetError when the inner expectations don't match" do
311
421
  expect do
312
422
  @aruba.with_file_content @file_name do |full_content|
313
- expect(full_content).to match /zoo/
314
- expect(full_content).not_to match /foo/
423
+ expect(full_content).to match(/zoo/)
424
+ expect(full_content).not_to match(/foo/)
315
425
  end
316
426
  end . to raise_error RSpec::Expectations::ExpectationNotMetError
317
427
  end
@@ -444,5 +554,4 @@ describe Aruba::Api do
444
554
  expect(@aruba.all_output).not_to include("LONG_LONG_ENV_VARIABLE")
445
555
  end
446
556
  end
447
-
448
557
  end # Aruba::Api
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'aruba/config'
3
3
  require 'aruba/api'
4
- include Aruba::Api
5
4
 
6
5
  describe "Aruba JRuby Startup Helper" do
7
6
  before(:all) do
@@ -9,29 +8,32 @@ describe "Aruba JRuby Startup Helper" do
9
8
  end
10
9
  before(:each) do
11
10
  Aruba.config = Aruba::Config.new
11
+
12
12
  @fake_env['JRUBY_OPTS'] = "--1.9"
13
13
  @fake_env['JAVA_OPTS'] = "-Xdebug"
14
+
15
+ stub_const('ENV', @fake_env)
14
16
  end
15
17
 
16
18
  it 'configuration does not load when RUBY_PLATFORM is not java' do
17
- with_constants :ENV => @fake_env, :RUBY_PLATFORM => 'x86_64-chocolate' do
18
- load 'aruba/jruby.rb'
19
- Aruba.config.hooks.execute :before_cmd, self
20
- expect(ENV['JRUBY_OPTS']).to eq "--1.9"
21
- expect(ENV['JAVA_OPTS']).to eq "-Xdebug"
22
- end
19
+ stub_const('RUBY_PLATFORM', 'x86_64-chocolate')
20
+
21
+ load 'aruba/jruby.rb'
22
+ Aruba.config.hooks.execute :before_cmd, self
23
+ expect(ENV['JRUBY_OPTS']).to eq "--1.9"
24
+ expect(ENV['JAVA_OPTS']).to eq "-Xdebug"
23
25
  end
24
26
 
25
27
  it 'configuration loads for java and merges existing environment variables' do
26
- with_constants :ENV => @fake_env, :RUBY_PLATFORM => 'java' do
27
- rb_config = double('rb_config')
28
- allow(rb_config).to receive(:[]).and_return('solaris')
29
- stub_const 'RbConfig::CONFIG', rb_config
30
-
31
- load 'aruba/jruby.rb'
32
- Aruba.config.hooks.execute :before_cmd, self
33
- expect(ENV['JRUBY_OPTS']).to eq "-X-C --1.9"
34
- expect(ENV['JAVA_OPTS']).to eq "-d32 -Xdebug"
35
- end
28
+ stub_const('RUBY_PLATFORM', 'java')
29
+
30
+ rb_config = double('rb_config')
31
+ allow(rb_config).to receive(:[]).and_return('solaris')
32
+ stub_const 'RbConfig::CONFIG', rb_config
33
+
34
+ load 'aruba/jruby.rb'
35
+ Aruba.config.hooks.execute :before_cmd, self
36
+ expect(ENV['JRUBY_OPTS']).to eq "-X-C --1.9"
37
+ expect(ENV['JAVA_OPTS']).to eq "-d32 -Xdebug"
36
38
  end
37
39
  end