Information Technology Reference
In-Depth Information
Here's what a
_spec.rb
file might look like for Windows, which uses the
set
command to
give Serverspec a cue on what OS is running:
require
'spec_helper'
set
:backend
,
:cmd
set
:os
,
:family
=>
'windows'
In this topic, we're using a Linux variant as our guest OS, so the Serverspec autodetect logic
should work just fine. Make sure you check this out on your test platform by using a resource
that requires OS platform detection, like the
package
command.
Let's add an example to
default_spec.rb
using the
package
command. As shown in
Example 16-8. chefdk/apache-test/test/integration/default/serverspec/default_spec.rb
require
'spec_helper'
describe
'web site'
ddo
it
'responds on port 80'
ddo
expect
(
port
80
)
.
to be_listening
'tcp'
end
end
it
'returns eth1 in the HTML body'
ddo
expect
(
command
(
'curl localhost:80'
)
.
stdout
)
.
to match
/eth1/
end
end
it
'has the apache web server installed'
ddo
expect
(
package
'httpd'
)
.
to be_installed
end
end
end
end
Run
kitchen verify
for Serverspec. The command works fine because Serverspec auto-
matically detected the OS:
$
kitchen verify
-----> Starting Kitchen (v1.2.1)
...
-----> Running serverspec test suite
/opt/chef/embedded/bin/ruby -I/tmp/busser/suites/serverspec
-I/tmp/busser/gems/gems/rspec-support-3.1.2/lib:/tmp/busser/gems/gems
/rspec-core-3.1.7/lib /opt/chef/embedded/bin/rspec --pattern /tmp/busser
/suites/serverspec/\*\*/\*_spec.rb --color --format documentation