-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #379 from puppetlabs/CONT-515-fix_uninitialized_co…
…nstant_error (CONT-515) Fix uninitialized constant error
- Loading branch information
Showing
6 changed files
with
510 additions
and
502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
# 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) | ||
next unless (found = line.match(%r{/spec/(.*)_spec\.rb:})) | ||
|
||
return fixtures(found[1]) | ||
module PuppetlabsSpec | ||
# 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 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 | ||
raise "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 | ||
raise "fixture '#{name}' for #{my_fixture_dir} is not readable" | ||
# 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) | ||
next unless (found = line.match(%r{/spec/(.*)_spec\.rb:})) | ||
|
||
return fixtures(found[1]) | ||
end | ||
raise "sorry, I couldn't work out your path from the caller stack!" | ||
end | ||
|
||
file | ||
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 | ||
raise "fixture '#{name}' for #{my_fixture_dir} is not readable" | ||
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 | ||
file | ||
end | ||
|
||
# Provides a block mechanism for iterating across the files in your fixture | ||
# area. | ||
def my_fixtures(glob = '*', flags = 0, &block) | ||
files = Dir.glob(File.join(my_fixture_dir, glob), flags) | ||
if files.empty? | ||
raise "fixture '#{glob}' for #{my_fixture_dir} had no files!" | ||
# 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 | ||
|
||
block && files.each(&block) | ||
files | ||
# Provides a block mechanism for iterating across the files in your fixture | ||
# area. | ||
def my_fixtures(glob = '*', flags = 0, &block) | ||
files = Dir.glob(File.join(my_fixture_dir, glob), flags) | ||
if files.empty? | ||
raise "fixture '#{glob}' for #{my_fixture_dir} had no files!" | ||
end | ||
|
||
block && files.each(&block) | ||
files | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.