From 15abe1709aa52bb45fe228139f4c0352dc8905df Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Tue, 21 Apr 2009 23:53:17 +0200 Subject: Add RSpec unit tests for network rights Signed-off-by: Brice Figureau --- spec/unit/network/rights.rb | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 spec/unit/network/rights.rb diff --git a/spec/unit/network/rights.rb b/spec/unit/network/rights.rb new file mode 100755 index 000000000..5fe8e51f4 --- /dev/null +++ b/spec/unit/network/rights.rb @@ -0,0 +1,54 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/network/rights' + +describe Puppet::Network::Rights do + before do + @right = Puppet::Network::Rights.new + end + + [:allow, :allowed?, :deny].each do |m| + it "should have a #{m} method" do + @right.should respond_to(m) + end + + describe "when using #{m}" do + it "should delegate to the correct acl" do + acl = stub 'acl' + @right.stubs(:right).returns(acl) + + acl.expects(m).with("me") + + @right.send(m, 'thisacl', "me") + end + end + end + + describe "when creating new ACLs" do + it "should throw an error if the ACL already exists" do + @right.newright("name") + + lambda { @right.newright("name")}.should raise_error + end + + it "should create a new ACL with the correct name" do + @right.newright("name") + + @right["name"].name.should == :name + end + + it "should create an ACL of type Puppet::Network::AuthStore" do + @right.newright("name") + + @right["name"].should be_a_kind_of(Puppet::Network::AuthStore) + end + + it "should create an ACL with a shortname" do + @right.newright("name") + + @right["name"].shortname.should == "n" + end + end +end -- cgit