2

I have no prior experience at all of ruby. I am not interested in ruby (and so have no knowledge of rails etc) as such but am using puppet to manage a group of servers. I have written some modules and the rspec-puppet system looks like it would be very useful.

However, I cannot get rspec-puppet to work

I am using Ubuntu LTS 10.04

I have installed puppet rspec using the directions on their web page

What I actually did

apt-get install rubygems # (installs 1.8)
gem install rspec-expectations
gem install rspec-puppet

I also installed librspec-ruby1.8

Then I ran rspec-puppet-init in a puppet module directory I'd already made (it's a working puppet module)

I made a file as defined in the tutorial

$ more spec/defines/rule_spec.rb 
require 'spec_helper'

describe 'vanusers::rule' do
let(:title) { 't1' }

it { should contain_class('vanusers::JamieA') }
end

but when I try and run it there is a mysterious dependancy issue

$ spec spec/defines/rule_spec.rb 
/home/jamie/git/puppet/modules/vanusers/spec/spec_helper.rb:1:in `require': no such file to load -- rspec-puppet (LoadError)
    from /home/jamie/git/puppet/modules/vanusers/spec/spec_helper.rb:1
    from ./spec/defines/rule_spec.rb:1:in `require'
    from ./spec/defines/rule_spec.rb:1
    from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:15:in `load'
    from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:15:in `load_files'
    from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:14:in `each'
    from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:14:in `load_files'
    from /usr/lib/ruby/1.8/spec/runner/options.rb:132:in `run_examples'
    from /usr/lib/ruby/1.8/spec/runner/command_line.rb:9:in `run'
    from /usr/bin/spec:3

Here is the solution I came up with in the end::

apt-get install rubygems
gem install rspec-expectations rspec-puppet puppet-lint puppetlabs_spec_helper

so your path picks up the gem stuff

export PATH=/var/lib/gems/1.8/bin:$PATH

cd into module and

rm spec/spec_helper.rb

rspec-puppet-init

replace Rakefile with

require 'rake'
require 'rspec/core/rake_task'
require 'puppetlabs_spec_helper/rake_tasks'

Then "rake spec" to run tests or "rake lint" to check files

http://sysadvent.blogspot.co.uk/2013/12/day-22-getting-started-testing-your.html was an excellent source of info

1

I had this same problem and the fix was to put the following in my spec_helper.rb file:

require 'rubygems'

at the top of the file. I was then able to run $ rake rspec successfully.

  • thanks for that, I've added the solution I came up with to the question – Vorsprung Jun 4 '14 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.