1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
require 'spec_helper'
describe Puppet::Parser::AST::Leaf do
before :each do
node = Puppet::Node.new('localhost')
compiler = Puppet::Parser::Compiler.new(node)
@scope = Puppet::Parser::Scope.new(compiler)
@value = double('value')
@leaf = Puppet::Parser::AST::Leaf.new(:value => @value)
end
describe "when converting to string" do
it "should transform its value to string" do
value = double('value', :is_a? => true)
expect(value).to receive(:to_s)
Puppet::Parser::AST::Leaf.new( :value => value ).to_s
end
end
it "should have a match method" do
expect(@leaf).to respond_to(:match)
end
it "should delegate match to ==" do
expect(@value).to receive(:==).with("value")
@leaf.match("value")
end
end
describe Puppet::Parser::AST::Regex do
before :each do
node = Puppet::Node.new('localhost')
compiler = Puppet::Parser::Compiler.new(node)
@scope = Puppet::Parser::Scope.new(compiler)
end
describe "when initializing" do
it "should create a Regexp with its content when value is not a Regexp" do
expect(Regexp).to receive(:new).with("/ab/")
Puppet::Parser::AST::Regex.new :value => "/ab/"
end
it "should not create a Regexp with its content when value is a Regexp" do
value = Regexp.new("/ab/")
expect(Regexp).not_to receive(:new).with("/ab/")
Puppet::Parser::AST::Regex.new :value => value
end
end
describe "when evaluating" do
it "should return self" do
val = Puppet::Parser::AST::Regex.new :value => "/ab/"
expect(val.evaluate(@scope)).to be === val
end
end
it 'should return the PRegexpType#regexp_to_s_with_delimiters with to_s' do
regex = double('regex')
allow(Regexp).to receive(:new).and_return(regex)
val = Puppet::Parser::AST::Regex.new :value => '/ab/'
expect(Puppet::Pops::Types::PRegexpType).to receive(:regexp_to_s_with_delimiters)
val.to_s
end
it "should delegate match to the underlying regexp match method" do
regex = Regexp.new("/ab/")
val = Puppet::Parser::AST::Regex.new :value => regex
expect(regex).to receive(:match).with("value")
val.match("value")
end
end
describe Puppet::Parser::AST::HostName do
before :each do
node = Puppet::Node.new('localhost')
compiler = Puppet::Parser::Compiler.new(node)
@scope = Puppet::Parser::Scope.new(compiler)
@value = 'value'
allow(@value).to receive(:to_s).and_return(@value)
allow(@value).to receive(:downcase).and_return(@value)
@host = Puppet::Parser::AST::HostName.new(:value => @value)
end
it "should raise an error if hostname is not valid" do
expect { Puppet::Parser::AST::HostName.new( :value => "not a hostname!" ) }.to raise_error(Puppet::DevError, /'not a hostname!' is not a valid hostname/)
end
it "should not raise an error if hostname is a regex" do
expect { Puppet::Parser::AST::HostName.new( :value => Puppet::Parser::AST::Regex.new(:value => "/test/") ) }.not_to raise_error
end
it "should stringify the value" do
value = double('value', :=~ => false)
expect(value).to receive(:to_s).and_return("test")
Puppet::Parser::AST::HostName.new(:value => value)
end
it "should downcase the value" do
value = double('value', :=~ => false)
allow(value).to receive(:to_s).and_return("UPCASED")
host = Puppet::Parser::AST::HostName.new(:value => value)
host.value == "upcased"
end
it "should evaluate to its value" do
expect(@host.evaluate(@scope)).to eq(@value)
end
it "should delegate eql? to the underlying value if it is an HostName" do
expect(@value).to receive(:eql?).with("value")
@host.eql?("value")
end
it "should delegate eql? to the underlying value if it is not an HostName" do
value = double('compared', :is_a? => true, :value => "value")
expect(@value).to receive(:eql?).with("value")
@host.eql?(value)
end
it "should delegate hash to the underlying value" do
expect(@value).to receive(:hash)
@host.hash
end
end
|