diff --git a/spec/integration/provider/mailalias/aliases_spec.rb b/spec/integration/provider/mailalias/aliases_spec.rb index 0511205f2..1bce13f90 100755 --- a/spec/integration/provider/mailalias/aliases_spec.rb +++ b/spec/integration/provider/mailalias/aliases_spec.rb @@ -1,25 +1,24 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppettest/support/utils' require 'puppettest/fileparsing' 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 it "should be able to parse the mailalias examples" do fakedata("data/providers/mailalias/aliases").each { |file| fakedataparse(file) } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0ee7d92a..ed4e826c9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,77 +1,81 @@ unless defined?(SPEC_HELPER_IS_LOADED) SPEC_HELPER_IS_LOADED = 1 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") # Don't want puppet getting the command line arguments for rake or autotest ARGV.clear require 'puppet' require 'mocha' gem 'rspec', '>=2.0.0' # 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 +module PuppetTest +end + require 'lib/puppet_spec/files' require 'monkey_patches/alias_should_to_must' require 'monkey_patches/publicize_methods' RSpec.configure do |config| config.mock_with :mocha config.after :each do Puppet.settings.clear Puppet::Node::Environment.clear Puppet::Util::Storage.clear if defined?($tmpfiles) $tmpfiles.each do |file| file = File.expand_path(file) if Puppet.features.posix? and file !~ /^\/tmp/ and file !~ /^\/var\/folders/ puts "Not deleting tmpfile #{file} outside of /tmp or /var/folders" next elsif Puppet.features.microsoft_windows? tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp")) if file !~ /^#{tempdir}/ puts "Not deleting tmpfile #{file} outside of #{tempdir}" next end end if FileTest.exist?(file) system("chmod -R 755 '#{file}'") system("rm -rf '#{file}'") end end $tmpfiles.clear end @logs.clear Puppet::Util::Log.close_all end config.before :each do # these globals are set by Application $puppet_application_mode = nil $puppet_application_name = nil # Set the confdir and vardir to gibberish so that tests # have to be correctly mocked. Puppet[:confdir] = "/dev/null" Puppet[:vardir] = "/dev/null" # Avoid opening ports to the outside world Puppet.settings[:bindaddress] = "127.0.0.1" @logs = [] Puppet::Util::Log.newdestination(@logs) end end end diff --git a/spec/spec_specs/runnable_spec.rb b/spec/spec_specs/runnable_spec.rb deleted file mode 100644 index da4faca4e..000000000 --- a/spec/spec_specs/runnable_spec.rb +++ /dev/null @@ -1,95 +0,0 @@ -require File.dirname(__FILE__) + '/../spec_helper' - -describe PuppetTest::RunnableTest do - before do - @runnable_test = Class.new.extend(PuppetTest::RunnableTest) - end - - describe "#confine" do - subject { @runnable_test } - - it "should accept a hash" do - subject.confine({}).should_not raise_error(ArgumentError) - end - - it "should accept a message and a block" do - subject.confine(""){}.should_not raise_error(ArgumentError) - end - - end - - describe "#runnable?" do - describe "when the superclass is not runnable" do - before { @runnable_test.stubs(:superclass).returns(stub("unrunnable superclass", :runnable? => false)) } - subject { @runnable_test.runnable? } - - it { should be_false } - end - - describe "when a confine is false" do - before { @runnable_test.confine(:message => false) } - subject { @runnable_test.runnable? } - - it { should be_false } - end - - describe "when a confine has a block that returns false" do - before { @runnable_test.confine(:message){ false } } - subject { @runnable_test.runnable? } - - it { should be_false } - end - - describe "when a confine is true and no false confines" do - before { @runnable_test.confine(:message => true) } - subject { @runnable_test.runnable? } - - it { should be_true } - end - - describe "when a confine has block that returns true and no false confines" do - before { @runnable_test.confine(:message){ true } } - subject { @runnable_test.runnable? } - - it { should be_true } - end - - end - - describe "#messages" do - describe "before runnable? is called" do - subject { @runnable_test.messages } - - it { should == [] } - end - - describe "when runnable? is called and returns false" do - before do - @runnable_test.confine(:message => false) - @runnable_test.runnable? - end - - subject { @runnable_test.messages } - - it "should include the failed confine's message" do - should include(:message) - end - - end - - describe "when runnable? is called whose block returns false" do - before do - @runnable_test.confine(:message){ false } - @runnable_test.runnable? - end - - subject { @runnable_test.messages } - - it "should include the failed confine's message" do - should include(:message) - end - - end - - end -end diff --git a/test/lib/puppettest/fileparsing.rb b/test/lib/puppettest/fileparsing.rb index 914c4bcb3..bd4f9e152 100644 --- a/test/lib/puppettest/fileparsing.rb +++ b/test/lib/puppettest/fileparsing.rb @@ -1,26 +1,28 @@ +require 'test/unit' + module PuppetTest::FileParsing # Run an isomorphism test on our parsing process. def fakedataparse(*files) files.each do |file| @provider.stubs(:default_target).returns(file) @provider.prefetch text = @provider.to_file(@provider.target_records(file)) text.gsub!(/^# HEADER.+\n/, '') yield if block_given? oldlines = File.readlines(file) newlines = text.chomp.split "\n" oldlines.zip(newlines).each do |old, new| if self.is_a?(Test::Unit::TestCase) assert_equal(old.chomp.gsub(/\s+/, ''), new.gsub(/\s+/, ''), "File was not written back out correctly") else new.gsub(/\s+/, '').should == old.chomp.gsub(/\s+/, '') end end end end end