I hear I should be using expectations rather than "should" statements in Serverspec
I have been Googling around for expectations that can be used for file matching but all of the tutorials I see for Serverspec use should rather than expect. Is this because Serverspec hasn't been updated to use expectations?
describe file('/etc/yum.conf') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 644 }
its(:content) { should match /^gpgcheck=1$/ }
its(:content) { should match /^clean_requirements_on_remove=1$/ }
end
So how would I write the test using expectations instead of should?
Your first question:
No, it is mostly because the author of the Serverspec project has a preference for the "should" syntax, and that's why the Serverspec documentation continues to use it. He has explained here that:
Be aware that
shouldandexpectcome from the rspec-expectations project, and the Serverspec author is correct "should" rather than "expect" is fine the way he is using it.There is more info on the original motivation for the expect syntax from the Rspec author Myron Marston here.
Your second question:
If you still want to use the
expectsyntax, just replaceshouldeverywhere withis_expected.toeverywhere. This works fine:You can also write it this way:
Or even:
See also: