let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("abs").should == "function_abs"
+ expect(Puppet::Parser::Functions.function("abs")).to eq("function_abs")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_abs([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert a negative number into a positive" do
result = scope.function_abs(["-34"])
- result.should(eq(34))
+ expect(result).to(eq(34))
end
it "should do nothing with a positive number" do
result = scope.function_abs(["5678"])
- result.should(eq(5678))
+ expect(result).to(eq(5678))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("any2array").should == "function_any2array"
+ expect(Puppet::Parser::Functions.function("any2array")).to eq("function_any2array")
end
it "should return an empty array if there is less than 1 argument" do
result = scope.function_any2array([])
- result.should(eq([]))
+ expect(result).to(eq([]))
end
it "should convert boolean true to [ true ] " do
result = scope.function_any2array([true])
- result.should(eq([true]))
+ expect(result).to(eq([true]))
end
it "should convert one object to [object]" do
result = scope.function_any2array(['one'])
- result.should(eq(['one']))
+ expect(result).to(eq(['one']))
end
it "should convert multiple objects to [objects]" do
result = scope.function_any2array(['one', 'two'])
- result.should(eq(['one', 'two']))
+ expect(result).to(eq(['one', 'two']))
end
it "should return empty array it was called with" do
result = scope.function_any2array([[]])
- result.should(eq([]))
+ expect(result).to(eq([]))
end
it "should return one-member array it was called with" do
result = scope.function_any2array([['string']])
- result.should(eq(['string']))
+ expect(result).to(eq(['string']))
end
it "should return multi-member array it was called with" do
result = scope.function_any2array([['one', 'two']])
- result.should(eq(['one', 'two']))
+ expect(result).to(eq(['one', 'two']))
end
it "should return members of a hash it was called with" do
result = scope.function_any2array([{ 'key' => 'value' }])
- result.should(eq(['key', 'value']))
+ expect(result).to(eq(['key', 'value']))
end
it "should return an empty array if it was called with an empty hash" do
result = scope.function_any2array([{ }])
- result.should(eq([]))
+ expect(result).to(eq([]))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("base64").should == "function_base64"
+ expect(Puppet::Parser::Functions.function("base64")).to eq("function_base64")
end
it "should raise a ParseError if there are other than 2 arguments" do
it "should encode a encoded string" do
result = scope.function_base64(["encode",'thestring'])
- result.should =~ /\AdGhlc3RyaW5n\n\Z/
+ expect(result).to match(/\AdGhlc3RyaW5n\n\Z/)
end
it "should decode a base64 encoded string" do
result = scope.function_base64(["decode",'dGhlc3RyaW5n'])
- result.should == 'thestring'
+ expect(result).to eq('thestring')
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("bool2num").should == "function_bool2num"
+ expect(Puppet::Parser::Functions.function("bool2num")).to eq("function_bool2num")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_bool2num([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert true to 1" do
result = scope.function_bool2num([true])
- result.should(eq(1))
+ expect(result).to(eq(1))
end
it "should convert false to 0" do
result = scope.function_bool2num([false])
- result.should(eq(0))
+ expect(result).to(eq(0))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("capitalize").should == "function_capitalize"
+ expect(Puppet::Parser::Functions.function("capitalize")).to eq("function_capitalize")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_capitalize([]) }.to( raise_error(Puppet::ParseError))
end
it "should capitalize the beginning of a string" do
result = scope.function_capitalize(["abc"])
- result.should(eq("Abc"))
+ expect(result).to(eq("Abc"))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("chomp").should == "function_chomp"
+ expect(Puppet::Parser::Functions.function("chomp")).to eq("function_chomp")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_chomp([]) }.to( raise_error(Puppet::ParseError))
end
it "should chomp the end of a string" do
result = scope.function_chomp(["abc\n"])
- result.should(eq("abc"))
+ expect(result).to(eq("abc"))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("chop").should == "function_chop"
+ expect(Puppet::Parser::Functions.function("chop")).to eq("function_chop")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_chop([]) }.to( raise_error(Puppet::ParseError))
end
it "should chop the end of a string" do
result = scope.function_chop(["asdf\n"])
- result.should(eq("asdf"))
+ expect(result).to(eq("asdf"))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should raise a ParseError if the client does not provide two arguments" do
- lambda { scope.function_concat([]) }.should(raise_error(Puppet::ParseError))
+ expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError))
end
it "should raise a ParseError if the first parameter is not an array" do
- lambda { scope.function_concat([1, []])}.should(raise_error(Puppet::ParseError))
+ expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError))
end
it "should be able to concat an array" do
result = scope.function_concat([['1','2','3'],['4','5','6']])
- result.should(eq(['1','2','3','4','5','6']))
+ expect(result).to(eq(['1','2','3','4','5','6']))
end
it "should be able to concat a primitive to an array" do
result = scope.function_concat([['1','2','3'],'4'])
- result.should(eq(['1','2','3','4']))
+ expect(result).to(eq(['1','2','3','4']))
end
it "should not accidentally flatten nested arrays" do
result = scope.function_concat([['1','2','3'],[['4','5'],'6']])
- result.should(eq(['1','2','3',['4','5'],'6']))
+ expect(result).to(eq(['1','2','3',['4','5'],'6']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("count").should == "function_count"
+ expect(Puppet::Parser::Functions.function("count")).to eq("function_count")
end
it "should raise a ArgumentError if there is more than 2 arguments" do
- lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError))
+ expect { scope.function_count(['foo', 'bar', 'baz']) }.to( raise_error(ArgumentError))
end
it "should be able to count arrays" do
- scope.function_count([["1","2","3"]]).should(eq(3))
+ expect(scope.function_count([["1","2","3"]])).to(eq(3))
end
it "should be able to count matching elements in arrays" do
- scope.function_count([["1", "2", "2"], "2"]).should(eq(2))
+ expect(scope.function_count([["1", "2", "2"], "2"])).to(eq(2))
end
it "should not count nil or empty strings" do
- scope.function_count([["foo","bar",nil,""]]).should(eq(2))
+ expect(scope.function_count([["foo","bar",nil,""]])).to(eq(2))
end
it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do
describe 'when calling deep_merge from puppet' do
it "should not compile when no arguments are passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = '$x = deep_merge()'
expect {
scope.compiler.compile
end
it "should not compile when 1 argument is passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = "$my_hash={'one' => 1}\n$x = deep_merge($my_hash)"
expect {
scope.compiler.compile
it 'should be able to deep_merge two hashes' do
new_hash = scope.function_deep_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
- new_hash['one'].should == '1'
- new_hash['two'].should == '2'
- new_hash['three'].should == '2'
+ expect(new_hash['one']).to eq('1')
+ expect(new_hash['two']).to eq('2')
+ expect(new_hash['three']).to eq('2')
end
it 'should deep_merge multiple hashes' do
hash = scope.function_deep_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
- hash['one'].should == '3'
+ expect(hash['one']).to eq('3')
end
it 'should accept empty hashes' do
- scope.function_deep_merge([{},{},{}]).should == {}
+ expect(scope.function_deep_merge([{},{},{}])).to eq({})
end
it 'should deep_merge subhashes' do
hash = scope.function_deep_merge([{'one' => 1}, {'two' => 2, 'three' => { 'four' => 4 } }])
- hash['one'].should == 1
- hash['two'].should == 2
- hash['three'].should == { 'four' => 4 }
+ expect(hash['one']).to eq(1)
+ expect(hash['two']).to eq(2)
+ expect(hash['three']).to eq({ 'four' => 4 })
end
it 'should append to subhashes' do
hash = scope.function_deep_merge([{'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } }])
- hash['one'].should == { 'two' => 2, 'three' => 3 }
+ expect(hash['one']).to eq({ 'two' => 2, 'three' => 3 })
end
it 'should append to subhashes 2' do
hash = scope.function_deep_merge([{'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, {'two' => 'dos', 'three' => { 'five' => 5 } }])
- hash['one'].should == 1
- hash['two'].should == 'dos'
- hash['three'].should == { 'four' => 4, 'five' => 5 }
+ expect(hash['one']).to eq(1)
+ expect(hash['two']).to eq('dos')
+ expect(hash['three']).to eq({ 'four' => 4, 'five' => 5 })
end
it 'should append to subhashes 3' do
hash = scope.function_deep_merge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }])
- hash['key1'].should == { 'a' => 1, 'b' => 99 }
- hash['key2'].should == { 'c' => 3 }
+ expect(hash['key1']).to eq({ 'a' => 1, 'b' => 99 })
+ expect(hash['key2']).to eq({ 'c' => 3 })
end
it 'should not change the original hashes' do
hash1 = {'one' => { 'two' => 2 } }
hash2 = { 'one' => { 'three' => 3 } }
hash = scope.function_deep_merge([hash1, hash2])
- hash1.should == {'one' => { 'two' => 2 } }
- hash2.should == { 'one' => { 'three' => 3 } }
- hash['one'].should == { 'two' => 2, 'three' => 3 }
+ expect(hash1).to eq({'one' => { 'two' => 2 } })
+ expect(hash2).to eq({ 'one' => { 'three' => 3 } })
+ expect(hash['one']).to eq({ 'two' => 2, 'three' => 3 })
end
it 'should not change the original hashes 2' do
hash1 = {'one' => { 'two' => [1,2] } }
hash2 = { 'one' => { 'three' => 3 } }
hash = scope.function_deep_merge([hash1, hash2])
- hash1.should == {'one' => { 'two' => [1,2] } }
- hash2.should == { 'one' => { 'three' => 3 } }
- hash['one'].should == { 'two' => [1,2], 'three' => 3 }
+ expect(hash1).to eq({'one' => { 'two' => [1,2] } })
+ expect(hash2).to eq({ 'one' => { 'three' => 3 } })
+ expect(hash['one']).to eq({ 'two' => [1,2], 'three' => 3 })
end
it 'should not change the original hashes 3' do
hash1 = {'one' => { 'two' => [1,2, {'two' => 2} ] } }
hash2 = { 'one' => { 'three' => 3 } }
hash = scope.function_deep_merge([hash1, hash2])
- hash1.should == {'one' => { 'two' => [1,2, {'two' => 2}] } }
- hash2.should == { 'one' => { 'three' => 3 } }
- hash['one'].should == { 'two' => [1,2, {'two' => 2} ], 'three' => 3 }
- hash['one']['two'].should == [1,2, {'two' => 2}]
+ expect(hash1).to eq({'one' => { 'two' => [1,2, {'two' => 2}] } })
+ expect(hash2).to eq({ 'one' => { 'three' => 3 } })
+ expect(hash['one']).to eq({ 'two' => [1,2, {'two' => 2} ], 'three' => 3 })
+ expect(hash['one']['two']).to eq([1,2, {'two' => 2}])
end
end
end
require 'rspec-puppet'
describe 'defined_with_params' do
describe 'when a resource is not specified' do
- it { should run.with_params().and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params().and_raise_error(ArgumentError) }
end
describe 'when compared against a resource with no attributes' do
let :pre_condition do
'user { "dan": }'
end
it do
- should run.with_params('User[dan]', {}).and_return(true)
- should run.with_params('User[bob]', {}).and_return(false)
- should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false)
+ is_expected.to run.with_params('User[dan]', {}).and_return(true)
+ is_expected.to run.with_params('User[bob]', {}).and_return(false)
+ is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false)
end
end
'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
end
it do
- should run.with_params('User[dan]', {}).and_return(true)
- should run.with_params('User[dan]', '').and_return(true)
- should run.with_params('User[dan]', {'ensure' => 'present'}
+ is_expected.to run.with_params('User[dan]', {}).and_return(true)
+ is_expected.to run.with_params('User[dan]', '').and_return(true)
+ is_expected.to run.with_params('User[dan]', {'ensure' => 'present'}
).and_return(true)
- should run.with_params('User[dan]',
+ is_expected.to run.with_params('User[dan]',
{'ensure' => 'present', 'managehome' => false}
).and_return(true)
- should run.with_params('User[dan]',
+ is_expected.to run.with_params('User[dan]',
{'ensure' => 'absent', 'managehome' => false}
).and_return(false)
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("delete_at").should == "function_delete_at"
+ expect(Puppet::Parser::Functions.function("delete_at")).to eq("function_delete_at")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_delete_at([]) }.to( raise_error(Puppet::ParseError))
end
it "should delete an item at specified location from an array" do
result = scope.function_delete_at([['a','b','c'],1])
- result.should(eq(['a','c']))
+ expect(result).to(eq(['a','c']))
end
it "should not change origin array passed as argument" do
origin_array = ['a','b','c','d']
result = scope.function_delete_at([origin_array, 1])
- origin_array.should(eq(['a','b','c','d']))
+ expect(origin_array).to(eq(['a','b','c','d']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("delete").should == "function_delete"
+ expect(Puppet::Parser::Functions.function("delete")).to eq("function_delete")
end
it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_delete([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_delete([]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if there are greater than 2 arguments" do
- lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_delete([[], 'foo', 'bar']) }.to( raise_error(Puppet::ParseError))
end
it "should raise a TypeError if a number is passed as the first argument" do
- lambda { scope.function_delete([1, 'bar']) }.should( raise_error(TypeError))
+ expect { scope.function_delete([1, 'bar']) }.to( raise_error(TypeError))
end
it "should delete all instances of an element from an array" do
result = scope.function_delete([['a','b','c','b'],'b'])
- result.should(eq(['a','c']))
+ expect(result).to(eq(['a','c']))
end
it "should delete all instances of a substring from a string" do
result = scope.function_delete(['foobarbabarz','bar'])
- result.should(eq('foobaz'))
+ expect(result).to(eq('foobaz'))
end
it "should delete a key from a hash" do
result = scope.function_delete([{ 'a' => 1, 'b' => 2, 'c' => 3 },'b'])
- result.should(eq({ 'a' => 1, 'c' => 3 }))
+ expect(result).to(eq({ 'a' => 1, 'c' => 3 }))
end
it "should not change origin array passed as argument" do
origin_array = ['a','b','c','d']
result = scope.function_delete([origin_array, 'b'])
- origin_array.should(eq(['a','b','c','d']))
+ expect(origin_array).to(eq(['a','b','c','d']))
end
it "should not change the origin string passed as argument" do
origin_string = 'foobarbabarz'
result = scope.function_delete([origin_string,'bar'])
- origin_string.should(eq('foobarbabarz'))
+ expect(origin_string).to(eq('foobarbabarz'))
end
it "should not change origin hash passed as argument" do
origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 }
result = scope.function_delete([origin_hash, 'b'])
- origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 }))
+ expect(origin_hash).to(eq({ 'a' => 1, 'b' => 2, 'c' => 3 }))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("delete_undef_values").should == "function_delete_undef_values"
+ expect(Puppet::Parser::Functions.function("delete_undef_values")).to eq("function_delete_undef_values")
end
it "should raise a ParseError if there is less than 1 argument" do
- lambda { scope.function_delete_undef_values([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_delete_undef_values([]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if the argument is not Array nor Hash" do
- lambda { scope.function_delete_undef_values(['']) }.should( raise_error(Puppet::ParseError))
- lambda { scope.function_delete_undef_values([nil]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_delete_undef_values(['']) }.to( raise_error(Puppet::ParseError))
+ expect { scope.function_delete_undef_values([nil]) }.to( raise_error(Puppet::ParseError))
end
it "should delete all undef items from Array and only these" do
result = scope.function_delete_undef_values([['a',:undef,'c','undef']])
- result.should(eq(['a','c','undef']))
+ expect(result).to(eq(['a','c','undef']))
end
it "should delete all undef items from Hash and only these" do
result = scope.function_delete_undef_values([{'a'=>'A','b'=>:undef,'c'=>'C','d'=>'undef'}])
- result.should(eq({'a'=>'A','c'=>'C','d'=>'undef'}))
+ expect(result).to(eq({'a'=>'A','c'=>'C','d'=>'undef'}))
end
it "should not change origin array passed as argument" do
origin_array = ['a',:undef,'c','undef']
result = scope.function_delete_undef_values([origin_array])
- origin_array.should(eq(['a',:undef,'c','undef']))
+ expect(origin_array).to(eq(['a',:undef,'c','undef']))
end
it "should not change origin hash passed as argument" do
origin_hash = { 'a' => 1, 'b' => :undef, 'c' => 'undef' }
result = scope.function_delete_undef_values([origin_hash])
- origin_hash.should(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' }))
+ expect(origin_hash).to(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' }))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("delete_values").should == "function_delete_values"
+ expect(Puppet::Parser::Functions.function("delete_values")).to eq("function_delete_values")
end
it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_delete_values([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_delete_values([]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if there are greater than 2 arguments" do
- lambda { scope.function_delete_values([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_delete_values([[], 'foo', 'bar']) }.to( raise_error(Puppet::ParseError))
end
it "should raise a TypeError if the argument is not a hash" do
- lambda { scope.function_delete_values([1,'bar']) }.should( raise_error(TypeError))
- lambda { scope.function_delete_values(['foo','bar']) }.should( raise_error(TypeError))
- lambda { scope.function_delete_values([[],'bar']) }.should( raise_error(TypeError))
+ expect { scope.function_delete_values([1,'bar']) }.to( raise_error(TypeError))
+ expect { scope.function_delete_values(['foo','bar']) }.to( raise_error(TypeError))
+ expect { scope.function_delete_values([[],'bar']) }.to( raise_error(TypeError))
end
it "should delete all instances of a value from a hash" do
result = scope.function_delete_values([{ 'a'=>'A', 'b'=>'B', 'B'=>'C', 'd'=>'B' },'B'])
- result.should(eq({ 'a'=>'A', 'B'=>'C' }))
+ expect(result).to(eq({ 'a'=>'A', 'B'=>'C' }))
end
it "should not change origin hash passed as argument" do
origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 }
result = scope.function_delete_values([origin_hash, 2])
- origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 }))
+ expect(origin_hash).to(eq({ 'a' => 1, 'b' => 2, 'c' => 3 }))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("difference").should == "function_difference"
+ expect(Puppet::Parser::Functions.function("difference")).to eq("function_difference")
end
it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_difference([]) }.should( raise_error(Puppet::ParseError) )
+ expect { scope.function_difference([]) }.to( raise_error(Puppet::ParseError) )
end
it "should return the difference between two arrays" do
result = scope.function_difference([["a","b","c"],["b","c","d"]])
- result.should(eq(["a"]))
+ expect(result).to(eq(["a"]))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("dirname").should == "function_dirname"
+ expect(Puppet::Parser::Functions.function("dirname")).to eq("function_dirname")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_dirname([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_dirname([]) }.to( raise_error(Puppet::ParseError))
end
it "should return dirname for an absolute path" do
result = scope.function_dirname(['/path/to/a/file.ext'])
- result.should(eq('/path/to/a'))
+ expect(result).to(eq('/path/to/a'))
end
it "should return dirname for a relative path" do
result = scope.function_dirname(['path/to/a/file.ext'])
- result.should(eq('path/to/a'))
+ expect(result).to(eq('path/to/a'))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("downcase").should == "function_downcase"
+ expect(Puppet::Parser::Functions.function("downcase")).to eq("function_downcase")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_downcase([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_downcase([]) }.to( raise_error(Puppet::ParseError))
end
it "should downcase a string" do
result = scope.function_downcase(["ASFD"])
- result.should(eq("asfd"))
+ expect(result).to(eq("asfd"))
end
it "should do nothing to a string that is already downcase" do
result = scope.function_downcase(["asdf asdf"])
- result.should(eq("asdf asdf"))
+ expect(result).to(eq("asdf asdf"))
end
end
describe "the empty function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("empty").should == "function_empty"
+ expect(Puppet::Parser::Functions.function("empty")).to eq("function_empty")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_empty([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_empty([]) }.to( raise_error(Puppet::ParseError))
end
it "should return a true for an empty string" do
result = scope.function_empty([''])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return a false for a non-empty string" do
result = scope.function_empty(['asdf'])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
describe "the flatten function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("flatten").should == "function_flatten"
+ expect(Puppet::Parser::Functions.function("flatten")).to eq("function_flatten")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_flatten([]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if there is more than 1 argument" do
- lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_flatten([[], []]) }.to( raise_error(Puppet::ParseError))
end
it "should flatten a complex data structure" do
result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
- result.should(eq(["a","b","c","d","e","f","g"]))
+ expect(result).to(eq(["a","b","c","d","e","f","g"]))
end
it "should do nothing to a structure that is already flat" do
result = scope.function_flatten([["a","b","c","d"]])
- result.should(eq(["a","b","c","d"]))
+ expect(result).to(eq(["a","b","c","d"]))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("floor").should == "function_floor"
+ expect(Puppet::Parser::Functions.function("floor")).to eq("function_floor")
end
it "should raise a ParseError if there is less than 1 argument" do
- lambda { scope.function_floor([]) }.should( raise_error(Puppet::ParseError, /Wrong number of arguments/))
+ expect { scope.function_floor([]) }.to( raise_error(Puppet::ParseError, /Wrong number of arguments/))
end
it "should should raise a ParseError if input isn't numeric (eg. String)" do
- lambda { scope.function_floor(["foo"]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/))
+ expect { scope.function_floor(["foo"]) }.to( raise_error(Puppet::ParseError, /Wrong argument type/))
end
it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do
- lambda { scope.function_floor([true]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/))
+ expect { scope.function_floor([true]) }.to( raise_error(Puppet::ParseError, /Wrong argument type/))
end
it "should return an integer when a numeric type is passed" do
result = scope.function_floor([12.4])
- result.is_a?(Integer).should(eq(true))
+ expect(result.is_a?(Integer)).to(eq(true))
end
it "should return the input when an integer is passed" do
result = scope.function_floor([7])
- result.should(eq(7))
+ expect(result).to(eq(7))
end
it "should return the largest integer less than or equal to the input" do
result = scope.function_floor([3.8])
- result.should(eq(3))
+ expect(result).to(eq(3))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("fqdn_rotate").should == "function_fqdn_rotate"
+ expect(Puppet::Parser::Functions.function("fqdn_rotate")).to eq("function_fqdn_rotate")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_fqdn_rotate([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_fqdn_rotate([]) }.to( raise_error(Puppet::ParseError))
end
it "should rotate a string and the result should be the same size" do
scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
result = scope.function_fqdn_rotate(["asdf"])
- result.size.should(eq(4))
+ expect(result.size).to(eq(4))
end
it "should rotate a string to give the same results for one host" do
scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
- scope.function_fqdn_rotate(["abcdefg"]).should eql(scope.function_fqdn_rotate(["abcdefg"]))
+ expect(scope.function_fqdn_rotate(["abcdefg"])).to eql(scope.function_fqdn_rotate(["abcdefg"]))
end
it "should rotate a string to give different values on different hosts" do
val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2")
val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
- val1.should_not eql(val2)
+ expect(val1).not_to eql(val2)
end
end
it 'should be able to find module paths from the modulepath setting' do
Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
- scope.function_get_module_path(['foo']).should == path_of_module_foo.path
+ expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
end
it 'should be able to find module paths when the modulepath is a list' do
Puppet[:modulepath] = modulepath + ":/tmp"
Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
- scope.function_get_module_path(['foo']).should == path_of_module_foo.path
+ expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
end
it 'should respect the environment' do
- pending("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/
+ skip("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/
Puppet.settings[:environment] = 'danstestenv'
Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo)
- scope('danstestenv').function_get_module_path(['foo']).should == path_of_module_foo.path
+ expect(scope('danstestenv').function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
end
end
end
end
it "should exist" do
- Puppet::Parser::Functions.function("getparam").should == "function_getparam"
+ expect(Puppet::Parser::Functions.function("getparam")).to eq("function_getparam")
end
describe 'when a resource is not specified' do
describe 'when calling getvar from puppet' do
it "should not compile when no arguments are passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = '$foo = getvar()'
expect {
scope.compiler.compile
end
it "should not compile when too many arguments are passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = '$foo = getvar("foo::bar", "baz")'
expect {
scope.compiler.compile
end
it "should lookup variables in other namespaces" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = <<-'ENDofPUPPETcode'
class site::data { $foo = 'baz' }
include site::data
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("grep").should == "function_grep"
+ expect(Puppet::Parser::Functions.function("grep")).to eq("function_grep")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_grep([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_grep([]) }.to( raise_error(Puppet::ParseError))
end
it "should grep contents from an array" do
result = scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"])
- result.should(eq(["aaabbb","bbbccc"]))
+ expect(result).to(eq(["aaabbb","bbbccc"]))
end
end
scope.stubs(:lookupvar).with("interfaces").returns('lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0')
end
it 'should have loopback (lo0)' do
- subject.call(['lo0']).should be_true
+ expect(subject.call(['lo0'])).to be_truthy
end
it 'should not have loopback (lo)' do
- subject.call(['lo']).should be_false
+ expect(subject.call(['lo'])).to be_falsey
end
end
context "On Linux Systems" do
scope.stubs(:lookupvar).with('muppet_eth0').returns('kermit')
end
it 'should have loopback (lo)' do
- subject.call(['lo']).should be_true
+ expect(subject.call(['lo'])).to be_truthy
end
it 'should not have loopback (lo0)' do
- subject.call(['lo0']).should be_false
+ expect(subject.call(['lo0'])).to be_falsey
end
it 'should have ipaddress with 127.0.0.1' do
- subject.call(['ipaddress', '127.0.0.1']).should be_true
+ expect(subject.call(['ipaddress', '127.0.0.1'])).to be_truthy
end
it 'should have ipaddress with 10.0.0.1' do
- subject.call(['ipaddress', '10.0.0.1']).should be_true
+ expect(subject.call(['ipaddress', '10.0.0.1'])).to be_truthy
end
it 'should not have ipaddress with 10.0.0.2' do
- subject.call(['ipaddress', '10.0.0.2']).should be_false
+ expect(subject.call(['ipaddress', '10.0.0.2'])).to be_falsey
end
it 'should have muppet named kermit' do
- subject.call(['muppet', 'kermit']).should be_true
+ expect(subject.call(['muppet', 'kermit'])).to be_truthy
end
it 'should have muppet named mspiggy' do
- subject.call(['muppet', 'mspiggy']).should be_true
+ expect(subject.call(['muppet', 'mspiggy'])).to be_truthy
end
it 'should not have muppet named bigbird' do
- subject.call(['muppet', 'bigbird']).should be_false
+ expect(subject.call(['muppet', 'bigbird'])).to be_falsey
end
end
end
end
it 'should have primary address (10.0.2.15)' do
- subject.call(['10.0.2.15']).should be_true
+ expect(subject.call(['10.0.2.15'])).to be_truthy
end
it 'should have lookupback address (127.0.0.1)' do
- subject.call(['127.0.0.1']).should be_true
+ expect(subject.call(['127.0.0.1'])).to be_truthy
end
it 'should not have other address' do
- subject.call(['192.1681.1.1']).should be_false
+ expect(subject.call(['192.1681.1.1'])).to be_falsey
end
it 'should not have "mspiggy" on an interface' do
- subject.call(['mspiggy']).should be_false
+ expect(subject.call(['mspiggy'])).to be_falsey
end
end
end
end
it 'should have primary network (10.0.2.0)' do
- subject.call(['10.0.2.0']).should be_true
+ expect(subject.call(['10.0.2.0'])).to be_truthy
end
it 'should have loopback network (127.0.0.0)' do
- subject.call(['127.0.0.1']).should be_true
+ expect(subject.call(['127.0.0.1'])).to be_truthy
end
it 'should not have other network' do
- subject.call(['192.168.1.0']).should be_false
+ expect(subject.call(['192.168.1.0'])).to be_falsey
end
end
end
describe 'when calling has_key from puppet' do
it "should not compile when no arguments are passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = '$x = has_key()'
expect {
scope.compiler.compile
end
it "should not compile when 1 argument is passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = "$x = has_key('foo')"
expect {
scope.compiler.compile
end
it "should require the first value to be a Hash" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = "$x = has_key('foo', 'bar')"
expect {
scope.compiler.compile
describe 'when calling the function has_key from a scope instance' do
it 'should detect existing keys' do
- scope.function_has_key([{'one' => 1}, 'one']).should be_true
+ expect(scope.function_has_key([{'one' => 1}, 'one'])).to be_truthy
end
it 'should detect existing keys' do
- scope.function_has_key([{'one' => 1}, 'two']).should be_false
+ expect(scope.function_has_key([{'one' => 1}, 'two'])).to be_falsey
end
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("hash").should == "function_hash"
+ expect(Puppet::Parser::Functions.function("hash")).to eq("function_hash")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_hash([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_hash([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert an array to a hash" do
result = scope.function_hash([['a',1,'b',2,'c',3]])
- result.should(eq({'a'=>1,'b'=>2,'c'=>3}))
+ expect(result).to(eq({'a'=>1,'b'=>2,'c'=>3}))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("intersection").should == "function_intersection"
+ expect(Puppet::Parser::Functions.function("intersection")).to eq("function_intersection")
end
it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_intersection([]) }.should( raise_error(Puppet::ParseError) )
+ expect { scope.function_intersection([]) }.to( raise_error(Puppet::ParseError) )
end
it "should return the intersection of two arrays" do
result = scope.function_intersection([["a","b","c"],["b","c","d"]])
- result.should(eq(["b","c"]))
+ expect(result).to(eq(["b","c"]))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_array").should == "function_is_array"
+ expect(Puppet::Parser::Functions.function("is_array")).to eq("function_is_array")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_array([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_array([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if passed an array" do
result = scope.function_is_array([[1,2,3]])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if passed a hash" do
result = scope.function_is_array([{'a'=>1}])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if passed a string" do
result = scope.function_is_array(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_bool").should == "function_is_bool"
+ expect(Puppet::Parser::Functions.function("is_bool")).to eq("function_is_bool")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_bool([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_bool([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if passed a TrueClass" do
result = scope.function_is_bool([true])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return true if passed a FalseClass" do
result = scope.function_is_bool([false])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if passed the string 'true'" do
result = scope.function_is_bool(['true'])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if passed the string 'false'" do
result = scope.function_is_bool(['false'])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if passed an array" do
result = scope.function_is_bool([["a","b"]])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if passed a hash" do
result = scope.function_is_bool([{"a" => "b"}])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_domain_name").should == "function_is_domain_name"
+ expect(Puppet::Parser::Functions.function("is_domain_name")).to eq("function_is_domain_name")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_domain_name([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if a valid short domain name" do
result = scope.function_is_domain_name(["x.com"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if the domain is ." do
result = scope.function_is_domain_name(["."])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if the domain is x.com." do
result = scope.function_is_domain_name(["x.com."])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if a valid domain name" do
result = scope.function_is_domain_name(["foo.bar.com"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should allow domain parts to start with numbers" do
result = scope.function_is_domain_name(["3foo.2bar.com"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should allow domain to end with a dot" do
result = scope.function_is_domain_name(["3foo.2bar.com."])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should allow a single part domain" do
result = scope.function_is_domain_name(["orange"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return false if domain parts start with hyphens" do
result = scope.function_is_domain_name(["-3foo.2bar.com"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return true if domain contains hyphens" do
result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return false if domain name contains spaces" do
result = scope.function_is_domain_name(["not valid"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_float").should == "function_is_float"
+ expect(Puppet::Parser::Functions.function("is_float")).to eq("function_is_float")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_float([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_float([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if a float" do
result = scope.function_is_float(["0.12"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if a string" do
result = scope.function_is_float(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if an integer" do
result = scope.function_is_float(["3"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return true if a float is created from an arithmetical operation" do
result = scope.function_is_float([3.2*2])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
end
end
it "should exist" do
- Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available"
+ expect(Puppet::Parser::Functions.function("is_function_available")).to eq("function_is_function_available")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { @scope.function_is_function_available([]) }.should( raise_error(Puppet::ParseError))
+ expect { @scope.function_is_function_available([]) }.to( raise_error(Puppet::ParseError))
end
it "should return false if a nonexistent function is passed" do
result = @scope.function_is_function_available(['jeff_mccunes_left_sock'])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return true if an available function is passed" do
result = @scope.function_is_function_available(['require'])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_hash").should == "function_is_hash"
+ expect(Puppet::Parser::Functions.function("is_hash")).to eq("function_is_hash")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_hash([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if passed a hash" do
result = scope.function_is_hash([{"a"=>1,"b"=>2}])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if passed an array" do
result = scope.function_is_hash([["a","b"]])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if passed a string" do
result = scope.function_is_hash(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_integer").should == "function_is_integer"
+ expect(Puppet::Parser::Functions.function("is_integer")).to eq("function_is_integer")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_integer([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if an integer" do
result = scope.function_is_integer(["3"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return true if a negative integer" do
result = scope.function_is_integer(["-7"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if a float" do
result = scope.function_is_integer(["3.2"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if a string" do
result = scope.function_is_integer(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return true if an integer is created from an arithmetical operation" do
result = scope.function_is_integer([3*2])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if an array" do
result = scope.function_is_numeric([["asdf"]])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if a hash" do
result = scope.function_is_numeric([{"asdf" => false}])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if a boolean" do
result = scope.function_is_numeric([true])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if a whitespace is in the string" do
result = scope.function_is_numeric([" -1324"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if it is zero prefixed" do
result = scope.function_is_numeric(["0001234"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if it is wrapped inside an array" do
result = scope.function_is_numeric([[1234]])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address"
+ expect(Puppet::Parser::Functions.function("is_ip_address")).to eq("function_is_ip_address")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_ip_address([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if an IPv4 address" do
result = scope.function_is_ip_address(["1.2.3.4"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return true if a full IPv6 address" do
result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return true if a compressed IPv6 address" do
result = scope.function_is_ip_address(["fe00::1"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if not valid" do
result = scope.function_is_ip_address(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if IP octets out of range" do
result = scope.function_is_ip_address(["1.1.1.300"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address"
+ expect(Puppet::Parser::Functions.function("is_mac_address")).to eq("function_is_mac_address")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_mac_address([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if a valid mac address" do
result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if octets are out of range" do
result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if not valid" do
result = scope.function_is_mac_address(["not valid"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric"
+ expect(Puppet::Parser::Functions.function("is_numeric")).to eq("function_is_numeric")
end
it "should raise a ParseError if there is less than 1 argument" do
- lambda { scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_numeric([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if an integer" do
result = scope.function_is_numeric(["3"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return true if a float" do
result = scope.function_is_numeric(["3.2"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return true if an integer is created from an arithmetical operation" do
result = scope.function_is_numeric([3*2])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return true if a float is created from an arithmetical operation" do
result = scope.function_is_numeric([3.2*2])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if a string" do
result = scope.function_is_numeric(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if an array" do
result = scope.function_is_numeric([["asdf"]])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if an array of integers" do
result = scope.function_is_numeric([[1,2,3,4]])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if a hash" do
result = scope.function_is_numeric([{"asdf" => false}])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if a hash with numbers in it" do
result = scope.function_is_numeric([{1 => 2}])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if a boolean" do
result = scope.function_is_numeric([true])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return true if a negative float with exponent" do
result = scope.function_is_numeric(["-342.2315e-12"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if a negative integer with whitespaces before/after the dash" do
result = scope.function_is_numeric([" - 751"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
# it "should return true if a hexadecimal" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_string").should == "function_is_string"
+ expect(Puppet::Parser::Functions.function("is_string")).to eq("function_is_string")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_string([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_string([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if a string" do
result = scope.function_is_string(["asdf"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if an integer" do
result = scope.function_is_string(["3"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if a float" do
result = scope.function_is_string(["3.23"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if an array" do
result = scope.function_is_string([["a","b","c"]])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("join_keys_to_values").should == "function_join_keys_to_values"
+ expect(Puppet::Parser::Functions.function("join_keys_to_values")).to eq("function_join_keys_to_values")
end
it "should raise a ParseError if there are fewer than two arguments" do
- lambda { scope.function_join_keys_to_values([{}]) }.should raise_error Puppet::ParseError
+ expect { scope.function_join_keys_to_values([{}]) }.to raise_error Puppet::ParseError
end
it "should raise a ParseError if there are greater than two arguments" do
- lambda { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.should raise_error Puppet::ParseError
+ expect { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.to raise_error Puppet::ParseError
end
it "should raise a TypeError if the first argument is an array" do
- lambda { scope.function_join_keys_to_values([[1,2], ',']) }.should raise_error TypeError
+ expect { scope.function_join_keys_to_values([[1,2], ',']) }.to raise_error TypeError
end
it "should raise a TypeError if the second argument is an array" do
- lambda { scope.function_join_keys_to_values([{}, [1,2]]) }.should raise_error TypeError
+ expect { scope.function_join_keys_to_values([{}, [1,2]]) }.to raise_error TypeError
end
it "should raise a TypeError if the second argument is a number" do
- lambda { scope.function_join_keys_to_values([{}, 1]) }.should raise_error TypeError
+ expect { scope.function_join_keys_to_values([{}, 1]) }.to raise_error TypeError
end
it "should return an empty array given an empty hash" do
result = scope.function_join_keys_to_values([{}, ":"])
- result.should == []
+ expect(result).to eq([])
end
it "should join hash's keys to its values" do
result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"])
- result.should =~ ['a:1','2:foo','b:']
+ expect(result).to match_array(['a:1','2:foo','b:'])
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("join").should == "function_join"
+ expect(Puppet::Parser::Functions.function("join")).to eq("function_join")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_join([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_join([]) }.to( raise_error(Puppet::ParseError))
end
it "should join an array into a string" do
result = scope.function_join([["a","b","c"], ":"])
- result.should(eq("a:b:c"))
+ expect(result).to(eq("a:b:c"))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("keys").should == "function_keys"
+ expect(Puppet::Parser::Functions.function("keys")).to eq("function_keys")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_keys([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_keys([]) }.to( raise_error(Puppet::ParseError))
end
it "should return an array of keys when given a hash" do
result = scope.function_keys([{'a'=>1, 'b'=>2}])
# =~ performs 'array with same elements' (set) matching
# For more info see RSpec::Matchers::MatchArray
- result.should =~ ['a','b']
+ expect(result).to match_array(['a','b'])
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("loadyaml").should == "function_loadyaml"
+ expect(Puppet::Parser::Functions.function("loadyaml")).to eq("function_loadyaml")
end
it "should raise a ParseError if there is less than 1 arguments" do
fh.write("---\n aaa: 1\n bbb: 2\n ccc: 3\n ddd: 4\n")
end
result = scope.function_loadyaml([yaml_file])
- result.should == {"aaa" => 1, "bbb" => 2, "ccc" => 3, "ddd" => 4 }
+ expect(result).to eq({"aaa" => 1, "bbb" => 2, "ccc" => 3, "ddd" => 4 })
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("lstrip").should == "function_lstrip"
+ expect(Puppet::Parser::Functions.function("lstrip")).to eq("function_lstrip")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_lstrip([]) }.to( raise_error(Puppet::ParseError))
end
it "should lstrip a string" do
result = scope.function_lstrip([" asdf"])
- result.should(eq('asdf'))
+ expect(result).to(eq('asdf'))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("max").should == "function_max"
+ expect(Puppet::Parser::Functions.function("max")).to eq("function_max")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_max([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_max([]) }.to( raise_error(Puppet::ParseError))
end
it "should be able to compare strings" do
- scope.function_max(["albatross","dog","horse"]).should(eq("horse"))
+ expect(scope.function_max(["albatross","dog","horse"])).to(eq("horse"))
end
it "should be able to compare numbers" do
- scope.function_max([6,8,4]).should(eq(8))
+ expect(scope.function_max([6,8,4])).to(eq(8))
end
it "should be able to compare a number with a stringified number" do
- scope.function_max([1,"2"]).should(eq("2"))
+ expect(scope.function_max([1,"2"])).to(eq("2"))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("member").should == "function_member"
+ expect(Puppet::Parser::Functions.function("member")).to eq("function_member")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_member([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_member([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if a member is in an array" do
result = scope.function_member([["a","b","c"], "a"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if a member is not in an array" do
result = scope.function_member([["a","b","c"], "d"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
describe 'when calling merge from puppet' do
it "should not compile when no arguments are passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = '$x = merge()'
expect {
scope.compiler.compile
end
it "should not compile when 1 argument is passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)"
expect {
scope.compiler.compile
it 'should be able to merge two hashes' do
new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
- new_hash['one'].should == '1'
- new_hash['two'].should == '2'
- new_hash['three'].should == '2'
+ expect(new_hash['one']).to eq('1')
+ expect(new_hash['two']).to eq('2')
+ expect(new_hash['three']).to eq('2')
end
it 'should merge multiple hashes' do
hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
- hash['one'].should == '3'
+ expect(hash['one']).to eq('3')
end
it 'should accept empty hashes' do
- scope.function_merge([{},{},{}]).should == {}
+ expect(scope.function_merge([{},{},{}])).to eq({})
end
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("min").should == "function_min"
+ expect(Puppet::Parser::Functions.function("min")).to eq("function_min")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_min([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_min([]) }.to( raise_error(Puppet::ParseError))
end
it "should be able to compare strings" do
- scope.function_min(["albatross","dog","horse"]).should(eq("albatross"))
+ expect(scope.function_min(["albatross","dog","horse"])).to(eq("albatross"))
end
it "should be able to compare numbers" do
- scope.function_min([6,8,4]).should(eq(4))
+ expect(scope.function_min([6,8,4])).to(eq(4))
end
it "should be able to compare a number with a stringified number" do
- scope.function_min([1,"2"]).should(eq(1))
+ expect(scope.function_min([1,"2"])).to(eq(1))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("num2bool").should == "function_num2bool"
+ expect(Puppet::Parser::Functions.function("num2bool")).to eq("function_num2bool")
end
it "should raise a ParseError if there are no arguments" do
- lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_num2bool([]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if there are more than 1 arguments" do
- lambda { scope.function_num2bool(["foo","bar"]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_num2bool(["foo","bar"]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if passed something non-numeric" do
- lambda { scope.function_num2bool(["xyzzy"]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_num2bool(["xyzzy"]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if passed string 1" do
result = scope.function_num2bool(["1"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if passed string 1.5" do
result = scope.function_num2bool(["1.5"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if passed number 1" do
result = scope.function_num2bool([1])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return false if passed string 0" do
result = scope.function_num2bool(["0"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed number 0" do
result = scope.function_num2bool([0])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed string -1" do
result = scope.function_num2bool(["-1"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed string -1.5" do
result = scope.function_num2bool(["-1.5"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed number -1" do
result = scope.function_num2bool([-1])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed float -1.5" do
result = scope.function_num2bool([-1.5])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("parsejson").should == "function_parsejson"
+ expect(Puppet::Parser::Functions.function("parsejson")).to eq("function_parsejson")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_parsejson([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert JSON to a data structure" do
["aaa","bbb","ccc"]
EOS
result = scope.function_parsejson([json])
- result.should(eq(['aaa','bbb','ccc']))
+ expect(result).to(eq(['aaa','bbb','ccc']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml"
+ expect(Puppet::Parser::Functions.function("parseyaml")).to eq("function_parseyaml")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_parseyaml([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert YAML to a data structure" do
- ccc
EOS
result = scope.function_parseyaml([yaml])
- result.should(eq(['aaa','bbb','ccc']))
+ expect(result).to(eq(['aaa','bbb','ccc']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("pick_default").should == "function_pick_default"
+ expect(Puppet::Parser::Functions.function("pick_default")).to eq("function_pick_default")
end
it 'should return the correct value' do
- scope.function_pick_default(['first', 'second']).should == 'first'
+ expect(scope.function_pick_default(['first', 'second'])).to eq('first')
end
it 'should return the correct value if the first value is empty' do
- scope.function_pick_default(['', 'second']).should == 'second'
+ expect(scope.function_pick_default(['', 'second'])).to eq('second')
end
it 'should skip empty string values' do
- scope.function_pick_default(['', 'first']).should == 'first'
+ expect(scope.function_pick_default(['', 'first'])).to eq('first')
end
it 'should skip :undef values' do
- scope.function_pick_default([:undef, 'first']).should == 'first'
+ expect(scope.function_pick_default([:undef, 'first'])).to eq('first')
end
it 'should skip :undefined values' do
- scope.function_pick_default([:undefined, 'first']).should == 'first'
+ expect(scope.function_pick_default([:undefined, 'first'])).to eq('first')
end
it 'should return the empty string if it is the last possibility' do
- scope.function_pick_default([:undef, :undefined, '']).should == ''
+ expect(scope.function_pick_default([:undef, :undefined, ''])).to eq('')
end
it 'should return :undef if it is the last possibility' do
- scope.function_pick_default(['', :undefined, :undef]).should == :undef
+ expect(scope.function_pick_default(['', :undefined, :undef])).to eq(:undef)
end
it 'should return :undefined if it is the last possibility' do
- scope.function_pick_default([:undef, '', :undefined]).should == :undefined
+ expect(scope.function_pick_default([:undef, '', :undefined])).to eq(:undefined)
end
it 'should return the empty string if it is the only possibility' do
- scope.function_pick_default(['']).should == ''
+ expect(scope.function_pick_default([''])).to eq('')
end
it 'should return :undef if it is the only possibility' do
- scope.function_pick_default([:undef]).should == :undef
+ expect(scope.function_pick_default([:undef])).to eq(:undef)
end
it 'should return :undefined if it is the only possibility' do
- scope.function_pick_default([:undefined]).should == :undefined
+ expect(scope.function_pick_default([:undefined])).to eq(:undefined)
end
it 'should error if no values are passed' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("pick").should == "function_pick"
+ expect(Puppet::Parser::Functions.function("pick")).to eq("function_pick")
end
it 'should return the correct value' do
- scope.function_pick(['first', 'second']).should == 'first'
+ expect(scope.function_pick(['first', 'second'])).to eq('first')
end
it 'should return the correct value if the first value is empty' do
- scope.function_pick(['', 'second']).should == 'second'
+ expect(scope.function_pick(['', 'second'])).to eq('second')
end
it 'should remove empty string values' do
- scope.function_pick(['', 'first']).should == 'first'
+ expect(scope.function_pick(['', 'first'])).to eq('first')
end
it 'should remove :undef values' do
- scope.function_pick([:undef, 'first']).should == 'first'
+ expect(scope.function_pick([:undef, 'first'])).to eq('first')
end
it 'should remove :undefined values' do
- scope.function_pick([:undefined, 'first']).should == 'first'
+ expect(scope.function_pick([:undefined, 'first'])).to eq('first')
end
it 'should error if no values are passed' do
it "returns a prefixed array" do
result = scope.function_prefix([['a','b','c'], 'p'])
- result.should(eq(['pa','pb','pc']))
+ expect(result).to(eq(['pa','pb','pc']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "exists" do
- Puppet::Parser::Functions.function("range").should == "function_range"
+ expect(Puppet::Parser::Functions.function("range")).to eq("function_range")
end
it "raises a ParseError if there is less than 1 arguments" do
describe 'with a letter range' do
it "returns a letter range" do
result = scope.function_range(["a","d"])
- result.should eq ['a','b','c','d']
+ expect(result).to eq ['a','b','c','d']
end
it "returns a letter range given a step of 1" do
result = scope.function_range(["a","d","1"])
- result.should eq ['a','b','c','d']
+ expect(result).to eq ['a','b','c','d']
end
it "returns a stepped letter range" do
result = scope.function_range(["a","d","2"])
- result.should eq ['a','c']
+ expect(result).to eq ['a','c']
end
it "returns a stepped letter range given a negative step" do
result = scope.function_range(["a","d","-2"])
- result.should eq ['a','c']
+ expect(result).to eq ['a','c']
end
end
describe 'with a number range' do
it "returns a number range" do
result = scope.function_range(["1","4"])
- result.should eq [1,2,3,4]
+ expect(result).to eq [1,2,3,4]
end
it "returns a number range given a step of 1" do
result = scope.function_range(["1","4","1"])
- result.should eq [1,2,3,4]
+ expect(result).to eq [1,2,3,4]
end
it "returns a stepped number range" do
result = scope.function_range(["1","4","2"])
- result.should eq [1,3]
+ expect(result).to eq [1,3]
end
it "returns a stepped number range given a negative step" do
result = scope.function_range(["1","4","-2"])
- result.should eq [1,3]
+ expect(result).to eq [1,3]
end
end
describe 'with a numeric-like string range' do
it "works with padded hostname like strings" do
expected = ("host01".."host10").to_a
- scope.function_range(["host01","host10"]).should eq expected
+ expect(scope.function_range(["host01","host10"])).to eq expected
end
it "coerces zero padded digits to integers" do
expected = (0..10).to_a
- scope.function_range(["00", "10"]).should eq expected
+ expect(scope.function_range(["00", "10"])).to eq expected
end
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("reject").should == "function_reject"
+ expect(Puppet::Parser::Functions.function("reject")).to eq("function_reject")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_reject([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_reject([]) }.to( raise_error(Puppet::ParseError))
end
it "should reject contents from an array" do
result = scope.function_reject([["1111", "aaabbb","bbbccc","dddeee"], "bbb"])
- result.should(eq(["1111", "dddeee"]))
+ expect(result).to(eq(["1111", "dddeee"]))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("reverse").should == "function_reverse"
+ expect(Puppet::Parser::Functions.function("reverse")).to eq("function_reverse")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_reverse([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_reverse([]) }.to( raise_error(Puppet::ParseError))
end
it "should reverse a string" do
result = scope.function_reverse(["asdfghijkl"])
- result.should(eq('lkjihgfdsa'))
+ expect(result).to(eq('lkjihgfdsa'))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("rstrip").should == "function_rstrip"
+ expect(Puppet::Parser::Functions.function("rstrip")).to eq("function_rstrip")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_rstrip([]) }.to( raise_error(Puppet::ParseError))
end
it "should rstrip a string" do
result = scope.function_rstrip(["asdf "])
- result.should(eq('asdf'))
+ expect(result).to(eq('asdf'))
end
it "should rstrip each element in an array" do
result = scope.function_rstrip([["a ","b ", "c "]])
- result.should(eq(['a','b','c']))
+ expect(result).to(eq(['a','b','c']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("shuffle").should == "function_shuffle"
+ expect(Puppet::Parser::Functions.function("shuffle")).to eq("function_shuffle")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_shuffle([]) }.to( raise_error(Puppet::ParseError))
end
it "should shuffle a string and the result should be the same size" do
result = scope.function_shuffle(["asdf"])
- result.size.should(eq(4))
+ expect(result.size).to(eq(4))
end
it "should shuffle a string but the sorted contents should still be the same" do
result = scope.function_shuffle(["adfs"])
- result.split("").sort.join("").should(eq("adfs"))
+ expect(result.split("").sort.join("")).to(eq("adfs"))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("size").should == "function_size"
+ expect(Puppet::Parser::Functions.function("size")).to eq("function_size")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_size([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_size([]) }.to( raise_error(Puppet::ParseError))
end
it "should return the size of a string" do
result = scope.function_size(["asdf"])
- result.should(eq(4))
+ expect(result).to(eq(4))
end
it "should return the size of an array" do
result = scope.function_size([["a","b","c"]])
- result.should(eq(3))
+ expect(result).to(eq(3))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("sort").should == "function_sort"
+ expect(Puppet::Parser::Functions.function("sort")).to eq("function_sort")
end
it "should raise a ParseError if there is not 1 arguments" do
- lambda { scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_sort(['','']) }.to( raise_error(Puppet::ParseError))
end
it "should sort an array" do
result = scope.function_sort([["a","c","b"]])
- result.should(eq(['a','b','c']))
+ expect(result).to(eq(['a','b','c']))
end
it "should sort a string" do
result = scope.function_sort(["acb"])
- result.should(eq('abc'))
+ expect(result).to(eq('abc'))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("squeeze").should == "function_squeeze"
+ expect(Puppet::Parser::Functions.function("squeeze")).to eq("function_squeeze")
end
it "should raise a ParseError if there is less than 2 arguments" do
- lambda { scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_squeeze([]) }.to( raise_error(Puppet::ParseError))
end
it "should squeeze a string" do
result = scope.function_squeeze(["aaabbbbcccc"])
- result.should(eq('abc'))
+ expect(result).to(eq('abc'))
end
it "should squeeze all elements in an array" do
result = scope.function_squeeze([["aaabbbbcccc","dddfff"]])
- result.should(eq(['abc','df']))
+ expect(result).to(eq(['abc','df']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("str2bool").should == "function_str2bool"
+ expect(Puppet::Parser::Functions.function("str2bool")).to eq("function_str2bool")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_str2bool([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert string 'true' to true" do
result = scope.function_str2bool(["true"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should convert string 'undef' to false" do
result = scope.function_str2bool(["undef"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return the boolean it was called with" do
result = scope.function_str2bool([true])
- result.should(eq(true))
+ expect(result).to(eq(true))
result = scope.function_str2bool([false])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("str2saltedsha512").should == "function_str2saltedsha512"
+ expect(Puppet::Parser::Functions.function("str2saltedsha512")).to eq("function_str2saltedsha512")
end
it "should raise a ParseError if there is less than 1 argument" do
it "should return a salted-sha512 password hash 136 characters in length" do
result = scope.function_str2saltedsha512(["password"])
- result.length.should(eq(136))
+ expect(result.length).to(eq(136))
end
it "should raise an error if you pass a non-string password" do
# Combine the Binary Salt with 'password' and compare the end result
saltedpass = Digest::SHA512.digest(str_salt + 'password')
result = (str_salt + saltedpass).unpack('H*')[0]
- result.should == password_hash
+ expect(result).to eq(password_hash)
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("strftime").should == "function_strftime"
+ expect(Puppet::Parser::Functions.function("strftime")).to eq("function_strftime")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_strftime([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_strftime([]) }.to( raise_error(Puppet::ParseError))
end
it "using %s should be higher then when I wrote this test" do
result = scope.function_strftime(["%s"])
- result.to_i.should(be > 1311953157)
+ expect(result.to_i).to(be > 1311953157)
end
it "using %s should be lower then 1.5 trillion" do
result = scope.function_strftime(["%s"])
- result.to_i.should(be < 1500000000)
+ expect(result.to_i).to(be < 1500000000)
end
it "should return a date when given %Y-%m-%d" do
result = scope.function_strftime(["%Y-%m-%d"])
- result.should =~ /^\d{4}-\d{2}-\d{2}$/
+ expect(result).to match(/^\d{4}-\d{2}-\d{2}$/)
end
end
describe "the strip function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("strip").should == "function_strip"
+ expect(Puppet::Parser::Functions.function("strip")).to eq("function_strip")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_strip([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_strip([]) }.to( raise_error(Puppet::ParseError))
end
it "should strip a string" do
result = scope.function_strip([" ab cd "])
- result.should(eq('ab cd'))
+ expect(result).to(eq('ab cd'))
end
end
it "returns a suffixed array" do
result = scope.function_suffix([['a','b','c'], 'p'])
- result.should(eq(['ap','bp','cp']))
+ expect(result).to(eq(['ap','bp','cp']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("swapcase").should == "function_swapcase"
+ expect(Puppet::Parser::Functions.function("swapcase")).to eq("function_swapcase")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_swapcase([]) }.to( raise_error(Puppet::ParseError))
end
it "should swapcase a string" do
result = scope.function_swapcase(["aaBBccDD"])
- result.should(eq('AAbbCCdd'))
+ expect(result).to(eq('AAbbCCdd'))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("time").should == "function_time"
+ expect(Puppet::Parser::Functions.function("time")).to eq("function_time")
end
it "should raise a ParseError if there is more than 2 arguments" do
- lambda { scope.function_time(['','']) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_time(['','']) }.to( raise_error(Puppet::ParseError))
end
it "should return a number" do
result = scope.function_time([])
- result.should be_an(Integer)
+ expect(result).to be_an(Integer)
end
it "should be higher then when I wrote this test" do
result = scope.function_time([])
- result.should(be > 1311953157)
+ expect(result).to(be > 1311953157)
end
it "should be lower then 1.5 trillion" do
result = scope.function_time([])
- result.should(be < 1500000000)
+ expect(result).to(be < 1500000000)
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("to_bytes").should == "function_to_bytes"
+ expect(Puppet::Parser::Functions.function("to_bytes")).to eq("function_to_bytes")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_to_bytes([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_to_bytes([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert kB to B" do
result = scope.function_to_bytes(["4 kB"])
- result.should(eq(4096))
+ expect(result).to(eq(4096))
end
it "should work without B in unit" do
result = scope.function_to_bytes(["4 k"])
- result.should(eq(4096))
+ expect(result).to(eq(4096))
end
it "should work without a space before unit" do
result = scope.function_to_bytes(["4k"])
- result.should(eq(4096))
+ expect(result).to(eq(4096))
end
it "should work without a unit" do
result = scope.function_to_bytes(["5678"])
- result.should(eq(5678))
+ expect(result).to(eq(5678))
end
it "should convert fractions" do
result = scope.function_to_bytes(["1.5 kB"])
- result.should(eq(1536))
+ expect(result).to(eq(1536))
end
it "should convert scientific notation" do
result = scope.function_to_bytes(["1.5e2 B"])
- result.should(eq(150))
+ expect(result).to(eq(150))
end
it "should do nothing with a positive number" do
result = scope.function_to_bytes([5678])
- result.should(eq(5678))
+ expect(result).to(eq(5678))
end
it "should should raise a ParseError if input isn't a number" do
- lambda { scope.function_to_bytes(["foo"]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_to_bytes(["foo"]) }.to( raise_error(Puppet::ParseError))
end
it "should should raise a ParseError if prefix is unknown" do
- lambda { scope.function_to_bytes(["5 uB"]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_to_bytes(["5 uB"]) }.to( raise_error(Puppet::ParseError))
end
end
describe "the type function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("type").should == "function_type"
+ expect(Puppet::Parser::Functions.function("type")).to eq("function_type")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_type([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_type([]) }.to( raise_error(Puppet::ParseError))
end
it "should return string when given a string" do
result = scope.function_type(["aaabbbbcccc"])
- result.should(eq('string'))
+ expect(result).to(eq('string'))
end
it "should return array when given an array" do
result = scope.function_type([["aaabbbbcccc","asdf"]])
- result.should(eq('array'))
+ expect(result).to(eq('array'))
end
it "should return hash when given a hash" do
result = scope.function_type([{"a"=>1,"b"=>2}])
- result.should(eq('hash'))
+ expect(result).to(eq('hash'))
end
it "should return integer when given an integer" do
result = scope.function_type(["1"])
- result.should(eq('integer'))
+ expect(result).to(eq('integer'))
end
it "should return float when given a float" do
result = scope.function_type(["1.34"])
- result.should(eq('float'))
+ expect(result).to(eq('float'))
end
it "should return boolean when given a boolean" do
result = scope.function_type([true])
- result.should(eq('boolean'))
+ expect(result).to(eq('boolean'))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("union").should == "function_union"
+ expect(Puppet::Parser::Functions.function("union")).to eq("function_union")
end
it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_union([]) }.should( raise_error(Puppet::ParseError) )
+ expect { scope.function_union([]) }.to( raise_error(Puppet::ParseError) )
end
it "should join two arrays together" do
result = scope.function_union([["a","b","c"],["b","c","d"]])
- result.should(eq(["a","b","c","d"]))
+ expect(result).to(eq(["a","b","c","d"]))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("unique").should == "function_unique"
+ expect(Puppet::Parser::Functions.function("unique")).to eq("function_unique")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_unique([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_unique([]) }.to( raise_error(Puppet::ParseError))
end
it "should remove duplicate elements in a string" do
result = scope.function_unique(["aabbc"])
- result.should(eq('abc'))
+ expect(result).to(eq('abc'))
end
it "should remove duplicate elements in an array" do
result = scope.function_unique([["a","a","b","b","c"]])
- result.should(eq(['a','b','c']))
+ expect(result).to(eq(['a','b','c']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("upcase").should == "function_upcase"
+ expect(Puppet::Parser::Functions.function("upcase")).to eq("function_upcase")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_upcase([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_upcase([]) }.to( raise_error(Puppet::ParseError))
end
it "should upcase a string" do
result = scope.function_upcase(["abc"])
- result.should(eq('ABC'))
+ expect(result).to(eq('ABC'))
end
it "should do nothing if a string is already upcase" do
result = scope.function_upcase(["ABC"])
- result.should(eq('ABC'))
+ expect(result).to(eq('ABC'))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("uriescape").should == "function_uriescape"
+ expect(Puppet::Parser::Functions.function("uriescape")).to eq("function_uriescape")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_uriescape([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_uriescape([]) }.to( raise_error(Puppet::ParseError))
end
it "should uriescape a string" do
result = scope.function_uriescape([":/?#[]@!$&'()*+,;= \"{}"])
- result.should(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'))
+ expect(result).to(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'))
end
it "should do nothing if a string is already safe" do
result = scope.function_uriescape(["ABCdef"])
- result.should(eq('ABCdef'))
+ expect(result).to(eq('ABCdef'))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("validate_slength").should == "function_validate_slength"
+ expect(Puppet::Parser::Functions.function("validate_slength")).to eq("function_validate_slength")
end
describe "validating the input argument types" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("values_at").should == "function_values_at"
+ expect(Puppet::Parser::Functions.function("values_at")).to eq("function_values_at")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_values_at([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_values_at([]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if you try to use a range where stop is greater then start" do
- lambda { scope.function_values_at([['a','b'],["3-1"]]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_values_at([['a','b'],["3-1"]]) }.to( raise_error(Puppet::ParseError))
end
it "should return a value at from an array" do
result = scope.function_values_at([['a','b','c'],"1"])
- result.should(eq(['b']))
+ expect(result).to(eq(['b']))
end
it "should return a value at from an array when passed a range" do
result = scope.function_values_at([['a','b','c'],"0-1"])
- result.should(eq(['a','b']))
+ expect(result).to(eq(['a','b']))
end
it "should return chosen values from an array when passed number of indexes" do
result = scope.function_values_at([['a','b','c'],["0","2"]])
- result.should(eq(['a','c']))
+ expect(result).to(eq(['a','c']))
end
it "should return chosen values from an array when passed ranges and multiple indexes" do
result = scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]])
- result.should(eq(['a','c','e','f']))
+ expect(result).to(eq(['a','c','e','f']))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("values").should == "function_values"
+ expect(Puppet::Parser::Functions.function("values")).to eq("function_values")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_values([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_values([]) }.to( raise_error(Puppet::ParseError))
end
it "should return values from a hash" do
result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}])
# =~ is the RSpec::Matchers::MatchArray matcher.
# A.K.A. "array with same elements" (multiset) matching
- result.should =~ %w{ 1 2 3 }
+ expect(result).to match_array(%w{ 1 2 3 })
end
it "should return a multiset" do
result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}])
- result.should =~ %w{ 1 3 3 }
- result.should_not =~ %w{ 1 3 }
+ expect(result).to match_array(%w{ 1 3 3 })
+ expect(result).not_to match_array(%w{ 1 3 })
end
it "should raise a ParseError unless a Hash is provided" do
- lambda { scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_values([['a','b','c']]) }.to( raise_error(Puppet::ParseError))
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_zip([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_zip([]) }.to( raise_error(Puppet::ParseError))
end
it "should be able to zip an array" do
result = scope.function_zip([['1','2','3'],['4','5','6']])
- result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
+ expect(result).to(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
end
end