summaryrefslogtreecommitdiff
path: root/spec/unit/util/autoload_spec.rb
AgeCommit message (Collapse)AuthorFilesLines
2014-10-13(maint) Separate test for missing module directoryAndrew Parker1-2/+7
The test of behavior when a module directory is specified as part of an environment but is missing on disk was hidden inside another test. This splits it out and calls out that the behavior is that the directory is simply ignored.
2014-10-13(PUP-3244) Allow autoload to handle missing environmentAndrew Parker1-13/+27
When a previous commit changed from get() to get!() the agent stopped being able to use an environment that is available on the master, but not available locally. I had misread the code and missed a trailing `&&`. This caused me to think that the environment lookup in this case was required, where in fact it is still optional. This changes the structure of the code to make it much clearer that the environment is optional, changes from get!() to get(), and adds some tests around these code paths.
2014-04-07(PUP-2158) Default a missing manifest to no_manifestAndrew Parker1-1/+1
The tests were often creating environments that didn't need to have manifests. Since we didn't have a way of specifying that when they were written, we used '' to fill in the blank. This actually caused a large number of tests to try to find code to load in the PWD, which caused tests to break if a developer had parse errors in manifests being used for testing in the root directory of their puppet project. This changes the manifest to be optional and removes '' from those tests. The tests no longer fail if a bad manifest is in the PWD :D
2014-01-29(PUP-1118) Stop using Environment.newAndrew Parker1-28/+5
Instead of creating environments directly, we need to go through the configured environment loaders, otherwise environments can't come from other places.
2014-01-23(PUP-1118) Load full environments from a directoryAndrew Parker1-11/+11
This changes the loader used by the code to list environments to be a composition of the legacy environments and the new directory environments.
2014-01-06(PUP-716) Fix up all of utilAndrew Parker1-14/+14
2013-12-12(#23373) Pull apart settings into a few more classesAndrew Parker1-2/+10
The monolithic settings infrastructure is really hard to work with. In order to implement the functionality for puppet config print to reliably be able to print the value of any given section of the configuration I need to be able to split it apart from the very static structure that exists inside puppet. This takes a step in that direction by starting the process of extracting the lookup logic into smaller classes.
2013-11-08(#19447) Puppet::FileSystem::File.exist?Ethan J. Brown1-14/+14
- All previous File and FileTest calls to exist? or exists? go through the new FileSystem::File abstraction so that the implementation can later be swapped for a Windows specific one to support symlinks
2012-12-05(#7316) Add method to expand autoloaded pathsJosh Cooper1-0/+6
Several places use an Autoloader to list files that could be loaded relative to some prefix, e.g. puppet/application. But then the same prefix is specified again when requiring a specific instance, e.g. require File.join('puppet', 'application', name) This commit adds an Autoload instance method to expand a path, so the above becomes: require @loader.expand(name)
2012-10-04Revert "Merge pull request #1190 from ↵Jeff McCune1-1/+1
jeffmccune/fix/master/7316_load_faces_from_modulepath_try4" This reverts commit bdda511d06ed6f89b58343e815585957a33db94e, reversing changes made to 8f9699cee0d1028d538b0a26aa5bc885751b6d46. Conflicts: lib/puppet/settings/config_file.rb
2012-09-26Revert "Revert "Merge branch 'fix/3.x/7316_load_faces_from_modulepath_try3' ↵Jeff McCune1-1/+1
into 3.x"" This reverts commit ef3fe695fd0be5ff2b5aeb563f34f62a0f503831.
2012-09-26(Maint) Remove rspec from shebang lineJeff McCune1-1/+1
Without this patch Ruby 1.9 is still complaining loudly about trying to parse the spec files. The previous attempt to clean up this problem in edc3ddf works for Ruby 1.8 but not 1.9. I'd prefer to remove the shebang lines entirely, but doing so will cause encoding errors in Ruby 1.9. This patch strives for a happy middle ground of convincing Ruby it is actually working with Ruby while not confusing it to think it should exec() to rspec. This patch is the result of the following command run against the source tree: find spec -type f -print0 | \ xargs -0 perl -pl -i -e 's,^\#\!\s?/(.*)rspec,\#! /usr/bin/env ruby,'
2012-09-25Revert "Merge branch 'fix/3.x/7316_load_faces_from_modulepath_try3' into 3.x"Andrew Parker1-1/+1
This reverts commit b277bb3874ecd50e1cd6e600bf6d36e3240d5510, reversing changes made to bdf193640701e9a107b1c6f6661499b31fdefb4d. These changes are being backed out because they referenced a undefined methods (`default_global_config_dir` and `default_global_var_dir`). After fixing that locally, there was still a problem with `puppet help` printing out a large number of warnings because it could not load face code correctly. I think we need to step back from this, re-evaluate what is happening, and try a new approach.
2012-09-24(#15214) Remove confdir and vardir from run_modeChris Price1-1/+1
Prior to this commit, the vardir and confdir settings were tied to run_mode. This caused a chicken-and-egg problem where you could not initialize the confdir and vardir until you'd loaded the application/subcommand, because that is the first point in time where you'd know the run_mode. However, without knowing the confdir/vardir ahead of time, it's impossible to know where all you might need to look to try to find the application/subcommand for loading. This commit decouples those settings from run_mode. The default values for them are now set solely based on whether the user is root or not. Individual applications may override these defaults a bit later in the life cycle (e.g., 'master' does this). Conflicts: lib/puppet/settings.rb lib/puppet/util/autoload.rb lib/puppet/util/run_mode.rb spec/unit/util/run_mode_spec.rb
2012-08-22(#7788) Rely on Rubygems caching of directoriesPatrick Carlisle1-10/+0
Previously the list of rubygem directories was kept in a thread local cache. Instead of doing that outright we'll try relying on the rubygem caching before we go down the path of trying to do that ourselves.
2012-08-22(#7788) Extend Puppet using rubygemsKelsey Hightower1-2/+13
The autoloader includes rubygems in the search path when searching for modules to load. Puppet can now load things like Faces, report processors, and parser functions using rubygems. Example: $ gem install puppetlabs-cloud_provisioner-1.0.4.gem ... Successfully installed fog-1.3.1 Successfully installed guid-0.1.1 Successfully installed puppetlabs-cloud_provisioner-1.0.4 $ puppet help Usage: puppet <subcommand> [options] <action> [options] Available subcommands: ... node_aws View and manage Amazon AWS EC2 nodes. This patch adds a new `Puppet::Util::RubyGems#directories` method for locating the latest gems and their load paths. This method is used in two places: * When searching for subcommands * When auto loading plug-ins Updated specs are included.
2012-07-23Reduce stubs and expectations on settingsPatrick Carlisle1-4/+4
Many tests set stubs or expectations on configuration values. This is unnecessary, as settings are reset before each test. Because creating a stub stubs out the entire value method on settings, stubbing any individual setting interferes with retrieving any other setting. This makes for weird errors and fragile tests. This commit changes most cases to just set each setting directly. Expectations on settings were often used to verify that a setting is used. This is not a good way of testing this, since it checks that the value is accessed but not that it is actually used correctly. Most expecations on settings are better expressed by changing the setting and then verifying a returned value.
2012-07-05Refactor module to require path and environment argsPatrick Carlisle1-3/+3
2012-07-02(maint) Standardize on /usr/bin/env ruby -S rspecJeff McCune1-1/+1
Without this patch some spec files are using `ruby -S rspec` and others are using `rspec`. We should standardize on a single form of the interpreter used for spec files. `ruby -S rspec` is the best choice because it correctly informs editors such as Vim with Syntastic that the file is a Ruby file rather than an Rspec file.
2012-06-07(#14789) Fix inconsistent normalization and API in autoloaderPatrick Carlisle1-0/+28
Since I didn't get around to adding a require method to the autoloader, it still makes sense to have the loaded? method exposed on instances. I also added the changed? method, which would be useful in similar situations. Testing these changes revealed inconsistency about how names are normalized, which is also fixed in this commit.
2012-04-30Use expand_path to normalize paths in autoloaderPatrick Carlisle1-11/+25
Just using Pathname#cleanpath didn't properly convert \ to / on windows. Using both should give correct normalized paths. This also cleans up the specs to work better with Windows paths, as problems there were revealed by this change.
2012-03-30Remove the "fails_on_ruby_1.9.2" tag from tests...Daniel Pittman1-2/+2
Now we have passing tests on Ruby 1.9, we can make all those tags go away and enable the full suite. Now anything that fails should be treated like a real failure, which is reasonable since this is a real and supported platform. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-03-30Calling map on string now fails, rather than yielding the string.Daniel Pittman1-1/+1
In Ruby 1.8 `"foo".map` would yield "foo" once, while in Ruby 1.9 it is not defined as a method. Various parts of our testing code stub other methods and return strings where arrays of strings are appropriate; this historically worked because of that 1.8 shim, and no longer does. The same is true of `String#each`, which fails in the same way. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-03-20(#7749) Improvements to handling settings, bootstrapping puppetcprice1-0/+3
Major changes include: * support multiple config files (/etc/puppet, ~/.puppet). we no longer use "run_mode" to determine the location of the config file. * remove all references to application run_mode/state from defaults * make the typing of settings a little more strict * create a new setting type for directories, to make us a little less vulnerable to the terrible matching algorithm in FileSetting
2012-02-28(#12126) Fix autoload spec on windowsPatrick Carlisle1-1/+1
When setting libdir the path is expanded, so using the actual libdir setting in the test instead of expecting it to remain what we initially set it to.
2012-02-27(#12126) Normalize path names to avoid unnecessary reloadingPatrick Carlisle1-0/+13
2012-02-27(#12126) Remove unnecessary searchpath methodPatrick Carlisle1-13/+3
2012-02-27(#12126) When reloading files detect changes anywhere in the load pathPatrick Carlisle1-3/+15
Prior to this change, if a file is loaded, and a new version is placed at a higher priority location in the load path, reload_changed would not detect it. This makes it properly detected so the first copy in the load path at the time reload_changed is called will always be loaded.
2012-02-27Remove Puppet::Util::Autoload::FileCache.Patrick Carlisle1-4/+0
This cache module was complex and had obvious bugs in it, and it's not clear that it was necessary. We'll add something back if it turns out we needed to cache file operations in the autoloader.
2012-02-27(#12126) Implement reloading changed filesPatrick Carlisle1-0/+54
This adds a reload_changed method to the autoloader. It checks all loaded files for changes (based on the mtime of the files) and reload any paths that have changed. Deleted files are still listed as loaded since there is no way to actually unload code in Ruby.
2012-02-27(#12126) Track mtime of autoloaded filesPatrick Carlisle1-0/+4
2012-02-27(#12126) Refactor Puppet::Util::AutoloadPatrick Carlisle1-15/+17
This consolidates all the the loading logic into the singleton associated with the Autoload class. The Autoload instance is now a thin proxy to this singleton. This may not seem like an improvement in the short term but it lays the groundwork for reloading support. Having the logic in the singleton gives load methods access to the full tree of loaded files, which will be necessary when we want to reload all changed files.
2012-02-27(#12126) Improve autoloading specsPatrick Carlisle1-9/+30
In preparation for refactoring, this adds some specs for the autoloader and cleans up the depedency on PuppetSpec in the existing specs.
2012-02-27(#12126) Rename loaded to mark_loaded to avoid conflict with new accessorPatrick Carlisle1-0/+4
2011-07-21Remove dead uses of Puppet::Util::Cacher from autoloaderNick Lewis1-4/+0
In the past, Puppet::Util::Autoload used a cached_attr for its 'searchpath'. However, it no longer does that, so its references to Puppet::Util::Cacher are unnecessary. Reviewed-By: Jacob Helwig <jacob@puppetlabs.com>
2011-07-19Fix tests with "relative" paths on WindowsJosh Cooper1-15/+23
Absolute paths on Unix, e.g. /foo/bar, are not absolute on Windows, which breaks many test cases. This commit adds a method to PuppetSpec::Files.make_absolute that makes the path absolute in test cases. On Unix (Puppet.features.posix?) it is a no-op. On Windows, (Puppet.features.microsoft_windows?) the drive from the current working directory is prepended. Reviewed-by: Jacob Helwig <jacob@puppetlabs.com>
2011-05-26maint: Dedup the loadpath so we don't have to walk it multiple timesMatt Robinson1-2/+2
If the user's path has duplicate entries, we end up looking at them multiple times. This has bitten people in the past in that if you get a lot of duplication it can make autloading a lot slower. Really the user shouldn't be duplicating their path, but since we can't control that, this is a safe fix to prevent them from having autoload slowness. Paired-with: Max Martin <max@puppetlabs.com>
2011-05-17(#7507) Add ability to filter Ruby 1.9 spec failuresMatt Robinson1-2/+2
By running: rspec spec --tag ~@fails_on_ruby_1.9.2 We can now just run the specs that pass under Ruby 1.9. Obviously in the long term we want to have all the specs passing, but until then we need notification when we regress. From now on new code will be required to pass under Ruby 1.9, and Jenkins will give us email notification if it doesn't or if we break something that was already working. Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
2011-04-13maint: clean up the spec test headers in bulk.Daniel Pittman1-2/+1
We now use a shebang of: #!/usr/bin/env rspec This enables the direct execution of spec tests again, which was lost earlier during the transition to more directly using the rspec2 runtime environment.
2011-04-08maint: just require 'spec_helper', thanks rspec2Daniel Pittman1-1/+1
rspec2 automatically sets a bunch of load-path stuff we were by hand, so we can just stop. As a side-effect we can now avoid a whole pile of stupid things to try and include the spec_helper.rb file... ...and then we can stop protecting spec_helper from evaluating twice, since we now require it with a consistent name. Yay. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-03-22maint: Change code for finding spec_helper to work with Ruby 1.9Matt Robinson1-1/+1
Running the specs under Ruby 1.9 didn't work using the lambda to recurse down directories to find the spec_helper. Standardizing the way to find spec_helper like the rest of specs seemed like the way to go. Here's the command line perl I used to make the change: perl -p -i -e "s/Dir.chdir.*lambda.*spec_helper.*$/require File.expand_path(File.dirname(__FILE__) + '\/..\/..\/spec_helper')/" `find spec -name "*_spec.rb"` Then I fixed the number of dots for files that weren't two levels from the spec dir and whose tests failed. Reviewed-by: Nick Lewis <nick@puppetlabs.com>
2010-07-09Code smell: Two space indentationMarkus Roberts1-89/+89
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
2010-07-09Code smell: English names for special globals rather than line-noiseMarkus Roberts1-2/+2
* Replaced 36 occurances of [$][?] with $CHILD_STATUS 3 Examples: The code: print "%s finished with exit code %s\n" % [host, $?.exitstatus] becomes: print "%s finished with exit code %s\n" % [host, $CHILD_STATUS.exitstatus] The code: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] becomes: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $CHILD_STATUS.exitstatus] The code: unless $? == 0 becomes: unless $CHILD_STATUS == 0 * Replaced 3 occurances of [$][$] with $PID 3 Examples: The code: Process.kill(:HUP, $$) if restart_requested? becomes: Process.kill(:HUP, $PID) if restart_requested? The code: if pid == $$ becomes: if pid == $PID The code: host[:name] = "!invalid.hostname.$$$" becomes: host[:name] = "!invalid.hostname.$PID$" * Replaced 7 occurances of [$]& with $MATCH 3 Examples: The code: work.slice!(0, $&.length) becomes: work.slice!(0, $MATCH.length) The code: if $& becomes: if $MATCH The code: if $& becomes: if $MATCH * Replaced 28 occurances of [$]:(?!:) with $LOAD_PATH 3 Examples: The code: sitelibdir = $:.find { |x| x =~ /site_ruby/ } becomes: sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ } The code: $:.unshift "lib" becomes: $LOAD_PATH.unshift "lib" The code: $:.shift becomes: $LOAD_PATH.shift * Replaced 3 occurances of [$]! with $ERROR_INFO 3 Examples: The code: $LOG.fatal("Problem reading #{filepath}: #{$!}") becomes: $LOG.fatal("Problem reading #{filepath}: #{$ERROR_INFO}") The code: $stderr.puts "Couldn't build man pages: " + $! becomes: $stderr.puts "Couldn't build man pages: " + $ERROR_INFO The code: $stderr.puts $!.message becomes: $stderr.puts $ERROR_INFO.message * Replaced 3 occurances of ^(.*)[$]" with \1$LOADED_FEATURES 3 Examples: The code: unless $".index 'racc/parser.rb' becomes: unless $LOADED_FEATURES.index 'racc/parser.rb' The code: $".push 'racc/parser.rb' becomes: $LOADED_FEATURES.push 'racc/parser.rb' The code: $".should be_include("tmp/myfile.rb") becomes: $LOADED_FEATURES.should be_include("tmp/myfile.rb")
2010-06-28[#3994-part 3] rename spec tests from *_spec_spec to *_spec.rbMarkus Roberts1-0/+120
Part 2 re-did the change on the spec files, which it shouldn't have.
2010-06-28[#3994-part 2] rename integration tests to *_spec.rbMarkus Roberts1-120/+0
Some spec files like active_record.rb had names that would confuse the load path and get loaded instead of the intended implentation when the spec was run from the same directory as the file. Author: Matt Robinson <matt@puppetlabs.com> Date: Fri Jun 11 15:29:33 2010 -0700
2010-06-23[#3994] rename the specs to have _spec.rb at the endMarkus Roberts1-0/+120
Some spec files like active_record.rb had names that would confuse the load path and get loaded instead of the intended implentation when the spec was run from the same directory as the file. Author: Matt Robinson <matt@puppetlabs.com> Date: Fri Jun 11 15:29:33 2010 -0700