Sha256: 25314ad225829d6d66eda97553e3e6a17c4b963962f5ec45412a39a7ae9b004b

Contents?: true

Size: 1.66 KB

Versions: 165

Compression:

Stored size: 1.66 KB

Contents

# This module provides some helper methods to assist with fixtures. It's
# methods are designed to help when you have a conforming fixture layout so we
# get project consistency.
module PuppetlabsSpec::Fixtures

  # Returns the joined path of the global FIXTURE_DIR plus any path given to it
  def fixtures(*rest)
    File.join(PuppetlabsSpec::FIXTURE_DIR, *rest)
  end

  # Returns the path to your relative fixture dir. So if your spec test is
  # <project>/spec/unit/facter/foo_spec.rb then your relative dir will be
  # <project>/spec/fixture/unit/facter/foo
  def my_fixture_dir
    callers = caller
    while line = callers.shift do
      next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
      return fixtures(found[1])
    end
    fail "sorry, I couldn't work out your path from the caller stack!"
  end

  # Given a name, returns the full path of a file from your relative fixture
  # dir as returned by my_fixture_dir.
  def my_fixture(name)
    file = File.join(my_fixture_dir, name)
    unless File.readable? file then
      fail "fixture '#{name}' for #{my_fixture_dir} is not readable"
    end
    return file
  end

  # Return the contents of the file using read when given a name. Uses
  # my_fixture to work out the relative path.
  def my_fixture_read(name)
    File.read(my_fixture(name))
  end

  # Provides a block mechanism for iterating across the files in your fixture
  # area.
  def my_fixtures(glob = '*', flags = 0)
    files = Dir.glob(File.join(my_fixture_dir, glob), flags)
    unless files.length > 0 then
      fail "fixture '#{glob}' for #{my_fixture_dir} had no files!"
    end
    block_given? and files.each do |file| yield file end
    files
  end
end

Version data entries

165 entries across 165 versions & 4 rubygems

Version Path
puppetlabs_spec_helper-2.5.1 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.5.0 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.4.0 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
facter-2.5.1 spec/puppetlabs_spec/fixtures.rb
facter-2.5.1-x86-mingw32 spec/puppetlabs_spec/fixtures.rb
facter-2.5.1-x64-mingw32 spec/puppetlabs_spec/fixtures.rb
facter-2.5.1-universal-darwin spec/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.3.2 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.3.1 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.3.0 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
facter-2.5.0 spec/puppetlabs_spec/fixtures.rb
facter-2.5.0-x86-mingw32 spec/puppetlabs_spec/fixtures.rb
facter-2.5.0-x64-mingw32 spec/puppetlabs_spec/fixtures.rb
facter-2.5.0-universal-darwin spec/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.2.0 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.1.5 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.1.4 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.1.3 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.1.2 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
puppetlabs_spec_helper-2.1.1 lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb