Stubbing functions in Puppet rspec

59 views
Skip to first unread message

Peter Berghold

unread,
Aug 5, 2016, 8:05:15 AM8/5/16
to puppet-users
I have this wonderful module that calls various custom functions that I've written that I'm trying to adopt RSpec testing for.  After seeing it crash and burn with "function unknown" errors I took a rather meandering path and arrived here: https://github.com/TomPoulton/rspec-puppet-unit-testing

So I attempted to follow the instructions given and I ended up with a result like this:

------------- 8< snip!   file: spec/classes/init_spec.rb --------------------------------------------

require 'spec_helper'
describe 'ourbind' do

  let!(:ipdot2dash) { MockFunction.new('ipdot2dash') { |f|
      f.stubbed.with('10.1.2.3').returns('10-1-2-3')
    }
  }
  context 'with defaults for all parameters' do
    it do
      ipdot2dash.stubs(:call).with('10.1.2.3').returns('10-1-2-3')
      should compile
      should contain_class('ourbind')

    end
  end
end

------------------ 8< snip! 8< ----------------------------------------------------------------

I run "rake spec" and I get this (at least to me) undecipherable message:

--------------8< error spew 8<---------------------------------------------------------------

    Failure/Error: should compile
     
     Mocha::ExpectationError:
       unexpected invocation: #<RSpecPuppetUtils::MockFunction:0x2b67950>.call(['', '21'])
       satisfied expectations:
       - allowed any number of times, not yet invoked: #<Puppet::Util::Feature:0x214fc38>.root?(any_parameters)
       - allowed any number of times, not yet invoked: #<RSpecPuppetUtils::MockFunction:0x2b67950>.call('10.1.2.3')
       - allowed any number of times, not yet invoked: #<RSpecPuppetUtils::MockFunction:0x2b67950>.execute('10.1.2.3')

-----------------8< snip! 8< ----------------------------------------------------------------------


Apparently I'm missing something here, what's it trying to tell me and how do I fix it?


Trevor Vaughan

unread,
Aug 5, 2016, 9:13:37 AM8/5/16
to puppet...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAArvnv2mhr7qyOhgRJWQ%2Bfr9hm88gdhmCB1AYB2aeqq1TFCA%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Trevor Vaughan
Vice President, Onyx Point, Inc

-- This account not approved for unencrypted proprietary information --

Peter Berghold

unread,
Aug 5, 2016, 9:31:44 AM8/5/16
to puppet...@googlegroups.com
ooo...  that looks to be an RSpec specification for a custom type/provider?  I'm going to need that! Thanks! 


To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.



--
Trevor Vaughan
Vice President, Onyx Point, Inc

-- This account not approved for unencrypted proprietary information --

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CANs%2BFoVkgH7uz-VkZqiE9ie3pA3oz53dvjj7MPq5xmO2-d9Ysg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages