Sha256: 6f8ea692515bc6f7bd9c50f81df6365c8593c5e00ef3a75959351542de5eea13

Contents?: true

Size: 1.71 KB

Versions: 6

Compression:

Stored size: 1.71 KB

Contents

#!/usr/bin/env ruby

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/util/feature'
require 'puppet_spec/files'

describe Puppet::Util::Feature do
    include PuppetSpec::Files

    it "should be able to load features from disk" do
        libdir = tmpfile("feature_lib")
        Dir.mkdir(libdir)

        $: << libdir

        $features = Puppet::Util::Feature.new("feature_lib")

        Dir.mkdir(File.join(libdir, "feature_lib"))

        File.open(File.join(libdir, "feature_lib", "able_to_load.rb"), "w") do |f|
            f.puts "$features.add(:able_to_load) { true }"
        end

        $features.should be_able_to_load
    end

    # TODO: Make this a spec test or remove it.
    def test_dynamic_loading
        $features = @features
        cleanup { $features = nil }
        # Now create a feature and make sure it loads.
        FileUtils.mkdir_p(@path)
        nope = File.join(@path, "nope.rb")
        File.open(nope, "w") { |f|
            f.puts "$features.add(:nope, :libs => %w{nosuchlib})"
        }
        assert_nothing_raised("Failed to autoload features") do
            assert(! @features.nope?, "'nope' returned true")
        end

        # First make sure "yep?" returns false
        assert_nothing_raised("Missing feature threw an exception") do
            assert(! @features.notyep?, "'notyep' returned true before definition")
        end

        yep = File.join(@path, "yep.rb")
        File.open(yep, "w") { |f|
            f.puts "$features.add(:yep, :libs => %w{puppet})"
        }

        assert(@features.yep?, "false 'yep' is apparently cached or feature could not be loaded")
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puppet-0.25.5 spec/integration/util/feature.rb
puppet-0.25.4 spec/integration/util/feature.rb
puppet-0.25.3 spec/integration/util/feature.rb
puppet-0.25.2 spec/integration/util/feature.rb
puppet-0.25.1 spec/integration/util/feature.rb
puppet-0.25.0 spec/integration/util/feature.rb