serverspec - a rubygem for testing provisioned servers with RSpec

In Testing servers provisioned by Puppet or Chef with RSpec, I wrote how to test provisioned servers with RSpec.

I've created a rubygem serverspec for that purpose.


You can install serverspec with gem install.

$ gem install serverspec

serverspec-init command creates template files and directories.

$ serverspec-init
 + spec/
 + spec/
 + spec/
 + spec/spec_helper.rb
 + Rakefile

spec/ contains example spec code.

require 'spec_helper'

describe 'httpd' do
  it { should be_installed }
  it { should be_enabled   }
  it { should be_running   }

describe 'port 80' do
  it { should be_listening }

describe '/etc/httpd/conf/httpd.conf' do
  it { should be_file }
  it { should contain "ServerName" }

You can write test code like this.

You may need some settings in ~/.ssh/config and ssh-agent for logging into the target server without the password/passphrase.

Host *
   User root
   IdentityFile ~/.ssh/for_serverspec_rsa

Run tests with rake spec.

$ rake spec
/usr/bin/ruby -S rspec spec/

Finished in 0.99715 seconds
6 examples, 0 failures