summaryrefslogtreecommitdiffstats
path: root/spec/unit/util
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-01-19 13:40:40 -0800
committerLuke Kanies <luke@madstop.com>2008-01-19 13:40:40 -0800
commitf98be4a7198326b26f1072c401b3e337f340db40 (patch)
tree36a3f5637a175bc7da7acb639857bf2c2ca9f0c3 /spec/unit/util
parent2cbab2c6916d6bd7c5ad01b137b3469eeea8d3e4 (diff)
Fixing #976 -- both the full name of qualified classes and
the class parts are now added as tags. I've also created a Tagging module that we should push throughout the rest of the system that uses tags.
Diffstat (limited to 'spec/unit/util')
-rwxr-xr-xspec/unit/util/tagging.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/unit/util/tagging.rb b/spec/unit/util/tagging.rb
new file mode 100755
index 000000000..51b69a63c
--- /dev/null
+++ b/spec/unit/util/tagging.rb
@@ -0,0 +1,79 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2008-01-19.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/util/tagging'
+
+describe Puppet::Util::Tagging, "when adding tags" do
+ before do
+ @tagger = Object.new
+ @tagger.extend(Puppet::Util::Tagging)
+ end
+
+ it "should have a method for adding tags" do
+ @tagger.should be_respond_to(:tag)
+ end
+
+ it "should have a method for returning all tags" do
+ @tagger.should be_respond_to(:tags)
+ end
+
+ it "should add tags to the returned tag list" do
+ @tagger.tag("one")
+ @tagger.tags.should be_include("one")
+ end
+
+ it "should not add duplicate tags to the returned tag list" do
+ @tagger.tag("one")
+ @tagger.tag("one")
+ @tagger.tags.should == ["one"]
+ end
+
+ it "should return a duplicate of the tag list, rather than the original" do
+ @tagger.tag("one")
+ tags = @tagger.tags
+ tags << "two"
+ @tagger.tags.should_not be_include("two")
+ end
+
+ it "should add all provided tags to the tag list" do
+ @tagger.tag("one", "two")
+ @tagger.tags.should be_include("one")
+ @tagger.tags.should be_include("two")
+ end
+
+ it "should fail on tags containing '*' characters" do
+ lambda { @tagger.tag("bad*tag") }.should raise_error(Puppet::ParseError)
+ end
+
+ it "should fail on tags starting with '-' characters" do
+ lambda { @tagger.tag("-badtag") }.should raise_error(Puppet::ParseError)
+ end
+
+ it "should fail on tags containing ' ' characters" do
+ lambda { @tagger.tag("bad tag") }.should raise_error(Puppet::ParseError)
+ end
+
+ it "should allow alpha tags" do
+ lambda { @tagger.tag("good_tag") }.should_not raise_error(Puppet::ParseError)
+ end
+
+ it "should provide a method for testing tag validity" do
+ @tagger.metaclass.publicize_methods(:valid_tag?) { @tagger.should be_respond_to(:valid_tag?) }
+ end
+
+ it "should add qualified classes as tags" do
+ @tagger.tag("one::two")
+ @tagger.tags.should be_include("one::two")
+ end
+
+ it "should add each part of qualified classes as tags" do
+ @tagger.tag("one::two::three")
+ @tagger.tags.should be_include("one")
+ @tagger.tags.should be_include("two")
+ @tagger.tags.should be_include("three")
+ end
+end