From 65b56c711dc882d7d7f8e26c4e020a6beb297c75 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 1 Jun 2015 12:21:59 +0100 Subject: Workaround the broken rspec-mocks support in rspec-puppet --- spec/spec_helper.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/spec_helper.rb') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 896cb83..ccc4d95 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,6 +19,9 @@ require 'puppet_spec/database' require 'monkey_patches/alias_should_to_must' require 'mocha/api' +# hack to enable all the expect syntax (like allow_any_instance_of) in rspec-puppet examples +RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers) + RSpec.configure do |config| config.before :each do # Ensure that we don't accidentally cache facts and environment between @@ -29,5 +32,12 @@ RSpec.configure do |config| Facter.clear_messages Puppet[:parser] = 'future' if ENV['FUTURE_PARSER'] == 'yes' + + RSpec::Mocks.setup + end + + config.after :each do + RSpec::Mocks.verify + RSpec::Mocks.teardown end end -- cgit v1.2.3 From b62dff0c6e09faf9bacfb02575e689ed09ee5e56 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 1 Jun 2015 12:21:59 +0100 Subject: spec_helper: implement an easy way for specs to confine to puppet version Usage: describe 'puppet3 behaviour', :unless => RSpec.configuration.puppet_future do describe 'puppet4 behaviour', :if => RSpec.configuration.puppet_future do --- spec/spec_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/spec_helper.rb') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ccc4d95..be392fd 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,6 +23,10 @@ require 'mocha/api' RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers) RSpec.configure do |config| + config.add_setting :puppet_future + #config.puppet_future = (ENV['FUTURE_PARSER'] == 'yes' or Puppet.version.to_f >= 4.0) + config.puppet_future = Puppet.version.to_f >= 4.0 + config.before :each do # Ensure that we don't accidentally cache facts and environment between # test cases. This requires each example group to explicitly load the -- cgit v1.2.3 From f3e79ddcd56a221c7799b35efde7e9803a5c7923 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 1 Jun 2015 12:21:59 +0100 Subject: Convert tests to use plain rspec-puppet Tests in the new style produces the following documentation output: abs should not eq nil should run abs() and raise an Puppet::ParseError should run abs(-34) and return 34 should run abs("-34") and return 34 should run abs(34) and return 34 should run abs("34") and return 34 --- spec/spec_helper.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'spec/spec_helper.rb') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index be392fd..f941c1c 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,11 +18,17 @@ require 'puppet_spec/matchers' require 'puppet_spec/database' require 'monkey_patches/alias_should_to_must' require 'mocha/api' +#require 'puppetlabs_spec_helper/module_spec_helper' +require 'puppetlabs_spec_helper_clone' # hack to enable all the expect syntax (like allow_any_instance_of) in rspec-puppet examples RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers) RSpec.configure do |config| + config.module_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'modules') + config.manifest_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests') + config.environmentpath = spec_path = File.expand_path(File.join(Dir.pwd, 'spec')) + config.add_setting :puppet_future #config.puppet_future = (ENV['FUTURE_PARSER'] == 'yes' or Puppet.version.to_f >= 4.0) config.puppet_future = Puppet.version.to_f >= 4.0 @@ -35,8 +41,6 @@ RSpec.configure do |config| Facter.clear Facter.clear_messages - Puppet[:parser] = 'future' if ENV['FUTURE_PARSER'] == 'yes' - RSpec::Mocks.setup end @@ -45,3 +49,7 @@ RSpec.configure do |config| RSpec::Mocks.teardown end end + +# Helper class to test handling of arguments which are derived from string +class AlsoString < String +end -- cgit v1.2.3 From 18d4c21418e8d188ae659a92ff3a8df04d711f6a Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 1 Jun 2015 12:21:59 +0100 Subject: Remove unused puppet_spec code This is copied and changed code from an older version of puppet's internal test setup code. It does not work with puppet4. --- spec/spec_helper.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'spec/spec_helper.rb') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f941c1c..416036b 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,12 +10,6 @@ end require 'puppet' require 'rspec-puppet' require 'puppetlabs_spec_helper/module_spec_helper' -require 'puppet_spec/verbose' -require 'puppet_spec/files' -require 'puppet_spec/settings' -require 'puppet_spec/fixtures' -require 'puppet_spec/matchers' -require 'puppet_spec/database' require 'monkey_patches/alias_should_to_must' require 'mocha/api' #require 'puppetlabs_spec_helper/module_spec_helper' -- cgit v1.2.3