Last active
October 21, 2015 16:02
-
-
Save danzilio/fc01f3ff64fcb7275fdc to your computer and use it in GitHub Desktop.
Good vs Bad Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This basically tests that Puppet works. It just re-creates your Puppet code in a different DSL. | |
# ANY change to the existing params on this resource will require that you update your tests. | |
describe 'foo' do | |
let(:params) { :param => 'somevalue' } | |
it do | |
should contain_file('bar').with({ | |
:ensure => present, | |
:owner => root, | |
:group => root, | |
:mode => 0644, | |
:content => 'somevalue' | |
}) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Better. This tests the interface instead of the implementation. You can change the implementation | |
# without updating the tests, as long as the interface stays the same. This is how you refactor! | |
describe 'foo' do | |
let(:params) { :param => 'somevalue' } | |
it 'should contain the expected resources' do | |
should contain_file('bar').with_content(/^somevalue$/) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class foo ( | |
$param = value, | |
) { | |
file { 'bar': | |
ensure => present, | |
owner => root, | |
group => root, | |
mode => 0644, | |
content => $param, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment