diff options
author | Matt Robinson <matt@puppetlabs.com> | 2010-07-02 22:19:28 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2010-09-03 02:53:01 +1000 |
commit | 07d0be4684f75e6edc6fbb5d1397dd79b8ca2b6b (patch) | |
tree | 9e8aa9c180f8cdff17bc6c000f9d4ce5dcc560d8 | |
parent | 9e696164237821fb6b48a913395240d376f8c3da (diff) | |
download | puppet-07d0be4684f75e6edc6fbb5d1397dd79b8ca2b6b.tar.gz puppet-07d0be4684f75e6edc6fbb5d1397dd79b8ca2b6b.tar.xz puppet-07d0be4684f75e6edc6fbb5d1397dd79b8ca2b6b.zip |
[#4308] Remove puppettest from specs
The less stuff being done in the spec_helper the better for reasoning
about what's happening in the tests. puppettest.rb does a lot of things
that aren't necessary for the specs, so this patch gets those things out
of the spec_helper.
Reviewed by: Jesse Wolfe
-rwxr-xr-x | spec/integration/provider/mailalias/aliases_spec.rb | 10 | ||||
-rw-r--r-- | spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb | 1 | ||||
-rw-r--r-- | spec/monkey_patches/publicize_methods.rb | 11 | ||||
-rw-r--r-- | spec/spec_helper.rb | 30 | ||||
-rwxr-xr-x | spec/unit/network/http/webrick/rest_spec.rb | 1 | ||||
-rwxr-xr-x | spec/unit/parser/lexer_spec.rb | 1 | ||||
-rwxr-xr-x | spec/unit/provider/ssh_authorized_key/parsed_spec.rb | 6 | ||||
-rwxr-xr-x | spec/unit/reports/tagmail_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/util/backups_spec.rb | 1 | ||||
-rw-r--r-- | test/lib/mocha_standalone.rb | 2 | ||||
-rwxr-xr-x | test/lib/puppettest.rb | 22 | ||||
-rw-r--r-- | test/lib/puppettest/fakes.rb | 2 | ||||
-rw-r--r-- | test/lib/puppettest/support/assertions.rb | 2 | ||||
-rw-r--r-- | test/lib/puppettest/support/utils.rb | 45 |
14 files changed, 54 insertions, 84 deletions
diff --git a/spec/integration/provider/mailalias/aliases_spec.rb b/spec/integration/provider/mailalias/aliases_spec.rb index 8106c2cb5..0511205f2 100755 --- a/spec/integration/provider/mailalias/aliases_spec.rb +++ b/spec/integration/provider/mailalias/aliases_spec.rb @@ -2,7 +2,6 @@ require File.dirname(__FILE__) + '/../../../spec_helper' -require 'puppettest' require 'puppettest/support/utils' require 'puppettest/fileparsing' @@ -11,15 +10,16 @@ provider_class = Puppet::Type.type(:mailalias).provider(:aliases) describe provider_class do include PuppetTest include PuppetTest::FileParsing + include PuppetTest::Support::Utils before :each do @provider = provider_class end # #1560 - PuppetTest.fakedata("data/providers/mailalias/aliases").each { |file| - it "should be able to parse the examples in #{file}" do + it "should be able to parse the mailalias examples" do + fakedata("data/providers/mailalias/aliases").each { |file| fakedataparse(file) - end - } + } + end end diff --git a/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb b/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb index 15a7cd0ac..3762b7033 100644 --- a/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +++ b/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb @@ -5,7 +5,6 @@ dir = File.expand_path(File.dirname(__FILE__)) end require 'spec' -require 'puppettest' require 'puppettest/runnable_test' module Spec diff --git a/spec/monkey_patches/publicize_methods.rb b/spec/monkey_patches/publicize_methods.rb new file mode 100644 index 000000000..b39e9c002 --- /dev/null +++ b/spec/monkey_patches/publicize_methods.rb @@ -0,0 +1,11 @@ +# Some monkey-patching to allow us to test private methods. +class Class + def publicize_methods(*methods) + saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods + + self.class_eval { public(*saved_private_instance_methods) } + yield + self.class_eval { private(*saved_private_instance_methods) } + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 539ae2040..ab7ff6caf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,20 +6,8 @@ dir = File.expand_path(File.dirname(__FILE__)) $LOAD_PATH.unshift("#{dir}/") $LOAD_PATH.unshift("#{dir}/lib") # a spec-specific test lib dir $LOAD_PATH.unshift("#{dir}/../lib") -$LOAD_PATH.unshift("#{dir}/../test/lib") # Add the old test dir, so that we can still find our local mocha and spec -# include any gems in vendor/gems -Dir["#{dir}/../vendor/gems/**"].each do |path| - libpath = File.join(path, "lib") - if File.directory?(libpath) - $LOAD_PATH.unshift(libpath) - else - $LOAD_PATH.unshift(path) - end -end - -require 'puppettest' -require 'puppettest/runnable_test' +require 'puppet' require 'mocha' gem 'rspec', '>=1.2.9' require 'spec/autorun' @@ -29,17 +17,13 @@ module PuppetSpec FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR) end -# load any monkey-patches -Dir["#{dir}/monkey_patches/*.rb"].map { |file| require file } +require 'monkey_patches/alias_should_to_must' +require 'monkey_patches/add_confine_and_runnable_to_rspec_dsl' +require 'monkey_patches/publicize_methods' Spec::Runner.configure do |config| config.mock_with :mocha -# config.prepend_before :all do -# setup_mocks_for_rspec -# setup if respond_to? :setup -# end -# config.prepend_after :each do Puppet.settings.clear Puppet::Node::Environment.clear @@ -88,10 +72,4 @@ Spec::Runner.configure do |config| end end -# We need this because the RAL uses 'should' as a method. This -# allows us the same behaviour but with a different method name. -class Object - alias :must :should -end - end diff --git a/spec/unit/network/http/webrick/rest_spec.rb b/spec/unit/network/http/webrick/rest_spec.rb index aa2b93176..b00c62dc4 100755 --- a/spec/unit/network/http/webrick/rest_spec.rb +++ b/spec/unit/network/http/webrick/rest_spec.rb @@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../../../../spec_helper' require 'puppet/network/http' +require 'webrick' require 'puppet/network/http/webrick/rest' describe Puppet::Network::HTTP::WEBrickREST do diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb index 7e51423f4..b27980bf2 100755 --- a/spec/unit/parser/lexer_spec.rb +++ b/spec/unit/parser/lexer_spec.rb @@ -644,7 +644,6 @@ end require 'puppettest/support/utils' describe "Puppet::Parser::Lexer in the old tests when lexing example files" do - extend PuppetTest extend PuppetTest::Support::Utils textfiles do |file| it "should correctly lex #{file}" do diff --git a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb index 059d010bb..648527924 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb @@ -3,14 +3,16 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet_spec/files' -require 'puppettest' require 'puppettest/support/utils' require 'puppettest/fileparsing' +require 'tmpdir' +require 'puppettest/fakes' provider_class = Puppet::Type.type(:ssh_authorized_key).provider(:parsed) describe provider_class do include PuppetSpec::Files + extend PuppetTest::Support::Utils include PuppetTest include PuppetTest::FileParsing @@ -49,7 +51,7 @@ describe provider_class do @provider.target_object(@keyfile).read end - PuppetTest.fakedata("data/providers/ssh_authorized_key/parsed").each { |file| + fakedata("data/providers/ssh_authorized_key/parsed").each { |file| it "should be able to parse example data in #{file}" do fakedataparse(file) end diff --git a/spec/unit/reports/tagmail_spec.rb b/spec/unit/reports/tagmail_spec.rb index 4349e999d..59cb5b2b8 100755 --- a/spec/unit/reports/tagmail_spec.rb +++ b/spec/unit/reports/tagmail_spec.rb @@ -3,12 +3,12 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } require 'puppet/reports' -require 'puppettest' +require 'puppettest/support/utils' tagmail = Puppet::Reports.report(:tagmail) describe tagmail do - extend PuppetTest + extend PuppetTest::Support::Utils before do @processor = Puppet::Transaction::Report.new diff --git a/spec/unit/util/backups_spec.rb b/spec/unit/util/backups_spec.rb index 5c10d4c3c..259b18652 100755 --- a/spec/unit/util/backups_spec.rb +++ b/spec/unit/util/backups_spec.rb @@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/util/backups' -include PuppetTest describe Puppet::Util::Backups do before do diff --git a/test/lib/mocha_standalone.rb b/test/lib/mocha_standalone.rb deleted file mode 100644 index ce605811a..000000000 --- a/test/lib/mocha_standalone.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'mocha/standalone' -require 'mocha/object' diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 294d0ef8d..0b3a89a72 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -6,17 +6,6 @@ mainlib = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) $LOAD_PATH.unshift(mainlib) unless $LOAD_PATH.include?(mainlib) require 'puppet' - -# include any gems in vendor/gems -Dir["#{mainlib}/../vendor/gems/**"].each do |path| - libpath = File.join(path, "lib") - if File.directory?(libpath) - $LOAD_PATH.unshift(libpath) - else - $LOAD_PATH.unshift(path) - end -end - require 'mocha' # Only load the test/unit class if we're not in the spec directory. @@ -31,16 +20,7 @@ if ARGV.include?("-d") $console = true end -# Some monkey-patching to allow us to test private methods. -class Class - def publicize_methods(*methods) - saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods - - self.class_eval { public(*saved_private_instance_methods) } - yield - self.class_eval { private(*saved_private_instance_methods) } - end -end +require File.expand_path(File.join(File.dirname(__FILE__), '../../spec/monkey_patches/publicize_methods')) module PuppetTest # These need to be here for when rspec tests use these diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb index aaa711004..712332b74 100644 --- a/test/lib/puppettest/fakes.rb +++ b/test/lib/puppettest/fakes.rb @@ -1,4 +1,4 @@ -require 'puppettest' +require File.expand_path(File.join(File.dirname(__FILE__), '../../../lib/puppet/util')) module PuppetTest # A baseclass for the faketypes. diff --git a/test/lib/puppettest/support/assertions.rb b/test/lib/puppettest/support/assertions.rb index 7f326b119..31fa3f1da 100644 --- a/test/lib/puppettest/support/assertions.rb +++ b/test/lib/puppettest/support/assertions.rb @@ -1,8 +1,6 @@ -require 'puppettest' require 'puppettest/support/utils' require 'fileutils' - module PuppetTest include PuppetTest::Support::Utils def assert_logged(level, regex, msg = nil) diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb index edc81d3d6..e022f123c 100644 --- a/test/lib/puppettest/support/utils.rb +++ b/test/lib/puppettest/support/utils.rb @@ -1,5 +1,3 @@ -require 'puppettest' - module PuppetTest::Support end module PuppetTest::Support::Utils @@ -7,6 +5,30 @@ module PuppetTest::Support::Utils Puppet.warning "#{type}: #{ObjectSpace.each_object(type) { |o| }}" end + def basedir(*list) + unless defined? @@basedir + Dir.chdir(File.dirname(__FILE__)) do + @@basedir = File.dirname(File.dirname(File.dirname(File.dirname(Dir.getwd)))) + end + end + if list.empty? + @@basedir + else + File.join(@@basedir, *list) + end + end + + def fakedata(dir,pat='*') + glob = "#{basedir}/test/#{dir}/#{pat}" + files = Dir.glob(glob,File::FNM_PATHNAME) + raise Puppet::DevError, "No fakedata matching #{glob}" if files.empty? + files + end + + def datadir(*list) + File.join(basedir, "test", "data", *list) + end + # # TODO: I think this method needs to be renamed to something a little more # explanatory. @@ -38,10 +60,6 @@ module PuppetTest::Support::Utils config end - # stop any services that might be hanging around - def stopservices - end - # TODO: rewrite this to use the 'etc' module. # Define a variable that contains the name of my user. @@ -84,7 +102,7 @@ module PuppetTest::Support::Utils end def fakefile(name) - ary = [PuppetTest.basedir, "test"] + ary = [basedir, "test"] ary += name.split("/") file = File.join(ary) raise Puppet::DevError, "No fakedata file #{file}" unless FileTest.exists?(file) @@ -140,16 +158,3 @@ module PuppetTest::Support::Utils config end end - -module PuppetTest - include PuppetTest::Support::Utils - - def fakedata(dir,pat='*') - glob = "#{basedir}/test/#{dir}/#{pat}" - files = Dir.glob(glob,File::FNM_PATHNAME) - raise Puppet::DevError, "No fakedata matching #{glob}" if files.empty? - files - end - module_function :fakedata - -end |