Skip to content

Commit

Permalink
Merge pull request redhat-openstack#268 from apenney/rspec3
Browse files Browse the repository at this point in the history
Rspec3 changes
  • Loading branch information
Morgan Haskel committed Jun 5, 2014
2 parents f9f6e92 + 6287a20 commit ffe21fc
Show file tree
Hide file tree
Showing 92 changed files with 510 additions and 510 deletions.
8 changes: 4 additions & 4 deletions spec/functions/abs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
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
20 changes: 10 additions & 10 deletions spec/functions/any2array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,51 @@
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
6 changes: 3 additions & 3 deletions spec/functions/base64_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand All @@ -25,10 +25,10 @@

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
8 changes: 4 additions & 4 deletions spec/functions/bool2num_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
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
6 changes: 3 additions & 3 deletions spec/functions/capitalize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
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
6 changes: 3 additions & 3 deletions spec/functions/chomp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
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
6 changes: 3 additions & 3 deletions spec/functions/chop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
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
10 changes: 5 additions & 5 deletions spec/functions/concat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
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
10 changes: 5 additions & 5 deletions spec/functions/count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
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
Expand Down
52 changes: 26 additions & 26 deletions spec/functions/deep_merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

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
}.to raise_error(Puppet::ParseError, /wrong number of arguments/)
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
Expand All @@ -35,71 +35,71 @@

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
Loading

0 comments on commit ffe21fc

Please sign in to comment.