This doesn't work without the later commits - it just relies on Ruby to read in Ruby files.
Signed-off-by: Luke Kanies <[email protected]> --- lib/puppet/parser/parser_support.rb | 10 ++++++++-- spec/unit/parser/parser.rb | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb index 1b961cd..df89ed7 100644 --- a/lib/puppet/parser/parser_support.rb +++ b/lib/puppet/parser/parser_support.rb @@ -5,6 +5,7 @@ class Puppet::Parser::Parser require 'puppet/parser/files' require 'puppet/parser/loaded_code' require 'puppet/parser/resource_type' + require 'puppet/dsl' require 'monitor' AST = Puppet::Parser::AST @@ -83,11 +84,11 @@ class Puppet::Parser::Parser end def file=(file) - unless FileTest.exists?(file) + unless FileTest.exist?(file) unless file =~ /\.pp$/ file = file + ".pp" end - unless FileTest.exists?(file) + unless FileTest.exist?(file) raise Puppet::Error, "Could not find file %s" % file end end @@ -317,6 +318,7 @@ class Puppet::Parser::Parser # how should I do error handling here? def parse(string = nil) + return parse_ruby_file if self.file =~ /\.rb$/ if string self.string = string end @@ -358,6 +360,10 @@ class Puppet::Parser::Parser @lexer.clear end + def parse_ruby_file + require self.file + end + # See if any of the files have changed. def reparse? if file = @files.detect { |name, file| file.changed? } diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb index 6a8b0e3..f10517f 100755 --- a/spec/unit/parser/parser.rb +++ b/spec/unit/parser/parser.rb @@ -12,6 +12,29 @@ describe Puppet::Parser do @true_ast = Puppet::Parser::AST::Boolean.new :value => true end + describe "when parsing files" do + before do + FileTest.stubs(:exist?).returns true + File.stubs(:open) + @parser.stubs(:check_and_add_to_watched_files).returns true + end + + it "should treat files ending in 'rb' as ruby files" do + @parser.expects(:parse_ruby_file) + @parser.file = "/my/file.rb" + @parser.parse + end + + describe "in ruby" do + it "should use the ruby interpreter to load the file" do + @parser.file = "/my/file.rb" + @parser.expects(:require).with "/my/file.rb" + + @parser.parse_ruby_file + end + end + end + describe "when parsing append operator" do it "should not raise syntax errors" do -- 1.6.1
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
