[Go to site: main page, start]

View on GitHub

logo

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

Tutorial

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.)

spec/target.example.jp/http_spec.rb

You can write a test file like this.

require 'spec_helper'

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

See details on Resource Types.


Multi OS support

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

  • AIX
  • Arch Linux
  • Darwin(Mac OS X)
  • Debian
  • Fedora/Red Hat/CentOS
  • FreeBSD
  • Gentoo Linux
  • NixOS
  • OpenBSD
  • openSUSE
  • Plamo Linux
  • SmartOS
  • Solaris
  • SUSE
  • Ubuntu
  • Windows

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