Ask Your Question

doubt is rspec-puppet concept

asked 2015-06-19 06:29:54 -0600

Chutki gravatar image

updated 2015-06-19 06:31:18 -0600


From the last two weeks I am learning rspec-puppet and doing sample code testing.

Today I tried host.pp manifests, just adding host name "1235 puppet" to /etc/hosts file.

I have written rspec-puppet testcase and it is working.

The host entry "1235 puppet" is not present in /etc/hosts, but howcome my testcase is passing. Because as per my knowledge rspec-puppet test file will check generated catalog, if so how my test pass without catalog update.

Please correct me if my understanding is wrong.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-06-19 06:53:07 -0600

updated 2015-06-25 07:51:35 -0600

Rspec-puppet works by compiling a catalog and comparing the results of the catalog. It doesn't actually execute the catalog per se, it just compiles it. This is by design, and totally intentional. This is why you don't see any changes when using rspec-puppet to test content, because it tries hard not to touch any part of the operating system.

However, if you want to test the real effect of your code, you have to use something like beaker instead, which provides system testing. Its a different level of testing and much more involved and usually goes hand-in-hand with rspec-puppet testing, but actually makes the real changes on the system and checks for real results.

edit flag offensive delete link more


My doubt is, the catalog is not available for the manifests what I test with rspec-puppet (the "1235 puppet" not available), then how my test case pass.

Chutki gravatar imageChutki ( 2015-06-22 09:23:46 -0600 )edit

As I've stated, the tests that rspec-puppet runs are virtual, it doesn't actually run the catalog contents, so you won't see a modification to /etc/hosts at all. All it does is compile a catalog, and ensure it _would_ do the right thing, if properly applied to a machine by comparing data results.

ken gravatar imageken ( 2015-06-22 09:50:38 -0600 )edit

yes, eg: " it should contain_file('/etc/sudoers').with_content( /Defaults requiretty/)}" this line will throw error if change to "with_content( /puppet/) " since" puppet" not available in /etc/sudoers. but why its not throwing error in this case if the value"1235puppet.examplecom" is not in /host

Chutki gravatar imageChutki ( 2015-06-26 07:08:53 -0600 )edit

I think you need to change your question to actually contain a better description, because your current one is confusing. If it's an actual rspec-puppet failure that you are having, whereby a test itself doesn't work you feel, we'll need to see the full code & transcript of the failure to answer it.

ken gravatar imageken ( 2015-06-26 07:49:47 -0600 )edit

Rather not "full code" but at least a cut-down reproducible transcript of the problem.

ken gravatar imageken ( 2015-06-26 07:50:28 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-06-19 06:29:54 -0600

Seen: 133 times

Last updated: Jun 25 '15