View on GitHub


RSpec tests for your servers configured
by CFEngine, Puppet, Ansible, Itamae or anything else.


Writing tests | Multi OS support | Sudo password support

Writing tests

Basic structure of test files

With Rakefile generated by serverspec-init, test files must be placed under the directory which name matches the target host name like this. (You can customize this structure by editing Rakefile and spec_helper.rb as you like.)


You can write a test file like this.

require 'spec_helper'

describe '<name of the resource being tested>' do
  # your tests ...

See details on Resource Types.

Multi OS support

Serverspec is supporting these OSes currently. (But all of OSes are not fully supported.)

Serverspec can detect target host’s OS automatically.

If you’d like to set target host’s OS explicitly, you should write set :os like this

require 'serverspec'
set :os, :family => 'redhat', :release => '7', :arch => 'x86_64'

Sudo password support

If you log into servers as non-root user, Serverspec add “sudo” in front of the command. You can specify sudo password like this.

$ SUDO_PASSWORD=xxxxxxxx rake spec

Or display prompt for sudo password if you run Serverspec like this.

$ ASK_SUDO_PASSWORD=1 rake spec