- Getting started with Serverspec
- Serverspec new matchers: Part 1
- Serverspec new matchers: Part 2
What is Serverspec?
Rspec tests for verifying the configuration of a given machine. It is used together with configuration management tools like Salt, Ansible, Puppet, Chef, etc. as a integration testing framework.
It is a Ruby-based framework, which uses internally Shell(Linux environments), Powershell(Windows environment) scripts for checking the target machines if the configuration management tool has configured them correctly.
The easiest way to install is to use the serverspec gem:
gem install serverspec
I will concentrate on testing Windows machines using the Serverspec framework, but the approach is the same for Linux ones.
To get started with Serverspec, the serverspec-init tool can be used, it creates the needed setup for a testing suite:
serverspec-init Select OS type: 1) UN*X 2) Windows Select number: 2 Select a backend type: 1) SSH 2) Exec (local) Select number: 2
Note: The setup is done for windows local environment.
The command will create the following setup on the local machine:
▾ spec/ ▾ localhost/ httpd_spec.rb spec_helper.rb Rakefile
The httpd_spec.rb contains example Rspec tests.
Executing the rake spec command(rake gem is needed) will run the Rspec tests.
Serverspec has many different resource types implemented, which allow users to describe the machine setup in their Rspec tests.
Helpful information about these resource types can be found here.