Skip to content

Commit

Permalink
Merge pull request #80 from jeffmccune/fix/2.3.x/go_green
Browse files Browse the repository at this point in the history
Fix up 2.3.x for new scope
  • Loading branch information
Jeff McCune committed Jul 23, 2012
2 parents 730aee4 + c129775 commit 731c07e
Show file tree
Hide file tree
Showing 61 changed files with 324 additions and 837 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/get_module_path.rb
Expand Up @@ -7,7 +7,7 @@ module Puppet::Parser::Functions
$module_path = get_module_path('stdlib')
EOT
) do |args|
raise(Puppet::ParseError, "get_module_name(): Wrong number of arguments, expects one") unless args.size == 1
raise(Puppet::ParseError, "get_module_path(): Wrong number of arguments, expects one") unless args.size == 1
if module_path = Puppet::Module.find(args[0], compiler.environment.to_s)
module_path.path
else
Expand Down
24 changes: 1 addition & 23 deletions spec/spec_helper.rb
Expand Up @@ -10,27 +10,5 @@
gem 'rspec', '>=2.0.0'
require 'rspec/expectations'

require 'puppetlabs_spec_helper/module_spec_helper'

# So everyone else doesn't have to include this base constant.
module PuppetSpec
FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
end

# TODO: ultimately would like to move these requires into the puppet_spec_helper.rb file, but the namespaces
# are not currently the same between the two, so tests would need to be modified. Not ready to undertake that
# just yet.
require 'puppet_spec/files'

require 'puppet_spec_helper'


RSpec.configure do |config|

config.before :each do
GC.disable
end

config.after :each do
GC.enable
end
end
18 changes: 6 additions & 12 deletions spec/unit/puppet/parser/functions/abs_spec.rb
@@ -1,31 +1,25 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec

require 'spec_helper'

describe "the abs function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

it "should exist" do
Puppet::Parser::Functions.function("abs").should == "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))
lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError))
end

it "should convert a negative number into a positive" do
result = @scope.function_abs(["-34"])
result = scope.function_abs(["-34"])
result.should(eq(34))
end

it "should do nothing with a positive number" do
result = @scope.function_abs(["5678"])
result = scope.function_abs(["5678"])
result.should(eq(5678))
end

end
17 changes: 5 additions & 12 deletions spec/unit/puppet/parser/functions/bool2num_spec.rb
@@ -1,31 +1,24 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the bool2num function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

it "should exist" do
Puppet::Parser::Functions.function("bool2num").should == "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))
lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError))
end

it "should convert true to 1" do
result = @scope.function_bool2num([true])
result = scope.function_bool2num([true])
result.should(eq(1))
end

it "should convert false to 0" do
result = @scope.function_bool2num([false])
result = scope.function_bool2num([false])
result.should(eq(0))
end

end
15 changes: 4 additions & 11 deletions spec/unit/puppet/parser/functions/capitalize_spec.rb
@@ -1,26 +1,19 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the capitalize function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

it "should exist" do
Puppet::Parser::Functions.function("capitalize").should == "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))
lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError))
end

it "should capitalize the beginning of a string" do
result = @scope.function_capitalize(["abc"])
result = scope.function_capitalize(["abc"])
result.should(eq("Abc"))
end

end
15 changes: 4 additions & 11 deletions spec/unit/puppet/parser/functions/chomp_spec.rb
@@ -1,26 +1,19 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the chomp function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

it "should exist" do
Puppet::Parser::Functions.function("chomp").should == "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))
lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError))
end

it "should chomp the end of a string" do
result = @scope.function_chomp(["abc\n"])
result = scope.function_chomp(["abc\n"])
result.should(eq("abc"))
end

end
15 changes: 4 additions & 11 deletions spec/unit/puppet/parser/functions/chop_spec.rb
@@ -1,26 +1,19 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the chop function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

it "should exist" do
Puppet::Parser::Functions.function("chop").should == "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))
lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError))
end

it "should chop the end of a string" do
result = @scope.function_chop(["asdf\n"])
result = scope.function_chop(["asdf\n"])
result.should(eq("asdf"))
end

end
15 changes: 4 additions & 11 deletions spec/unit/puppet/parser/functions/delete_at_spec.rb
@@ -1,26 +1,19 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the delete_at function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

it "should exist" do
Puppet::Parser::Functions.function("delete_at").should == "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))
lambda { scope.function_delete_at([]) }.should( 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 = scope.function_delete_at([['a','b','c'],1])
result.should(eq(['a','c']))
end

end
15 changes: 4 additions & 11 deletions spec/unit/puppet/parser/functions/delete_spec.rb
@@ -1,26 +1,19 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the delete function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

it "should exist" do
Puppet::Parser::Functions.function("delete").should == "function_delete"
end

it "should raise a ParseError if there is less than 1 arguments" do
lambda { @scope.function_delete([]) }.should( raise_error(Puppet::ParseError))
lambda { scope.function_delete([]) }.should( raise_error(Puppet::ParseError))
end

it "should delete an item from an array" do
result = @scope.function_delete([['a','b','c'],'b'])
result = scope.function_delete([['a','b','c'],'b'])
result.should(eq(['a','c']))
end

end
17 changes: 5 additions & 12 deletions spec/unit/puppet/parser/functions/downcase_spec.rb
@@ -1,31 +1,24 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the downcase function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

it "should exist" do
Puppet::Parser::Functions.function("downcase").should == "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))
lambda { scope.function_downcase([]) }.should( raise_error(Puppet::ParseError))
end

it "should downcase a string" do
result = @scope.function_downcase(["ASFD"])
result = scope.function_downcase(["ASFD"])
result.should(eq("asfd"))
end

it "should do nothing to a string that is already downcase" do
result = @scope.function_downcase(["asdf asdf"])
result = scope.function_downcase(["asdf asdf"])
result.should(eq("asdf asdf"))
end

end
18 changes: 5 additions & 13 deletions spec/unit/puppet/parser/functions/empty_spec.rb
@@ -1,31 +1,23 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the empty function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end

let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
Puppet::Parser::Functions.function("empty").should == "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))
lambda { scope.function_empty([]) }.should( raise_error(Puppet::ParseError))
end

it "should return a true for an empty string" do
result = @scope.function_empty([''])
result = scope.function_empty([''])
result.should(eq(true))
end

it "should return a false for a non-empty string" do
result = @scope.function_empty(['asdf'])
result = scope.function_empty(['asdf'])
result.should(eq(false))
end

end
18 changes: 5 additions & 13 deletions spec/unit/puppet/parser/functions/flatten_spec.rb
@@ -1,31 +1,23 @@
#!/usr/bin/env rspec
#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the flatten function" do
before :all do
Puppet::Parser::Functions.autoloader.loadall
end

before :each do
@scope = Puppet::Parser::Scope.new
end

let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
Puppet::Parser::Functions.function("flatten").should == "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))
lambda { scope.function_flatten([]) }.should( 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 = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
result.should(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 = scope.function_flatten([["a","b","c","d"]])
result.should(eq(["a","b","c","d"]))
end

end

0 comments on commit 731c07e

Please sign in to comment.