rspec and facter 2 vs facter 3

49 views
Skip to first unread message

Miguel Di Ciurcio Filho

unread,
Sep 9, 2015, 8:23:28 AM9/9/15
to puppe...@googlegroups.com
Hi there,

I was playing with rspec and run `rake spec` on puppetlabs-apache module.

I'm have puppet-agent 1.2.2 installed and this error happens:

Failure/Error: Unable to find matching line from backtrace
NameError:
uninitialized constant Facter::Util::Loader

After some investigation, I've found that the problem comes down to
theses lines:

https://github.com/puppetlabs/puppetlabs-apache/blob/master/spec/spec_helper.rb#L9

Facter::Util::Loader.any_instance.stubs(:load_all)
Facter.clear
Facter.clear_messages

Looking further into the problem, I looked into the logs produced by
Travis-CI and finally understood that the tests are depending on
Facter 2.

I commented out those 3 lines and the tests passed fine locally.

Since I'm not that familiar with Facter's API changes from 2 to 3, are
these 3 lines still relevant? I've read the comment above them (Ensure
that we don't accidentally cache facts and environment between test
cases) but I still don't understand what is the issue being handled.

Is this in any way related to https://tickets.puppetlabs.com/browse/FACT-981 ?

Regards,

Miguel


--
http://www.instruct.com.br - 19 2511-6506

Peter Huene

unread,
Sep 9, 2015, 11:53:35 AM9/9/15
to puppe...@googlegroups.com
Hi Miguel,

On Wed, Sep 9, 2015 at 5:23 AM, Miguel Di Ciurcio Filho <mig...@instruct.com.br> wrote:
Hi there,

I was playing with rspec and run `rake spec` on puppetlabs-apache module.

I'm have puppet-agent 1.2.2 installed and this error happens:

Failure/Error: Unable to find matching line from backtrace
     NameError:
       uninitialized constant Facter::Util::Loader

After some investigation, I've found that the problem comes down to
theses lines:

https://github.com/puppetlabs/puppetlabs-apache/blob/master/spec/spec_helper.rb#L9

Facter::Util::Loader.any_instance.stubs(:load_all)

Facter 3 doesn't have a Facter::Util::Loader defined, which is why this code is unable to stub it.  Removing this line should be fine.
 
Facter.clear

This call to `Facter.clear` should remain as it is attempting to ensure that the facts collection is cleared between test runs.
 
Facter.clear_messages

This method was removed in Facter 2, so I'm unsure as to how this was working without testing against Facter 1.x.  Regardless, it should also be removed.


Looking further into the problem, I looked into the logs produced by
Travis-CI and finally understood that the tests are depending on
Facter 2.

I commented out those 3 lines and the tests passed fine locally.

Since I'm not that familiar with Facter's API changes from 2 to 3, are
these 3 lines still relevant? I've read the comment above them (Ensure
that we don't accidentally cache facts and environment between test
cases) but I still don't understand what is the issue being handled.

Is this in any way related to https://tickets.puppetlabs.com/browse/FACT-981 ?

Regards,

Miguel


--
http://www.instruct.com.br - 19 2511-6506

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



--
--
Peter Huene
Software Engineer, Puppet Labs
Puppet Open Source Team
-------------------------------------------

PuppetConf 2015 is coming to Portland, Oregon! Join us October 5-9!

Peter Huene

unread,
Sep 9, 2015, 12:02:46 PM9/9/15
to puppe...@googlegroups.com
On Wed, Sep 9, 2015 at 8:53 AM, Peter Huene <peter...@puppetlabs.com> wrote:
Hi Miguel,

On Wed, Sep 9, 2015 at 5:23 AM, Miguel Di Ciurcio Filho <mig...@instruct.com.br> wrote:
Hi there,

I was playing with rspec and run `rake spec` on puppetlabs-apache module.

I'm have puppet-agent 1.2.2 installed and this error happens:

Failure/Error: Unable to find matching line from backtrace
     NameError:
       uninitialized constant Facter::Util::Loader

After some investigation, I've found that the problem comes down to
theses lines:

https://github.com/puppetlabs/puppetlabs-apache/blob/master/spec/spec_helper.rb#L9

Facter::Util::Loader.any_instance.stubs(:load_all)

Facter 3 doesn't have a Facter::Util::Loader defined, which is why this code is unable to stub it.  Removing this line should be fine.
 
Facter.clear

This call to `Facter.clear` should remain as it is attempting to ensure that the facts collection is cleared between test runs.
 
Facter.clear_messages

This method was removed in Facter 2, so I'm unsure as to how this was working without testing against Facter 1.x.  Regardless, it should also be removed.

Actually, I misspoke.  This method was moved into a different module and mixed back into the Facter module, so it still exists in 2.x.  The Facter 3 API is missing this method as it was marked private and was not considered to be part of the public API.  We may need to add this back in as there is currently no way for tests to clear the warnonce/debugonce messages if they are testing those methods.
Reply all
Reply to author
Forward
0 new messages