On Tue, Sep 2, 2014 at 10:48 AM, Brett Swift <[email protected]> wrote:

>
> rspec-puppet supports classes, functions, defined types, but not facts.
>
>
> spec
>  |
>   -> classses
>   -> defines
>   -> facts    ?     ?  ? ??  ?
>
>
> Is there a recommended way to test facts?
>

You don't actually need any of the helpers in rspec-puppet to test facts
with rspec.

In rspec, you would stub any facts that are required but not under test
with `allow(Facter.fact(:osfamily)).to
receive(:value).and_return("fakeosfamily")`, then stub any commands that
the fact that you're testing with `expect(Facter::Util::Resolution).to
receive(:exec).with("some command here").and_return("out that the command
would return")`

Then you can call `expect(Facter.fact(:myfact).value).to eq("factvalue")`

Eg, testing the root_home fact in stdlib:
https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/spec/unit/facter/root_home_spec.rb#L34-L50


>
> I've seen a few examples, but they seem hacky, and I have a feeling this
> should be or is available from puppet modules.
>
> http://unethicalblogger.com/2014/03/01/testing-custom-facts-with-rspec.html
>
>  --> requires re-writing every fact.  Not super keen on doing that if I
> don't have to.
>
>
> github.com/vStone/puppet-testing-example
> -->  seems to work at first, but then when I change an expectation from
> false to true,  it still passes.     This is 2 years old and the version of
> rspec isn't locked down in the gemfile, so it may not even be valid with
> the latest version.
>
>
> Does anyone have a working solution?  Maybe my google-fu isn't very good..
>  there has to be something out there that works?
>
>
>
>
>
>  --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/e55b7789-ea18-4440-933b-efa1e5bc3263%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/e55b7789-ea18-4440-933b-efa1e5bc3263%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAJaQvGDj3Vf0LaVR2Q9c6PtUeYDHgzAp6%2B9T5C8mh46sQF7fSA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to