Re: [Puppet Users] Stubbing functions in Puppet rspec

2016-08-05 Thread Peter Berghold
ooo...  that looks to be an RSpec specification for a custom
type/provider?  I'm going to need that! Thanks!


On Fri, Aug 5, 2016 at 9:13 AM Trevor Vaughan 
wrote:

> Hi Peter,
>
> See if this helps
> https://github.com/onyxpoint/puppet-gpasswd/blob/master/spec/unit/provider/group/gpasswd_spec.rb
>
> Thanks,
>
> Trevor
>
> On Fri, Aug 5, 2016 at 8:04 AM, Peter Berghold 
> wrote:
>
>> 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:
>> #.call(['', '21'])
>>satisfied expectations:
>>- allowed any number of times, not yet invoked:
>> #.root?(any_parameters)
>>- allowed any number of times, not yet invoked:
>> #.call('10.1.2.3')
>>- allowed any number of times, not yet invoked:
>> #.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?
>>
>>
>> --
>> 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+unsubscr...@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
> (410) 541-6699 x788
>
> -- 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+unsubscr...@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
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAArvnv2J0TBXAYuktX_dHBwDXm1HvzEckw32rPH_uZVdWu1P1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Stubbing functions in Puppet rspec

2016-08-05 Thread Trevor Vaughan
Hi Peter,

See if this helps
https://github.com/onyxpoint/puppet-gpasswd/blob/master/spec/unit/provider/group/gpasswd_spec.rb

Thanks,

Trevor

On Fri, Aug 5, 2016 at 8:04 AM, Peter Berghold 
wrote:

> 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: # MockFunction:0x2b67950>.call(['', '21'])
>satisfied expectations:
>- allowed any number of times, not yet invoked:
> #.root?(any_parameters)
>- allowed any number of times, not yet invoked: # MockFunction:0x2b67950>.call('10.1.2.3')
>- allowed any number of times, not yet invoked: # 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?
>
>
> --
> 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+unsubscr...@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
(410) 541-6699 x788

-- 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+unsubscr...@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.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Stubbing functions in Puppet rspec

2016-08-05 Thread Peter Berghold
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:
#.call(['', '21'])
   satisfied expectations:
   - allowed any number of times, not yet invoked:
#.root?(any_parameters)
   - allowed any number of times, not yet invoked:
#.call('10.1.2.3')
   - allowed any number of times, not yet invoked:
#.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?

-- 
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+unsubscr...@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.