summaryrefslogtreecommitdiffstats
path: root/spec/unit/parameter/value_spec.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-06-28 17:10:20 -0700
committerMarkus Roberts <Markus@reality.com>2010-06-28 17:10:20 -0700
commitfdc8c3509b5ac5bc170c54d72b2c2bafb58409f2 (patch)
tree6ed2204d72c6924e867a1320d3b7e6728035f1a1 /spec/unit/parameter/value_spec.rb
parent9a94ee274c39c261cd49e688a7bd7ea0eb73af50 (diff)
downloadpuppet-fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2.tar.gz
puppet-fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2.tar.xz
puppet-fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2.zip
[#3994-part 3] rename spec tests from *_spec_spec to *_spec.rb
Part 2 re-did the change on the spec files, which it shouldn't have.
Diffstat (limited to 'spec/unit/parameter/value_spec.rb')
-rwxr-xr-xspec/unit/parameter/value_spec.rb88
1 files changed, 88 insertions, 0 deletions
diff --git a/spec/unit/parameter/value_spec.rb b/spec/unit/parameter/value_spec.rb
new file mode 100755
index 000000000..f6def01dd
--- /dev/null
+++ b/spec/unit/parameter/value_spec.rb
@@ -0,0 +1,88 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/parameter'
+
+describe Puppet::Parameter::Value do
+ it "should require a name" do
+ lambda { Puppet::Parameter::Value.new }.should raise_error(ArgumentError)
+ end
+
+ it "should set its name" do
+ Puppet::Parameter::Value.new(:foo).name.should == :foo
+ end
+
+ it "should support regexes as names" do
+ lambda { Puppet::Parameter::Value.new(%r{foo}) }.should_not raise_error
+ end
+
+ it "should mark itself as a regex if its name is a regex" do
+ Puppet::Parameter::Value.new(%r{foo}).should be_regex
+ end
+
+ it "should always convert its name to a symbol if it is not a regex" do
+ Puppet::Parameter::Value.new("foo").name.should == :foo
+ Puppet::Parameter::Value.new(true).name.should == :true
+ end
+
+ it "should support adding aliases" do
+ Puppet::Parameter::Value.new("foo").should respond_to(:alias)
+ end
+
+ it "should be able to return its aliases" do
+ value = Puppet::Parameter::Value.new("foo")
+ value.alias("bar")
+ value.alias("baz")
+ value.aliases.should == [:bar, :baz]
+ end
+
+ [:block, :call, :method, :event, :required_features].each do |attr|
+ it "should support a #{attr} attribute" do
+ value = Puppet::Parameter::Value.new("foo")
+ value.should respond_to(attr.to_s + "=")
+ value.should respond_to(attr)
+ end
+ end
+
+ it "should default to :instead for :call if a block is provided" do
+ Puppet::Parameter::Value.new("foo").call.should == :instead
+ end
+
+ it "should always return events as symbols" do
+ value = Puppet::Parameter::Value.new("foo")
+ value.event = "foo_test"
+ value.event.should == :foo_test
+ end
+
+ describe "when matching" do
+ describe "a regex" do
+ it "should return true if the regex matches the value" do
+ Puppet::Parameter::Value.new(/\w/).should be_match("foo")
+ end
+
+ it "should return false if the regex does not match the value" do
+ Puppet::Parameter::Value.new(/\d/).should_not be_match("foo")
+ end
+ end
+
+ describe "a non-regex" do
+ it "should return true if the value, converted to a symbol, matches the name" do
+ Puppet::Parameter::Value.new("foo").should be_match("foo")
+ Puppet::Parameter::Value.new(:foo).should be_match(:foo)
+ Puppet::Parameter::Value.new(:foo).should be_match("foo")
+ Puppet::Parameter::Value.new("foo").should be_match(:foo)
+ end
+
+ it "should return false if the value, converted to a symbol, does not match the name" do
+ Puppet::Parameter::Value.new(:foo).should_not be_match(:bar)
+ end
+
+ it "should return true if any of its aliases match" do
+ value = Puppet::Parameter::Value.new("foo")
+ value.alias("bar")
+ value.should be_match("bar")
+ end
+ end
+ end
+end