Information Technology Reference
In-Depth Information
chen.yml
file, Test Kitchen infers this from the directory structure underneath
test/integra-
tion
. Create the
test/integration/default/serverspec
directory now.
Linux/Mac OS X:
$
mkdir -p test/integration/default/serverspec
Windows:
$
mkdir test\integration\default\serverspec
By convention, Serverspec expects files containing test code to end in the suffix
spec.rb
.
Create the file
default_spec.rb
in the
test/integration/default/serverspec
subdirectory of your
cookbook, as shown in
Example 16-4
.
Example 16-4. chefdk/apache-test/test/integration/default/serverspec/default_spec.rb
require
'serverspec'
set
:backend
,
:exec
describe
'web site'
ddo
it
'responds on port 80'
ddo
expect
(
port
80
)
.
to be_listening
'tcp'
end
end
end
end
There are three major components to the
spec.rb
file, which we've labeled 1, 2, and 3:
require
'serverspec'
set
:backend
,
:exec
describe
'web site'
ddo
it
'responds on port 80'
ddo
expect
(
port
80
)
.
to be_listening
'tcp'
end
end
end
end
The
require
statement is used to load the gem library for
serverspec
, so we can refer-
ence Serverspec classes and methods, such as the
set
method.