libvirt-ruby 0.0.4 → 0.0.5
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.
- data/README.rdoc +9 -4
- data/lib/libvirt-ruby/util.rb +15 -0
- data/lib/libvirt-ruby/version.rb +1 -1
- data/spec/libvirt-ruby/connect_spec.rb +75 -1
- data/spec/libvirt-ruby/domain_spec.rb +74 -0
- data/spec/libvirt-ruby/network_spec.rb +74 -0
- data/spec/libvirt-ruby/storage_pool_spec.rb +74 -0
- data/spec/libvirt-ruby/storage_vol_spec.rb +74 -0
- metadata +10 -10
data/README.rdoc
CHANGED
@@ -12,7 +12,13 @@ This gem has as a dependencie the libvirt package. Google it and u will find how
|
|
12
12
|
|
13
13
|
== Usage
|
14
14
|
|
15
|
-
You should one of the classes defined and call method
|
15
|
+
You should use one of the classes defined and call the method directly:
|
16
|
+
Libvirt::Ruby::Connect.Close([:int])
|
17
|
+
|
18
|
+
The parameter of the function should be an array where the last instance is the return of the C function.
|
19
|
+
|
20
|
+
|
21
|
+
The old method dispatcher still can be called, but is now deprecated. Call dispatcher passing as parameters:
|
16
22
|
first -> the method just like the one from Libvirt in C as a string except the vir and the name of the Class just like 'Close' from 'virConnectClose'
|
17
23
|
second -> the args of the function in C in the same order
|
18
24
|
third -> a symbol of the retun of the function.
|
@@ -30,10 +36,9 @@ Give it a try in another distro and let me know if it works.
|
|
30
36
|
|
31
37
|
Add Support for a ton of thigs. =D
|
32
38
|
Improve a lot of things:
|
33
|
-
*
|
34
|
-
* Find a way to make the test suit pass without the lib. By now it only works if u have it installed.
|
39
|
+
* Remove all classes and make gem wotk without them. Using Just one class: Libvirt::Ruby
|
35
40
|
* Create more Exceptions for another type of errors.
|
36
|
-
* Create pages on Wiki teaching how to
|
41
|
+
* Create pages on Wiki teaching how to install libvirt on several distros.
|
37
42
|
...
|
38
43
|
|
39
44
|
== Contribute
|
data/lib/libvirt-ruby/util.rb
CHANGED
@@ -3,7 +3,16 @@ module Libvirt
|
|
3
3
|
class Util
|
4
4
|
extend FFI::Library
|
5
5
|
|
6
|
+
def self.method_missing(method, *args)
|
7
|
+
args.flatten!
|
8
|
+
return_type = args.delete(args.last)
|
9
|
+
dispatcher(method, args, return_type)
|
10
|
+
end
|
11
|
+
|
6
12
|
def self.dispatcher(method, args = [], return_type = nil)
|
13
|
+
unless not_direct_call?
|
14
|
+
warn "[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead."
|
15
|
+
end
|
7
16
|
begin
|
8
17
|
ffi_lib "libvirt"
|
9
18
|
attach_function (self.klass + method.to_s), (self.klass + method.to_s), args, return_type
|
@@ -14,6 +23,12 @@ module Libvirt
|
|
14
23
|
raise Libvirt::Ruby::Exceptions::MissingLib
|
15
24
|
end
|
16
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.not_direct_call?
|
30
|
+
caller[1][/`.*'/][1..-2] == 'method_missing'
|
31
|
+
end
|
17
32
|
end
|
18
33
|
end
|
19
34
|
end
|
data/lib/libvirt-ruby/version.rb
CHANGED
@@ -4,14 +4,28 @@ describe Libvirt::Ruby::Connect do
|
|
4
4
|
let(:connect) { Libvirt::Ruby::Connect }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
+
context "that is now deprecated" do
|
8
|
+
before :each do
|
9
|
+
connect.stub(:ffi_lib).with("libvirt")
|
10
|
+
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int)
|
11
|
+
connect.stub(:send).with("virConnectClose", [])
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should raise a deprecated method warning" do
|
15
|
+
connect.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
+
connect.dispatcher('Close', [], :int)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
context "with libvirt installed" do
|
8
21
|
before :each do
|
22
|
+
connect.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
9
23
|
connect.stub(:ffi_lib).with("libvirt")
|
10
24
|
end
|
11
25
|
|
12
26
|
context "and a valid libvirt function" do
|
13
27
|
before :each do
|
14
|
-
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int)
|
28
|
+
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int)
|
15
29
|
connect.stub(:send).with("virConnectClose", [])
|
16
30
|
end
|
17
31
|
|
@@ -40,9 +54,69 @@ describe Libvirt::Ruby::Connect do
|
|
40
54
|
end
|
41
55
|
|
42
56
|
context "without libvirt installed" do
|
57
|
+
before :each do
|
58
|
+
connect.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
+
end
|
60
|
+
|
43
61
|
it "should raise an exception" do
|
44
62
|
lambda { connect.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
45
63
|
end
|
46
64
|
end
|
47
65
|
end
|
66
|
+
|
67
|
+
context "when calling any libvirt function directly" do
|
68
|
+
context "that is the new way" do
|
69
|
+
before :each do
|
70
|
+
connect.stub(:ffi_lib).with("libvirt")
|
71
|
+
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int)
|
72
|
+
connect.stub(:send).with("virConnectClose", [])
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not raise a deprecated method warning" do
|
76
|
+
connect.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
+
connect.Close([:int])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with libvirt installed" do
|
82
|
+
before :each do
|
83
|
+
connect.stub(:ffi_lib).with("libvirt")
|
84
|
+
end
|
85
|
+
|
86
|
+
context "and the function is a valid one" do
|
87
|
+
before :each do
|
88
|
+
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
|
89
|
+
connect.stub(:send).with("virConnectClose", [])
|
90
|
+
end
|
91
|
+
|
92
|
+
after :each do
|
93
|
+
connect.Close([:int])
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should attach it as a binding for C's function" do
|
97
|
+
connect.should_receive(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call the new attached method" do
|
101
|
+
connect.should_receive(:send).with("virConnectClose", [])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "and the function is not a valid one" do
|
106
|
+
before :each do
|
107
|
+
connect.stub(:attach_function).with("virConnectAbc", "virConnectAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should raise an exception" do
|
111
|
+
lambda { connect.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "without libvirt installed" do
|
117
|
+
it "should raise an exception" do
|
118
|
+
lambda { connect.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
48
122
|
end
|
@@ -4,8 +4,22 @@ describe Libvirt::Ruby::Domain do
|
|
4
4
|
let(:domain) { Libvirt::Ruby::Domain }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
+
context "that is now deprecated" do
|
8
|
+
before :each do
|
9
|
+
domain.stub(:ffi_lib).with("libvirt")
|
10
|
+
domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int)
|
11
|
+
domain.stub(:send).with("virDomainCreate", [])
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should raise a deprecated method warning" do
|
15
|
+
domain.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
+
domain.dispatcher('Create', [], :int)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
context "with libvirt installed" do
|
8
21
|
before :each do
|
22
|
+
domain.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
9
23
|
domain.stub(:ffi_lib).with("libvirt")
|
10
24
|
end
|
11
25
|
|
@@ -40,9 +54,69 @@ describe Libvirt::Ruby::Domain do
|
|
40
54
|
end
|
41
55
|
|
42
56
|
context "without libvirt installed" do
|
57
|
+
before :each do
|
58
|
+
domain.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
+
end
|
60
|
+
|
43
61
|
it "should raise an exception" do
|
44
62
|
lambda { domain.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
45
63
|
end
|
46
64
|
end
|
47
65
|
end
|
66
|
+
|
67
|
+
context "when calling any libvirt function directly" do
|
68
|
+
context "that is the new way" do
|
69
|
+
before :each do
|
70
|
+
domain.stub(:ffi_lib).with("libvirt")
|
71
|
+
domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int)
|
72
|
+
domain.stub(:send).with("virDomainCreate", [])
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not raise a deprecated method warning" do
|
76
|
+
domain.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
+
domain.Create([:int])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with libvirt installed" do
|
82
|
+
before :each do
|
83
|
+
domain.stub(:ffi_lib).with("libvirt")
|
84
|
+
end
|
85
|
+
|
86
|
+
context "and the function is a valid one" do
|
87
|
+
before :each do
|
88
|
+
domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
|
89
|
+
domain.stub(:send).with("virDomainCreate", [])
|
90
|
+
end
|
91
|
+
|
92
|
+
after :each do
|
93
|
+
domain.Create([:int])
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should attach it as a binding for C's function" do
|
97
|
+
domain.should_receive(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call the new attached method" do
|
101
|
+
domain.should_receive(:send).with("virDomainCreate", [])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "and the function is not a valid one" do
|
106
|
+
before :each do
|
107
|
+
domain.stub(:attach_function).with("virDomainAbc", "virDomainAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should raise an exception" do
|
111
|
+
lambda { domain.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "without libvirt installed" do
|
117
|
+
it "should raise an exception" do
|
118
|
+
lambda { domain.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
48
122
|
end
|
@@ -4,8 +4,22 @@ describe Libvirt::Ruby::Network do
|
|
4
4
|
let(:network) { Libvirt::Ruby::Network }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
+
context "that is now deprecated" do
|
8
|
+
before :each do
|
9
|
+
network.stub(:ffi_lib).with("libvirt")
|
10
|
+
network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int)
|
11
|
+
network.stub(:send).with("virNetworkRef", [])
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should raise a deprecated method warning" do
|
15
|
+
network.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
+
network.dispatcher('Ref', [], :int)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
context "with libvirt installed" do
|
8
21
|
before :each do
|
22
|
+
network.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
9
23
|
network.stub(:ffi_lib).with("libvirt")
|
10
24
|
end
|
11
25
|
|
@@ -40,9 +54,69 @@ describe Libvirt::Ruby::Network do
|
|
40
54
|
end
|
41
55
|
|
42
56
|
context "without libvirt installed" do
|
57
|
+
before :each do
|
58
|
+
network.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
+
end
|
60
|
+
|
43
61
|
it "should raise an exception" do
|
44
62
|
lambda { network.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
45
63
|
end
|
46
64
|
end
|
47
65
|
end
|
66
|
+
|
67
|
+
context "when calling any libvirt function directly" do
|
68
|
+
context "that is the new way" do
|
69
|
+
before :each do
|
70
|
+
network.stub(:ffi_lib).with("libvirt")
|
71
|
+
network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int)
|
72
|
+
network.stub(:send).with("virNetworkRef", [])
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not raise a deprecated method warning" do
|
76
|
+
network.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
+
network.Ref([:int])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with libvirt installed" do
|
82
|
+
before :each do
|
83
|
+
network.stub(:ffi_lib).with("libvirt")
|
84
|
+
end
|
85
|
+
|
86
|
+
context "and the function is a valid one" do
|
87
|
+
before :each do
|
88
|
+
network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
|
89
|
+
network.stub(:send).with("virNetworkRef", [])
|
90
|
+
end
|
91
|
+
|
92
|
+
after :each do
|
93
|
+
network.Ref([:int])
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should attach it as a binding for C's function" do
|
97
|
+
network.should_receive(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call the new attached method" do
|
101
|
+
network.should_receive(:send).with("virNetworkRef", [])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "and the function is not a valid one" do
|
106
|
+
before :each do
|
107
|
+
network.stub(:attach_function).with("virNetworkAbc", "virNetworkAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should raise an exception" do
|
111
|
+
lambda { network.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "without libvirt installed" do
|
117
|
+
it "should raise an exception" do
|
118
|
+
lambda { network.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
48
122
|
end
|
@@ -4,8 +4,22 @@ describe Libvirt::Ruby::StoragePool do
|
|
4
4
|
let(:storage_pool) { Libvirt::Ruby::StoragePool }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
+
context "that is now deprecated" do
|
8
|
+
before :each do
|
9
|
+
storage_pool.stub(:ffi_lib).with("libvirt")
|
10
|
+
storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int)
|
11
|
+
storage_pool.stub(:send).with("virStoragePoolRefresh", [])
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should raise a deprecated method warning" do
|
15
|
+
storage_pool.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
+
storage_pool.dispatcher('Refresh', [], :int)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
context "with libvirt installed" do
|
8
21
|
before :each do
|
22
|
+
storage_pool.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
9
23
|
storage_pool.stub(:ffi_lib).with("libvirt")
|
10
24
|
end
|
11
25
|
|
@@ -40,9 +54,69 @@ describe Libvirt::Ruby::StoragePool do
|
|
40
54
|
end
|
41
55
|
|
42
56
|
context "without libvirt installed" do
|
57
|
+
before :each do
|
58
|
+
storage_pool.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
+
end
|
60
|
+
|
43
61
|
it "should raise an exception" do
|
44
62
|
lambda { storage_pool.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
45
63
|
end
|
46
64
|
end
|
47
65
|
end
|
66
|
+
|
67
|
+
context "when calling any libvirt function directly" do
|
68
|
+
context "that is the new way" do
|
69
|
+
before :each do
|
70
|
+
storage_pool.stub(:ffi_lib).with("libvirt")
|
71
|
+
storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int)
|
72
|
+
storage_pool.stub(:send).with("virStoragePoolRefresh", [])
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not raise a deprecated method warning" do
|
76
|
+
storage_pool.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
+
storage_pool.Refresh([:int])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with libvirt installed" do
|
82
|
+
before :each do
|
83
|
+
storage_pool.stub(:ffi_lib).with("libvirt")
|
84
|
+
end
|
85
|
+
|
86
|
+
context "and the function is a valid one" do
|
87
|
+
before :each do
|
88
|
+
storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
|
89
|
+
storage_pool.stub(:send).with("virStoragePoolRefresh", [])
|
90
|
+
end
|
91
|
+
|
92
|
+
after :each do
|
93
|
+
storage_pool.Refresh([:int])
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should attach it as a binding for C's function" do
|
97
|
+
storage_pool.should_receive(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call the new attached method" do
|
101
|
+
storage_pool.should_receive(:send).with("virStoragePoolRefresh", [])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "and the function is not a valid one" do
|
106
|
+
before :each do
|
107
|
+
storage_pool.stub(:attach_function).with("virStoragePoolAbc", "virStoragePoolAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should raise an exception" do
|
111
|
+
lambda { storage_pool.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "without libvirt installed" do
|
117
|
+
it "should raise an exception" do
|
118
|
+
lambda { storage_pool.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
48
122
|
end
|
@@ -4,8 +4,22 @@ describe Libvirt::Ruby::StorageVol do
|
|
4
4
|
let(:storage_vol) { Libvirt::Ruby::StorageVol }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
+
context "that is now deprecated" do
|
8
|
+
before :each do
|
9
|
+
storage_vol.stub(:ffi_lib).with("libvirt")
|
10
|
+
storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int)
|
11
|
+
storage_vol.stub(:send).with("virStorageVolResize", [])
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should raise a deprecated method warning" do
|
15
|
+
storage_vol.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
+
storage_vol.dispatcher('Resize', [], :int)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
context "with libvirt installed" do
|
8
21
|
before :each do
|
22
|
+
storage_vol.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
9
23
|
storage_vol.stub(:ffi_lib).with("libvirt")
|
10
24
|
end
|
11
25
|
|
@@ -40,9 +54,69 @@ describe Libvirt::Ruby::StorageVol do
|
|
40
54
|
end
|
41
55
|
|
42
56
|
context "without libvirt installed" do
|
57
|
+
before :each do
|
58
|
+
storage_vol.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
+
end
|
60
|
+
|
43
61
|
it "should raise an exception" do
|
44
62
|
lambda { storage_vol.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
45
63
|
end
|
46
64
|
end
|
47
65
|
end
|
66
|
+
|
67
|
+
context "when calling method #dispatcher" do
|
68
|
+
context "that is the new way" do
|
69
|
+
before :each do
|
70
|
+
storage_vol.stub(:ffi_lib).with("libvirt")
|
71
|
+
storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int)
|
72
|
+
storage_vol.stub(:send).with("virStorageVolResize", [])
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not raise a deprecated method warning" do
|
76
|
+
storage_vol.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
+
storage_vol.Resize([:int])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with libvirt installed" do
|
82
|
+
before :each do
|
83
|
+
storage_vol.stub(:ffi_lib).with("libvirt")
|
84
|
+
end
|
85
|
+
|
86
|
+
context "and the function is a valid one" do
|
87
|
+
before :each do
|
88
|
+
storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
|
89
|
+
storage_vol.stub(:send).with("virStorageVolResize", [])
|
90
|
+
end
|
91
|
+
|
92
|
+
after :each do
|
93
|
+
storage_vol.Resize([:int])
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should attach it as a binding for C's function" do
|
97
|
+
storage_vol.should_receive(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call the new attached method" do
|
101
|
+
storage_vol.should_receive(:send).with("virStorageVolResize", [])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "and the function is not a valid one" do
|
106
|
+
before :each do
|
107
|
+
storage_vol.stub(:attach_function).with("virStorageVolAbc", "virStorageVolAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should raise an exception" do
|
111
|
+
lambda { storage_vol.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "without libvirt installed" do
|
117
|
+
it "should raise an exception" do
|
118
|
+
lambda { storage_vol.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
48
122
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libvirt-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
|
-
requirement: &
|
16
|
+
requirement: &12021240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *12021240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &12020740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *12020740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &12019800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *12019800
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: fakefs
|
49
|
-
requirement: &
|
49
|
+
requirement: &12019200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *12019200
|
58
58
|
description: Access Libvirt's C Library through ruby classes and methods
|
59
59
|
email: plribeiro3000@gmail.com
|
60
60
|
executables: []
|