Permalink
Browse files

Initial commit

Signed-off-by: Luke Kanies <luke@reductivelabs.com>
  • Loading branch information...
0 parents commit 129fd5dce32bae3877e532f9266171bc0e69db12 @lak lak committed Mar 9, 2010
Showing with 596 additions and 0 deletions.
  1. +339 −0 LICENSE
  2. +4 −0 README.markdown
  3. +9 −0 autotest/discover.rb
  4. +51 −0 autotest/puppet_lvm_rspec.rb
  5. +74 −0 autotest/rspec.rb
  6. +60 −0 spec/lib/helpers.rb
  7. +30 −0 spec/lib/matchers.rb
  8. +6 −0 spec/spec.opts
  9. +23 −0 spec/spec_helper.rb
339 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,4 @@
+
+Puppet Remote Resource
+======================
+Add some docs.
@@ -0,0 +1,9 @@
+require 'autotest'
+
+Autotest.add_discovery do
+ "rspec"
+end
+
+Autotest.add_discovery do
+ "puppet_lvm"
+end
@@ -0,0 +1,51 @@
+require 'autotest'
+require 'autotest/rspec'
+
+Autotest.add_hook :initialize do |at|
+ at.clear_mappings
+
+ # the libraries under lib/puppet
+ at.add_mapping(%r%^lib/(.*)\.rb$%) { |filename, m|
+ at.files_matching %r!spec/(unit|integration)/#{m[1]}.rb!
+ }
+
+ # the actual spec files themselves
+ at.add_mapping(%r%^spec/(unit|integration)/.*\.rb$%) { |filename, _|
+ filename
+ }
+
+ # force a complete re-run for all of these:
+
+ # main puppet lib
+ at.add_mapping(%r!^lib/puppet\.rb$!) { |filename, _|
+ at.files_matching %r!spec/(unit|integration)/.*\.rb!
+ }
+
+ # the spec_helper
+ at.add_mapping(%r!^spec/spec_helper\.rb$!) { |filename, _|
+ at.files_matching %r!spec/(unit|integration)/.*\.rb!
+ }
+
+ # the puppet test libraries
+ at.add_mapping(%r!^test/lib/puppettest/.*!) { |filename, _|
+ at.files_matching %r!spec/(unit|integration)/.*\.rb!
+ }
+
+ # the puppet spec libraries
+ at.add_mapping(%r!^spec/lib/spec.*!) { |filename, _|
+ at.files_matching %r!spec/(unit|integration)/.*\.rb!
+ }
+
+ # the monkey patches for rspec
+ at.add_mapping(%r!^spec/lib/monkey_patches/.*!) { |filename, _|
+ at.files_matching %r!spec/(unit|integration)/.*\.rb!
+ }
+end
+
+# a place for overrides when necessary.
+class Autotest::Puppet_lvmRspec < Autotest::Rspec
+ def spec_commands
+ ENV["AUTOTEST"] = "true"
+ ENV["PATH"].split(File::PATH_SEPARATOR).collect { |dir| File.join(dir, "spec") }
+ end
+end
@@ -0,0 +1,74 @@
+require 'autotest'
+
+Autotest.add_hook :initialize do |at|
+ at.clear_mappings
+ # watch out: Ruby bug (1.8.6):
+ # %r(/) != /\//
+ at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
+ filename
+ }
+ at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
+ ["spec/#{m[1]}_spec.rb"]
+ }
+ at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
+ at.files_matching %r{^spec/.*_spec\.rb$}
+ }
+end
+
+class RspecCommandError < StandardError; end
+
+class Autotest::Rspec < Autotest
+
+ def initialize
+ super
+
+ self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
+ self.completed_re = /\Z/ # FIX: some sort of summary line at the end?
+ end
+
+ def consolidate_failures(failed)
+ filters = Hash.new { |h,k| h[k] = [] }
+ failed.each do |spec, failed_trace|
+ if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
+ filters[f] << spec
+ break
+ end
+ end
+ return filters
+ end
+
+ def make_test_cmd(files_to_test)
+ return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
+ end
+
+ def add_options_if_present
+ File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
+ end
+
+ # Finds the proper spec command to use. Precendence is set in the
+ # lazily-evaluated method spec_commands. Alias + Override that in
+ # ~/.autotest to provide a different spec command then the default
+ # paths provided.
+ def spec_command(separator=File::ALT_SEPARATOR)
+ unless defined? @spec_command then
+ @spec_command = spec_commands.find { |cmd| File.exists? cmd }
+
+ raise RspecCommandError, "No spec command could be found!" unless @spec_command
+
+ @spec_command.gsub! File::SEPARATOR, separator if separator
+ end
+ @spec_command
+ end
+
+ # Autotest will look for spec commands in the following
+ # locations, in this order:
+ #
+ # * bin/spec
+ # * default spec bin/loader installed in Rubygems
+ def spec_commands
+ [
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
+ File.join(Config::CONFIG['bindir'], 'spec')
+ ]
+ end
+end
@@ -0,0 +1,60 @@
+module Helpers
+
+ TEST_DIR = Pathname.new(__FILE__).parent + '..'
+
+ TYPES = {
+ :pv => :physical_volume,
+ :lv => :logical_volume,
+ :vg => :volume_group,
+ :fs => :filesystem
+ }
+
+ def self.included(obj)
+ obj.instance_eval { attr_reader :valid_params }
+ end
+
+ # Creates a new resource of +type+
+ def with(opts = {}, &block)
+ resource = @type.new(opts)
+ block ? (yield resource) : resource
+ end
+
+ # Returns a lambda creating a resource (ready for use with +should+)
+ def specifying(opts = {}, &block)
+ specification = lambda { with(opts) }
+ block ? (yield specification) : specification
+ end
+
+ # Sets up an expection that a resource for +type+ is not created
+ def should_not_create(type)
+ raise "Invalid type #{type}" unless TYPES[type]
+ Puppet::Type.type(TYPES[type]).expects(:new).never
+ end
+
+ # Sets up an expection that a resource for +type+ is created
+ def should_create(type)
+ raise "Invalid type #{type}" unless TYPES[type]
+ Puppet::Type.type(TYPES[type]).expects(:new).with { |args| yield(args) }
+ end
+
+ # Return the +@valid_params+ without one or more keys
+ # Note: Useful since resource types don't like it when +nil+ is
+ # passed as a parameter value
+ def valid_params_without(*keys)
+ valid_params.reject { |k, v| keys.include?(k) }
+ end
+
+ # Stub the default provider to get around confines for testing
+ def stub_default_provider!
+ unless defined?(@type)
+ raise ArgumentError, "@type must be set"
+ end
+ provider = @type.provider(:lvm)
+ @type.stubs(:defaultprovider => provider)
+ end
+
+ def fixture(name, ext = '.txt')
+ (TEST_DIR + 'fixtures' + "#{name}#{ext}").read
+ end
+
+end
@@ -0,0 +1,30 @@
+module Matchers
+
+ class AutoRequireMatcher
+ def initialize(*expected)
+ @expected = expected
+ end
+
+ def matches?(resource)
+ resource_type = resource.class
+ configuration = resource_type.instance_variable_get(:@autorequires) || {}
+ @autorequires = configuration.inject([]) do |memo, (param, block)|
+ memo + resource.instance_eval(&block)
+ end
+ @autorequires.include?(@expected)
+ end
+ def failure_message_for_should
+ "expected resource autorequires (#{@autorequires.inspect}) to include #{@expected.inspect}"
+ end
+ def failure_message_for_should_not
+ "expected resource autorequires (#{@autorequires.inspect}) to not include #{@expected.inspect}"
+ end
+ end
+
+ # call-seq:
+ # autorequire :logical_volume, 'mylv'
+ def autorequire(type, name)
+ AutoRequireMatcher.new(type, name)
+ end
+
+end
@@ -0,0 +1,6 @@
+--format
+s
+--colour
+--loadby
+mtime
+--backtrace
@@ -0,0 +1,23 @@
+require 'pathname'
+dir = Pathname.new(__FILE__).parent
+$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib')
+
+require 'mocha'
+require 'puppet'
+gem 'rspec', '=1.2.9'
+require 'spec/autorun'
+
+require 'helpers'
+require 'matchers'
+
+Spec::Runner.configure do |config|
+ config.mock_with :mocha
+ config.include Helpers
+ config.include Matchers
+end
+
+# We need this because the RAL uses 'should' as a method. This
+# allows us the same behaviour but with a different method name.
+class Object
+ alias :must :should
+end

0 comments on commit 129fd5d

Please sign in to comment.