1

I'm quite new to all of this. I am trying to test out a puppet module using Beaker. I keep getting this:

 NoMethodError: undefined method `describe' for 
 #Beaker::TestCase:0x007fd6f95e6460
 /Users/user1/beaker/Puppet/puppet-files/spec/classes/unit_spec.rb:3  
 /Users/user1/.rvm/gems/ruby-2.2.7/gems/beaker-3.24.0/bin/beaker:9  
 /Users/user1/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15  
 /Users/user1/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15.
 This is the command that I'm running - "beaker --hosts myhost.yaml --pre-suite spec".

My unit_spec.rb contains this:

  require 'puppetlabs_spec_helper/rake_tasks'

  describe 'application' do
  context 'applied to supported operating system' do
  on_supported_os.each do |os, facts|
  context "#{os}" do
   let(:facts) do
     facts
   end

   context "without any parameters" do
     let(:params) {{ }}

     it { is_expected.to compile.with_all_deps }
     it { is_expected.to contain_class('files') }
     end
    end
   end
  end


    context 'applied to unsupported operating system' do
    describe 'ubuntu-14-x86_64' do
    let(:facts) {{
     :osfamily        => 'Debian',
     :operatingsystem => 'Ubuntu'
      }}

    it { is_expected.to raise_error(Puppet::Error, /Ubuntu not supported/) }
    end
   end
  end

Any help would be much appreciated! Btw, I am using 'puppetlabs_spec_helper/rake_tasks' due to the fact that when I just used 'spec_helper' it gave me an error that it could not "load such file" even though it was there.

Also, I have tried doing

RSpec.Describe

That did not fix the issue either. I get the following error -

 NameError: undefined local variable or method `on_supported_os' for #Class:0x007f92a61d5e58

I realise that this might be an RSpec Puppet issue, as this module was previously tested through puppet RSpec, however now I am trying to test using Beaker and not quite sure how to fully achieve that!

F.P.MCF
  • 21
  • 3
  • try adding `require 'rspec'`. – Sachin Singh Sep 29 '17 at 10:29
  • I tried that, it's still giving me the - `NameError: undefined local variable or method "on_supported_os" for #Class:0x007f92a61d5e58` – F.P.MCF Sep 29 '17 at 10:37
  • Where is `on_supported_os` defined?? You have not shown us in your code above. – Tom Lord Sep 29 '17 at 10:54
  • After a quick google, I found [this](https://github.com/mcanevet/rspec-puppet-facts#installation) -- is that what you're using? Follow the installation instructions; i.e. somewhere (probably, but not necessarily, in `spec_helper.rb`) you need to `require 'rspec-puppet-facts'` and `include RspecPuppetFacts`. – Tom Lord Sep 29 '17 at 10:56
  • I don't know, that's the thing. The module I am testing on already contained all that in the unit_spec.rb. I'm not even sure it is properly defined. If I do need to define it, I don't know where to do that. – F.P.MCF Sep 29 '17 at 10:57
  • @TomLord yeah I have already tried that , it does not work. The errors stay the same, – F.P.MCF Sep 29 '17 at 11:00
  • Oh, so is this code from an existing project, which worked on the previous developer's machine but not yours? Maybe you just need to `bundle install`? – Tom Lord Sep 29 '17 at 11:00
  • @TomLord Yeah, it's from an existing project which now needs to be tested using Beaker instead, to determine whether Beaker is a suitable way of doing future testing, and at the moment it appears not. `bundle install` the spec folder? – F.P.MCF Sep 29 '17 at 11:03
  • Just run `bundle install` from anywhere within the project. – Tom Lord Sep 29 '17 at 11:06
  • @TomLord When I run `bundle install` it just added some more gems and dependencies `Bundle complete! 9 Gemfile dependencies, 35 gems now installed. Use bundle info [gemname] to see where a bundled gem is installed.`. Then when I run the original beaker command it is displaying the same error . – F.P.MCF Sep 29 '17 at 11:18
  • What do you mean, "run the original beaker command"? If you're not already, then try: `bundle exec rspec spec/path/to/unit_spec.rb`. Is the original author of this code not available to show you the ropes? – Tom Lord Sep 29 '17 at 11:24
  • ....For example, do you have any continuous integration service like `TravicCI`, `CircleCI` `Jenkins`, etc. which you could use to see how the tests are normally run? – Tom Lord Sep 29 '17 at 11:42
  • `beaker --hosts myhost.yaml --pre-suite spec` -- this command. No not really, as this code was done quite a while ago. I think Travis and Jenkins are used but not for this specific task that I'm doing. – F.P.MCF Sep 29 '17 at 12:18

1 Answers1

1

You're mixing up unit- and VM-based testing.

  • rspec-puppet (and rspec-puppet-facts' on_supported_os) are for catalog-based unit testing. They do not require a VM, and can give you quick feedback on syntax, and logic of your module.

  • beaker, and the recommended beaker-rspec add-on, provide full end-to-end testing capabilities, using actual VMs, and testing a complete stack deploy (as defined in you tests).

The main entry point for existing modules is usually rake. Take a look at the existing rake tasks in the module using rake -T. In a well-written module it should have tasks for both rspec-puppet (usually called spec), and beaker (often called beaker, or acceptance).

If it is your own module, you also might want to look into the new Puppet Development Kit to get the most important tools in a single installer.

David Schmitt
  • 58,259
  • 26
  • 121
  • 165