Skip to content

Fix up 2.3.x for new scope #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/get_module_path.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading