Sha256: be6442c4112683b7f02bf220500d13df23706a0e340091b5c80ccfe2e50ea44e

Contents?: true

Size: 1.46 KB

Versions: 35

Compression:

Stored size: 1.46 KB

Contents

#!/usr/bin/env rspec
require 'spec_helper'

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)

    $LOAD_PATH << 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

35 entries across 35 versions & 3 rubygems

Version Path
puppet-2.7.26 spec/integration/util/feature_spec.rb
puppet-2.7.25 spec/integration/util/feature_spec.rb
puppet-2.7.24 spec/integration/util/feature_spec.rb
puppet-2.7.23 spec/integration/util/feature_spec.rb
puppet-2.7.22 spec/integration/util/feature_spec.rb
puppet-2.7.21 spec/integration/util/feature_spec.rb
puppet-2.7.20 spec/integration/util/feature_spec.rb
puppet-2.7.20.rc1 spec/integration/util/feature_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/integration/util/feature_spec.rb
puppet-2.7.19 spec/integration/util/feature_spec.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/integration/util/feature_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/integration/util/feature_spec.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/spec/integration/util/feature_spec.rb
puppet-2.7.18 spec/integration/util/feature_spec.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/spec/integration/util/feature_spec.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/integration/util/feature_spec.rb
puppet-2.7.17 spec/integration/util/feature_spec.rb
puppet-2.7.16 spec/integration/util/feature_spec.rb
puppet-2.7.14 spec/integration/util/feature_spec.rb
puppet-2.7.13 spec/integration/util/feature_spec.rb