summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2011-03-25 16:25:09 -0700
committerJesse Wolfe <jes5199@gmail.com>2011-03-25 16:25:09 -0700
commit6985cc0f898d71dbd2ffbb353a2a482d9783cb42 (patch)
tree04aa795343486b7bb384836d2550dc9a6312ebe2 /spec/unit
parentcc53969290512b15819fbd72021f342fee2f28f5 (diff)
parentdaaa048a8d8829ad509b4a456826cc8a33cf6444 (diff)
downloadpuppet-6985cc0f898d71dbd2ffbb353a2a482d9783cb42.tar.gz
puppet-6985cc0f898d71dbd2ffbb353a2a482d9783cb42.tar.xz
puppet-6985cc0f898d71dbd2ffbb353a2a482d9783cb42.zip
Merge branch 'ticket/next/5477' into next
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/node/environment_spec.rb29
-rwxr-xr-xspec/unit/parser/lexer_spec.rb12
-rwxr-xr-xspec/unit/util/loadedfile_spec.rb7
-rwxr-xr-xspec/unit/util/rdoc/parser_spec.rb7
4 files changed, 36 insertions, 19 deletions
diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb
index 153be5f60..05527e70f 100755
--- a/spec/unit/node/environment_spec.rb
+++ b/spec/unit/node/environment_spec.rb
@@ -6,6 +6,7 @@ require 'puppet/node/environment'
require 'puppet/util/execution'
describe Puppet::Node::Environment do
+ include PuppetSpec::Files
after do
Puppet::Node::Environment.clear
end
@@ -276,16 +277,11 @@ describe Puppet::Node::Environment do
describe "when performing initial import" do
before do
- @parser = stub 'parser', :file= => nil, :string => nil, :parse => nil
+ @parser = stub 'parser'
Puppet::Parser::Parser.stubs(:new).returns @parser
@env = Puppet::Node::Environment.new("env")
end
- it "should create a new parser instance" do
- Puppet::Parser::Parser.expects(:new).returns @parser
- @env.instance_eval { perform_initial_import }
- end
-
it "should set the parser's string to the 'code' setting and parse if code is available" do
Puppet.settings[:code] = "my code"
@parser.expects(:string=).with "my code"
@@ -294,25 +290,26 @@ describe Puppet::Node::Environment do
end
it "should set the parser's file to the 'manifest' setting and parse if no code is available and the manifest is available" do
- File.stubs(:expand_path).with("/my/file").returns "/my/file"
- File.expects(:exist?).with("/my/file").returns true
- Puppet.settings[:manifest] = "/my/file"
- @parser.expects(:file=).with "/my/file"
+ filename = tmpfile('myfile')
+ File.open(filename, 'w'){|f| }
+ Puppet.settings[:manifest] = filename
+ @parser.expects(:file=).with filename
@parser.expects(:parse)
@env.instance_eval { perform_initial_import }
end
- it "should not attempt to load a manifest if none is present" do
- File.stubs(:expand_path).with("/my/file").returns "/my/file"
- File.expects(:exist?).with("/my/file").returns false
- Puppet.settings[:manifest] = "/my/file"
- @parser.expects(:file=).never
- @parser.expects(:parse).never
+ it "should pass the manifest file to the parser even if it does not exist on disk" do
+ filename = tmpfile('myfile')
+ Puppet.settings[:code] = ""
+ Puppet.settings[:manifest] = filename
+ @parser.expects(:file=).with(filename).once
+ @parser.expects(:parse).once
@env.instance_eval { perform_initial_import }
end
it "should fail helpfully if there is an error importing" do
File.stubs(:exist?).returns true
+ @parser.expects(:file=).once
@parser.expects(:parse).raises ArgumentError
lambda { @env.instance_eval { perform_initial_import } }.should raise_error(Puppet::Error)
end
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index 96df61348..bc9e22e48 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -676,3 +676,15 @@ describe "Puppet::Parser::Lexer in the old tests when lexing example files" do
end
end
end
+
+describe "when trying to lex an non-existent file" do
+ include PuppetSpec::Files
+
+ it "should return an empty list of tokens" do
+ lexer = Puppet::Parser::Lexer.new
+ lexer.file = nofile = tmpfile('lexer')
+ File.exists?(nofile).should == false
+
+ lexer.fullscan.should == [[false,false]]
+ end
+end
diff --git a/spec/unit/util/loadedfile_spec.rb b/spec/unit/util/loadedfile_spec.rb
index 23d2766d7..92daeb953 100755
--- a/spec/unit/util/loadedfile_spec.rb
+++ b/spec/unit/util/loadedfile_spec.rb
@@ -6,6 +6,7 @@ require 'tempfile'
require 'puppet/util/loadedfile'
describe Puppet::Util::LoadedFile do
+ include PuppetSpec::Files
before(:each) do
@f = Tempfile.new('loadedfile_test')
@f.puts "yayness"
@@ -18,6 +19,12 @@ describe Puppet::Util::LoadedFile do
@fake_now = Time.now + (2 * Puppet[:filetimeout])
end
+ it "should accept files that don't exist" do
+ nofile = tmpfile('testfile')
+ File.exists?(nofile).should == false
+ lambda{ Puppet::Util::LoadedFile.new(nofile) }.should_not raise_error
+ end
+
it "should recognize when the file has not changed" do
# Use fake "now" so that we can be sure changed? actually checks, without sleeping
# for Puppet[:filetimeout] seconds.
diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb
index ab54c8cd3..f118dc99b 100755
--- a/spec/unit/util/rdoc/parser_spec.rb
+++ b/spec/unit/util/rdoc/parser_spec.rb
@@ -20,8 +20,9 @@ describe RDoc::Parser do
@parser.stubs(:scan_top_level)
parser = stub 'parser'
Puppet::Parser::Parser.stubs(:new).returns(parser)
- parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
+ parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')).at_least_once
parser.expects(:file=).with("module/manifests/init.pp")
+ parser.expects(:file=).with("/dev/null/manifests/site.pp")
@parser.scan
end
@@ -29,7 +30,7 @@ describe RDoc::Parser do
it "should scan the ast for Puppet files" do
parser = stub_everything 'parser'
Puppet::Parser::Parser.stubs(:new).returns(parser)
- parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
+ parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')).at_least_once
@parser.expects(:scan_top_level)
@@ -39,7 +40,7 @@ describe RDoc::Parser do
it "should return a PuppetTopLevel to RDoc" do
parser = stub_everything 'parser'
Puppet::Parser::Parser.stubs(:new).returns(parser)
- parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
+ parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')).at_least_once
@parser.expects(:scan_top_level)