On Fri, Jan 30, 2015 at 4:23 AM, Remi Ferrand < remi.mathieu.ferr...@gmail.com> wrote:
I want to use hiera as described in > https://github.com/rodjek/rspec-puppet/tree/v2.0.0#hiera-integration. > This mean: > > - I want to provide a hierarchy > - I want hiera to use my custom configuration file as described in > https://github.com/rodjek/rspec-puppet/tree/v2.0.0#enabling-hiera-lookups > > I've already been using the method above for testing puppet code that > involves hiera lookups, and it worked as expected. > > What I don't want is to stub or mock hiera function. > I just want that the hiera() lookup actually uses my custom hierarchy > specified in my configuration file ( > https://github.com/riton/rspec-hiera-test-function/blob/master/spec/fixtures/hiera/hiera.yaml > ) > > As described in my sample repository README ( > https://github.com/riton/rspec-hiera-test-function/blob/master/README.md), > right now I wasn't able to make it work. > There are a couple of problems with your test because you're doing what should ordinarily work, rather than slavishly following the docs, forgetting about the layers and layers of magic that is rspec and rspec-puppet: 1. You're using the lower-level function interface directly into Puppet rather than the rspec-puppet function-testing interface, so rspec-puppet magic does not get called, so the setup that rspec-pupppet does for your `c.hiera_config = ...` never happens. Instead, try: context 'Using rspec-puppet wrapper' do it 'should work' do expect(subject).to run.with_params().and_return('plop') end end 2. Once you've worked that out, you find that you get an *undefined method* error: Failure/Error: expect(subject).to run.with_params().and_return('plop') NoMethodError: undefined method `call' for nil:NilClass The name of the thing under test w/rspec-puppet *must* be the the top-level `describe` argument: describe 'test_hiera', :focus => true do This is how rspec-puppet knows what function to make available. Note that you can still use the `scope.function_test_hiera([])` stuff, as long as you put it after the rspec-puppet-style function call. (If you were still using rspec-puppet 1.0.1, you might want to duplicate the test with this style, because rspec-puppet had a bug in the error handler that made it impossible determine how your method call errored!) For me, one of the most frustrating aspects of rspec and rspec-puppet is the amount of magic that goes into making the whole thing seem like a DSL rather than an API. For example, try changing 'plop' in the test to see it fail and then run rspec with the --backtrace option -- you'll find no mention of rspec-puppet at all! And don't bother trying to use ruby -rtracer either -- I just ran it with your simple test and got a 170MiB file -- 750,000 lines long. Sorry for the rant. Wil -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/CAMmm3r41iGBtiYKUfJ-N2OmjLzqP01PC-wr-45AaitBQMF04xw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.