virtualbox 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
@@ -92,15 +92,25 @@ module VirtualBox
92
92
  # has not yet been set, it attempts to infer it based on the
93
93
  # platform ruby is running on.
94
94
  def vboxconfig
95
- return @@vboxconfig unless @@vboxconfig.nil?
96
-
97
- if Platform.mac?
98
- "~/Library/VirtualBox/VirtualBox.xml"
99
- elsif Platform.linux? || Platform.windows?
100
- "~/.VirtualBox/VirtualBox.xml"
101
- else
102
- "Unknown"
95
+ if @@vboxconfig.nil?
96
+ if Platform.mac?
97
+ @@vboxconfig = "~/Library/VirtualBox/VirtualBox.xml"
98
+ elsif Platform.linux? || Platform.windows?
99
+ @@vboxconfig = "~/.VirtualBox/VirtualBox.xml"
100
+ else
101
+ @@vboxconfig = "Unknown"
102
+ end
103
103
  end
104
+
105
+ File.expand_path(@@vboxconfig)
106
+ end
107
+
108
+ # Returns a boolean denoting whether or not the vboxconfig value is
109
+ # valid or not.
110
+ #
111
+ # @return [Boolean]
112
+ def vboxconfig?
113
+ File.file?(vboxconfig)
104
114
  end
105
115
 
106
116
  # Returns the XML document of the configuration. This will raise an
@@ -109,8 +119,8 @@ module VirtualBox
109
119
  #
110
120
  # @return [Nokogiri::XML::Document]
111
121
  def config
112
- raise Exceptions::ConfigurationException.new("The path to the global VirtualBox config must be set. See Global.vboxconfig=") unless File.exist?(File.expand_path(vboxconfig))
113
- Command.parse_xml(File.expand_path(vboxconfig))
122
+ raise Exceptions::ConfigurationException.new("The path to the global VirtualBox config must be set. See Global.vboxconfig=") unless vboxconfig?
123
+ Command.parse_xml(vboxconfig)
114
124
  end
115
125
 
116
126
  # Expands path relative to the configuration file.
data/test/test_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  begin
2
- require File.expand_path('../.bundle/environment', __FILE__)
2
+ require File.expand_path('../../.bundle/environment', __FILE__)
3
3
  rescue LoadError
4
4
  # Fallback on doing the resolve at runtime.
5
5
  require "rubygems"
@@ -12,32 +12,49 @@ class GlobalTest < Test::Unit::TestCase
12
12
 
13
13
  should "return the path if its set" do
14
14
  VirtualBox::Global.vboxconfig = "foo"
15
+ File.expects(:expand_path).with("foo").returns("foo")
15
16
  assert_equal "foo", VirtualBox::Global.vboxconfig
16
17
  end
17
18
 
18
19
  should "return Mac-path if on mac" do
20
+ result = "~/Library/VirtualBox/VirtualBox.xml"
19
21
  VirtualBox::Platform.stubs(:mac?).returns(true)
20
- assert_equal "~/Library/VirtualBox/VirtualBox.xml", VirtualBox::Global.vboxconfig
22
+
23
+ expanded_result = result + result
24
+ File.expects(:expand_path).with(result).returns(expanded_result)
25
+ assert_equal expanded_result, VirtualBox::Global.vboxconfig
21
26
  end
22
27
 
23
28
  should "return Windows-path if on windows" do
29
+ result = "~/.VirtualBox/VirtualBox.xml"
24
30
  VirtualBox::Platform.stubs(:mac?).returns(false)
25
31
  VirtualBox::Platform.stubs(:windows?).returns(true)
26
- assert_equal "~/.VirtualBox/VirtualBox.xml", VirtualBox::Global.vboxconfig
32
+
33
+ expanded_result = result + result
34
+ File.expects(:expand_path).with(result).returns(expanded_result)
35
+ assert_equal expanded_result, VirtualBox::Global.vboxconfig
27
36
  end
28
37
 
29
38
  should "return Linux-path if on linux" do
39
+ result = "~/.VirtualBox/VirtualBox.xml"
30
40
  VirtualBox::Platform.stubs(:mac?).returns(false)
31
41
  VirtualBox::Platform.stubs(:windows?).returns(false)
32
42
  VirtualBox::Platform.stubs(:linux?).returns(true)
33
- assert_equal "~/.VirtualBox/VirtualBox.xml", VirtualBox::Global.vboxconfig
43
+
44
+ expanded_result = result + result
45
+ File.expects(:expand_path).with(result).returns(expanded_result)
46
+ assert_equal expanded_result, VirtualBox::Global.vboxconfig
34
47
  end
35
48
 
36
49
  should "return 'unknown' otherwise" do
50
+ result = "Unknown"
37
51
  VirtualBox::Platform.stubs(:mac?).returns(false)
38
52
  VirtualBox::Platform.stubs(:windows?).returns(false)
39
53
  VirtualBox::Platform.stubs(:linux?).returns(false)
40
- assert_equal "Unknown", VirtualBox::Global.vboxconfig
54
+
55
+ expanded_result = result + result
56
+ File.expects(:expand_path).with(result).returns(expanded_result)
57
+ assert_equal expanded_result, VirtualBox::Global.vboxconfig
41
58
  end
42
59
  end
43
60
 
@@ -63,41 +80,41 @@ class GlobalTest < Test::Unit::TestCase
63
80
  assert !VirtualBox::Global.reload?
64
81
  end
65
82
  end
66
-
67
- context "parsing configuration XML" do
83
+
84
+ context "testingn the config path" do
68
85
  setup do
69
- VirtualBox::Command.stubs(:vboxconfig).returns("foo")
70
- File.stubs(:exist?).returns(true)
71
- VirtualBox::Command.stubs(:parse_xml)
86
+ @result = "foo"
87
+ VirtualBox::Global.stubs(:vboxconfig).returns(@result)
88
+ end
89
+
90
+ should "return true if it is a file" do
91
+ File.expects(:file?).with(@result).returns(true)
92
+ assert VirtualBox::Global.vboxconfig?
93
+ end
94
+
95
+ should "return false if it is not a file" do
96
+ File.expects(:file?).with(@result).returns(false)
97
+ assert !VirtualBox::Global.vboxconfig?
72
98
  end
99
+ end
73
100
 
74
- should "check the file with the expanded path" do
75
- File.stubs(:expand_path).returns("FOO")
76
- File.expects(:exist?).with("FOO").returns(true)
77
- VirtualBox::Global.config
101
+ context "parsing configuration XML" do
102
+ setup do
103
+ @vboxconfig = "foo"
104
+ VirtualBox::Global.stubs(:vboxconfig?).returns(true)
105
+ VirtualBox::Global.stubs(:vboxconfig).returns(@vboxconfig)
78
106
  end
79
107
 
80
- should "raise an error if the config XML doesn't exist" do
81
- File.expects(:exist?).returns(false)
108
+ should "raise an error if the config XML is invalid" do
109
+ VirtualBox::Command.stubs(:parse_xml)
110
+ VirtualBox::Global.expects(:vboxconfig?).returns(false)
82
111
  assert_raises(VirtualBox::Exceptions::ConfigurationException) do
83
112
  VirtualBox::Global.config
84
113
  end
85
114
  end
86
115
 
87
116
  should "use Command.parse_xml to parse" do
88
- VirtualBox::Command.expects(:parse_xml).with(anything).once
89
- VirtualBox::Global.config
90
- end
91
-
92
- should "use the set vboxconfig to parse xml" do
93
- VirtualBox::Global.vboxconfig = "/foo"
94
- VirtualBox::Command.expects(:parse_xml).with("/foo").once
95
- VirtualBox::Global.config
96
- end
97
-
98
- should "file expand path the vboxconfig path" do
99
- VirtualBox::Global.vboxconfig = "foo"
100
- VirtualBox::Command.expects(:parse_xml).with(File.expand_path("foo")).once
117
+ VirtualBox::Command.expects(:parse_xml).with(@vboxconfig).once
101
118
  VirtualBox::Global.config
102
119
  end
103
120
  end
data/virtualbox.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{virtualbox}
8
- s.version = "0.5.3"
8
+ s.version = "0.5.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mitchell Hashimoto"]
12
- s.date = %q{2010-03-16}
12
+ s.date = %q{2010-03-17}
13
13
  s.description = %q{Create and modify virtual machines in VirtualBox using pure ruby.}
14
14
  s.email = %q{mitchell.hashimoto@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 3
9
- version: 0.5.3
8
+ - 4
9
+ version: 0.5.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mitchell Hashimoto
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-16 00:00:00 -07:00
17
+ date: 2010-03-17 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency