example:
it "should have mysql service" do
expect(service("mysql")).to be_enabled
expect(service("mysql")).to be_running
end
example_data:
{
: name=>"should have mysql service",
: desc=>"mysql audit should have mysql service",
: resource_type=>nil,
: resource_name=>nil,
: context=>[
],
: line_number=>26
}
The implicit subject populates the :resource_type
and :resource_name
elements
control package("mysql") do
it { is_expected.to be_installed.with_version("5.6") }
end
example_data:
{
: name=>"should be installed",
: desc=>"mysql audit Package \"mysql\" should be installed",
: resource_type=>"Package",
: resource_name=>"mysql",
: context=>[
],
: line_number=>22
}
A single wrapping describe
block populates the :context
. Rspec also modifies the :desc
field to include information about both wrapping blocks.
describe "a describe block" do
let(:f) { file("/etc/mysql") }
let(:u) { 'mysql' }
it "should only include output from first failed expectation" do
expect(f).to be_directory
expect(f).to be_mode(0700)
end
end
example_data:
{
: name=>"should only include output from first failed expectation",
: desc=>"mysql audit a describe block should only include output from first failed expectation",
: resource_type=>nil,
: resource_name=>nil,
: context=>[
"a describe block"
],
: line_number=>36
}
The multiple describe
and context
end up in the :context
field in the order they occured, starting with the outermost. Any implicit subjects (file("/etc/mysql/my.cnf")
) do not show in the :context
because they are assumed to be in the :resource_type
and :resource_name
field. You can also see the block names appended in the :desc
field.
describe "outer 1" do
context "inner 2" do
describe file("will be ignored") do
describe "innermost 3" do
describe file("/etc/mysql/my.cnf") do
it "should have a config" do
expect(subject).to be_file
expect(subject.content).to contain("default-time-zone='UTC'")
expect(subject).to be_mode(0400)
end
end
end
end
end
end
example_data:
{
: name=>"should have a config",
: desc=>"mysql audit outer 1 inner 2 File \"will be ignored\" innermost 3 File \"/etc/mysql/my.cnf\" should have a config",
: resource_type=>"File",
: resource_name=>"/etc/mysql/my.cnf",
: context=>[
"outer 1",
"inner 2",
"File \"will be ignored\"",
"innermost 3"
],
: line_number=>53
}