summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2011-03-25 16:10:03 -0700
committerJesse Wolfe <jes5199@gmail.com>2011-03-25 16:10:03 -0700
commita2ac367c2bea2b94b88f739250edb828da0091d4 (patch)
treec8abe56ae0baf82ef51c5a27a3814bec42a8f890 /spec
parent0fec21fcd887685cf8421fdc309b878088f9fc48 (diff)
parent7c60db5d9db8eeda46f7041100759e69aed120a8 (diff)
Merge branch 'ticket/2.6.next/5477' into 2.6.next
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/parser/lexer_spec.rb12
-rw-r--r--spec/unit/resource/type_collection_spec.rb31
-rwxr-xr-xspec/unit/util/loadedfile_spec.rb7
-rwxr-xr-xspec/unit/util/rdoc/parser_spec.rb3
4 files changed, 35 insertions, 18 deletions
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index 4ef242cf5..d144504c5 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -679,3 +679,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/resource/type_collection_spec.rb b/spec/unit/resource/type_collection_spec.rb
index ff4c22234..cf7039a51 100644
--- a/spec/unit/resource/type_collection_spec.rb
+++ b/spec/unit/resource/type_collection_spec.rb
@@ -6,6 +6,7 @@ require 'puppet/resource/type_collection'
require 'puppet/resource/type'
describe Puppet::Resource::TypeCollection do
+ include PuppetSpec::Files
before do
@instance = Puppet::Resource::Type.new(:hostclass, "foo")
@code = Puppet::Resource::TypeCollection.new("env")
@@ -276,7 +277,7 @@ describe Puppet::Resource::TypeCollection do
end
end
-
+
it "should not look in the local scope for classes when the name is qualified" do
@loader = Puppet::Resource::TypeCollection.new("env")
@loader.add Puppet::Resource::Type.new(:hostclass, "foo::bar")
@@ -386,16 +387,11 @@ describe Puppet::Resource::TypeCollection 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
@code = Puppet::Resource::TypeCollection.new("env")
end
- it "should create a new parser instance" do
- Puppet::Parser::Parser.expects(:new).returns @parser
- @code.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"
@@ -404,26 +400,27 @@ describe Puppet::Resource::TypeCollection 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)
@code.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
@code.perform_initial_import
end
it "should fail helpfully if there is an error importing" do
File.stubs(:exist?).returns true
@parser.expects(:parse).raises ArgumentError
+ @parser.stubs(:file=)
lambda { @code.perform_initial_import }.should raise_error(Puppet::Error)
end
end
diff --git a/spec/unit/util/loadedfile_spec.rb b/spec/unit/util/loadedfile_spec.rb
index 3bc26a421..c6fd625fc 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 b4453ae86..6ae28b40a 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)
+ parser.expects(:parse).at_least_once
parser.expects(:file=).with("module/manifests/init.pp")
+ parser.expects(:file=).with("/dev/null/manifests/site.pp")
@parser.scan
end