Commit Graph

122 Commits

Author SHA1 Message Date
Jeff McCune 4afd64e895 Merge pull request #39 from jeffmccune/fix/master/clean_function_testing
Use puppetlabs_spec_helper to test parser functions
2012-08-14 18:20:11 -07:00
Jeff McCune e6b88cff4f Use puppetlabs_spec_helper to test parser functions
Without this patch applied rspec-puppet reaches deep inside of Puppet
and uses an unsupported and private interface to obtain functions and
scope instances.  This is a problem because Puppet Labs considers
internal classes such as Puppet::Parser::Scope as private and internal.

We change these classes without warning and this is a maintenance issue
for third party testing tools.

This patch fixes this maintenance problem by using the compatibility
layer implemented in the puppetlabs_spec_helper.  When we change the
internal behavior of private classes such as Puppet::Parser::Scope,
we'll update the spec helper module methods to provide a version
agnostic way to get instances of these internal objects.

As an example, a supported way to get a scope instance is:

    PuppetlabsSpec::PuppetInternals.scope

Instead of the private and unsupported method of:

    Puppet::Parser::Scope.new

This patch introduces a Gem dependency onto the puppetlabs_spec_helper
gem.
2012-08-14 16:25:09 -07:00
Tim Sharpe 8d4c96485f Bump to 0.1.4 2012-08-09 11:08:50 +10:00
Tim Sharpe 2db185bf22 Fix bug with optional arrays in the matcher
When a type parameter takes an array with a single value, the compiled version
only has the single value not as an array.
2012-08-09 11:07:22 +10:00
Tim Sharpe c49240e585 Merge branch 'memoize-build-catalog' of https://github.com/Jimdo/rspec-puppet into Jimdo-memoize-build-catalog 2012-08-09 10:03:07 +10:00
Ilya Margolin e474433342 fix tests for rspec-2.11.0 2012-08-09 09:51:47 +10:00
Tim Sharpe e3495af21b Merge pull request #36 from bodepd/pre_condition_catalogs_function_testing
Add support for pre_condition with functions
2012-08-08 15:28:34 -07:00
Ilya Margolin 0bc21c778d fix regression, Puppet[:code] should be part of cache key 2012-08-03 14:43:59 +02:00
Dan Bode 41a2fc8ed7 Add support for pre_condition with functions
This commit adds support for using the pre_condition
hook to specify the source code that should be used to
compile a catalog that can be introspected by functions for
testing purposes.

This allows users to test functions that need access to
catalog contents.

This allows the following snippet to test a function that
needs access to the catalog generated by pre_condition:

  describe 'defined_with_params' do
    #describe 'when resource is passed as a string' do
    let :pre_condition do
      'user { "dan": }'
    end
    it { should run.with_params('User[dan]', {}).and_return('true') }
  end
2012-08-01 19:55:15 -07:00
Ilya Margolin 4ae3e45af7 Cache the result of build_catalog 2012-07-31 16:00:23 +02:00
Tim Sharpe eed11c7dc0 Bump to 0.1.3 2012-04-07 13:02:10 -07:00
Tim Sharpe 79afb02139 I'm not even going to worry about 0.25.x support for now 2012-04-07 12:54:30 -07:00
Tim Sharpe 1034302b7c Not sure where the second .. came from 2012-04-07 12:53:22 -07:00
Tim Sharpe 1ef8c26388 Remove a couple of parameterised class tests for 0.25.x 2012-04-06 15:05:49 -07:00
Tim Sharpe eea6dd57c9 String#to_a doesn't work under 1.9 2012-04-06 14:34:29 -07:00
Tim Sharpe aa73753614 Puppet 2.7 under 1.9.x converts all array members to strings
This hack should keep things working the same under 1.8 and 1.9
2012-04-06 14:23:08 -07:00
Tim Sharpe 398fc775b9 Have travis build 1.9 2012-04-06 14:20:21 -07:00
Tim Sharpe cf7100f95c Have Travis-ci test rspec-puppet automatically 2012-04-05 16:27:33 -07:00
Tim Sharpe 130aec57bd Friendlier descriptions for contain_ matcher 2012-04-05 18:19:27 +10:00
Tim Sharpe f95f81190b Merge pull request #21 from nanliu/tb/config
Add Puppet[:config] as a supported option.
2012-03-12 16:17:12 -07:00
Tim Sharpe 4300f25d22 Add helper script to configure a module for rspec-puppet testing 2012-03-13 10:05:39 +11:00
Nan Liu cbc3a77949 Add Puppet[:config] as a supported option. 2012-02-15 17:24:11 -08:00
Tim Sharpe a1b5ebe25d Add support for testing the catalogue for a defined host 2012-02-15 16:33:48 +11:00
Tim Sharpe a3fff45164 Organise fixtures into modules/ & manifests/ 2012-02-15 16:27:46 +11:00
Tim Sharpe d102ebed5b bump to 0.1.1 2012-01-20 11:24:48 +11:00
Jeff McCune 782520d601 Merge pull request #18 from bodepd/with_without_methods
Adds with/without methods
2011-12-30 13:33:59 -08:00
Dan Bode 4588a91049 Add 'without' method
Adds a method 'without' which accepts a list of
parameters that should not be defined in the resource.

Example:

  it { should contain_service('keystone').without(
    ['restart', 'status']
  )}
2011-12-29 19:51:33 -08:00
Dan Bode 4184c54118 Add with method to generic matcher
This commit adds a method 'with' that can be used
to test mulitple parameters/values with a single
method call

Example:

  it do should contain_service('keystone').with(
    'ensure'     => 'running',
    'enable'     => 'true',
    'hasstatus'  => 'true',
    'hasrestart' => 'true'
  ) end

It was created as a more condensed alternative to
chaining methods per parameter to validate.
2011-12-29 15:37:24 -08:00
Jeff McCune a3e66776b9 Merge pull request #16 from jeffmccune/bug/master/fix_rspec_requirement
Fix rspec dependency
2011-12-29 15:22:16 -08:00
Jeff McCune 8d2e3e6647 Merge pull request #17 from jeffmccune/feature/master/improve_matcher_error_message
Add Regexp support to with_* matchers and improve error messages
2011-12-29 15:22:02 -08:00
Dan Bode 48407ca8c5 Add Rake task 'spec'
Adds the Rake task 'spec' for consistency
with other Rakefiles in Puppet related projects.
2011-12-29 15:04:56 -08:00
Jeff McCune 3b34a50f3b Add Regexp support to with_* matchers and improve error messages
Without this patch it is difficult to match portions of long strings
which are attribute values of resource parameters.  For example, the
content parameter of a file resource with a multi-line template.

This patch makes it easier to match portions of the parameter's value by
passing a Regexp instance to the with_ catch all matcher.

The use case looks like:

    describe 'with lsbmajdistrelease available' do
      let(:facts) { @facter_facts.merge({'lsbmajdistrelease' => '6'}) }
      it { should_not contain_file('puppetenterprise.repo').with_content(missing_content) }
      it { should contain_package 'pe-ruby-devel' }
      it do
        should contain_file('puppetenterprise.repo').with_content(/baseurl=http/)
        should contain_file('puppetenterprise.repo').with_content(/pe_base/)
        should contain_file('puppetenterprise.repo').with_content(/pe_updates/)
        should contain_file('puppetenterprise.repo').with_content(/pe_extras/)
      end
    end

This feature allows the same parameter to be matched multiple times using
multiple different regular expressions.

This patch also improves the error message by presenting the actual value in
the catalog when it does not match the expectation.  This change applies to
both String and Regexp expectation matches.

The error output now looks like:

    1) pe_devel on redhat el6 os families with lsbmajdistrelease available
       Failure/Error: should contain_file('puppetenterprise.repo').with_content(/JEFF MCCUNE/)
         expected that the catalogue would contain File[puppetenterprise.repo] with content \
         matching `/JEFF MCCUNE/` but its value of `"# KERMIT FROG\n"` does not

Spec tests have been added to exercise the handling of Regexp instances.

Reviewed-by: Dan Bode
2011-12-29 14:55:40 -08:00
Jeff McCune d37b5a68f8 Fix rspec dependency
Without this patch, working with rspec-puppet in IRB fails when directly
requiring the library:

    ruby-1.8.7-p334 :001 > require 'rspec-puppet'
    NameError: uninitialized constant RSpec
        from /Users/jeff/.rvm/gems/ruby-1.8.7-p334@puppet/gems/rspec-puppet-0.1.0/lib/rspec-puppet/matchers/create_generic.rb:1
        from /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
        from /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
        from /Users/jeff/.rvm/gems/ruby-1.8.7-p334@puppet/gems/rspec-puppet-0.1.0/lib/rspec-puppet/matchers.rb:1
        from /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
        from /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
        from /Users/jeff/.rvm/gems/ruby-1.8.7-p334@puppet/gems/rspec-puppet-0.1.0/lib/rspec-puppet.rb:2
        from /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:58:in `gem_original_require'
        from /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:58:in `require'
        from (irb):1

This patch fixes the problem by requiring rspec directly from rspec-puppet.rb
2011-12-05 16:21:19 -08:00
Tim Sharpe c73f8ce165 Bump to 0.1.0 2011-11-04 08:51:52 +13:00
Tim Sharpe aefb870658 Better failure messages for the run matcher 2011-11-03 15:28:30 +13:00
Tim Sharpe bf2be9407a Don't hardcode path separator 2011-11-01 21:59:56 +13:00
Tim Sharpe 7f7e74f02c Munge libdir to autoload module plugins without pluginsync 2011-11-01 21:57:42 +13:00
Tim Sharpe dd259e69ac Add new files to gemspec 2011-11-01 21:25:02 +13:00
Tim Sharpe eb50b75789 Double plural 2011-11-01 21:20:38 +13:00
Tim Sharpe bb9f2338fd Missing an end in an example 2011-11-01 21:05:41 +13:00
Tim Sharpe 81257c7f4e Document function testing 2011-11-01 21:03:35 +13:00
Tim Sharpe 7310eecb76 WIP 2011-11-01 15:51:03 +11:00
Tim Sharpe b757ad173e Move manifest matchers into ManifestMatchers module 2011-11-01 14:51:24 +11:00
Tim Sharpe 89ac6b8877 Initial function testing mock up 2011-11-01 14:40:31 +11:00
Tim Sharpe cdd0bcb47e Bump to 0.0.9 2011-09-17 08:18:10 +10:00
Tim Sharpe 1cd3bb9247 automatically set domain fact 2011-09-17 08:17:42 +10:00
Tim Sharpe 37906c4c6b default manifest_dir, manifest & template_dir to nil 2011-09-17 08:16:08 +10:00
Atha Kouroussis 0820a4f57e Add support for additional puppet settings 2011-08-31 00:46:29 -04:00
Tim Sharpe 60264341e7 Bump to 0.0.8 2011-08-29 14:43:44 +12:00
Tim Sharpe 26920e9cb5 munge symbol fact names to strings 2011-08-29 14:41:37 +12:00