spec/libvirt-ruby/domain_spec.rb in libvirt-ruby-0.0.2 vs spec/libvirt-ruby/domain_spec.rb in libvirt-ruby-0.0.3
- old
+ new
@@ -2,31 +2,47 @@
describe Libvirt::Ruby::Domain do
let(:domain) { Libvirt::Ruby::Domain }
context "when calling method #dispatcher" do
- context "with a valid libvirt function" do
+ context "with libvirt installed" do
before :each do
- domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
- domain.stub(:send).with("virDomainCreate", [])
+ domain.stub(:ffi_lib).with("libvirt")
end
- after :each do
- domain.dispatcher('Create', [:int])
- end
+ context "and a valid libvirt function" do
+ before :each do
+ domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
+ domain.stub(:send).with("virDomainCreate", [])
+ end
- it "should attach it as a binding for C's function" do
- domain.should_receive(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
+ after :each do
+ domain.dispatcher('Create', [], :int)
+ end
+
+ it "should attach it as a binding for C's function" do
+ domain.should_receive(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
+ end
+
+ it "should call the new attached method" do
+ domain.should_receive(:send).with("virDomainCreate", [])
+ end
end
- it "should call the new attached method" do
- domain.should_receive(:send).with("virDomainCreate", [])
+ context "and an invalid libvirt function" do
+ before :each do
+ domain.stub(:attach_function).with("virDomainAbc", "virDomainAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
+ end
+
+ it "should raise an exception" do
+ lambda { domain.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
+ end
end
end
- context "with an invalid libvirt function" do
- it "should return an invalid function message" do
- lambda { domain.dispatcher('Abc', [:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
+ context "without libvirt installed" do
+ it "should raise an exception" do
+ lambda { domain.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
end
end
end
end
\ No newline at end of file