From cc73ceec64603d44e68ca198b9cd1186d749a3c8 Mon Sep 17 00:00:00 2001 From: Gosuke Miyashita Date: Sun, 19 May 2013 01:53:02 +0900 Subject: [PATCH] Add specs for cron type --- spec/darwin/cron_spec.rb | 8 ++++++++ spec/debian/cron_spec.rb | 8 ++++++++ spec/gentoo/cron_spec.rb | 8 ++++++++ spec/redhat/cron_spec.rb | 8 ++++++++ spec/redhat/file_spec.rb | 2 +- spec/solaris/cron_spec.rb | 8 ++++++++ spec/support/shared_cron_examples.rb | 23 +++++++++++++++++++++++ 7 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 spec/darwin/cron_spec.rb create mode 100644 spec/debian/cron_spec.rb create mode 100644 spec/gentoo/cron_spec.rb create mode 100644 spec/redhat/cron_spec.rb create mode 100644 spec/solaris/cron_spec.rb create mode 100644 spec/support/shared_cron_examples.rb diff --git a/spec/darwin/cron_spec.rb b/spec/darwin/cron_spec.rb new file mode 100644 index 00000000..66e961bb --- /dev/null +++ b/spec/darwin/cron_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +include Serverspec::Helper::Darwin + +describe 'Serverspec cron matchers of Darwin family' do + it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh' + it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root' +end diff --git a/spec/debian/cron_spec.rb b/spec/debian/cron_spec.rb new file mode 100644 index 00000000..5dc76de4 --- /dev/null +++ b/spec/debian/cron_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +include Serverspec::Helper::Debian + +describe 'Serverspec cron matchers of Debian family' do + it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh' + it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root' +end diff --git a/spec/gentoo/cron_spec.rb b/spec/gentoo/cron_spec.rb new file mode 100644 index 00000000..4d4a6e25 --- /dev/null +++ b/spec/gentoo/cron_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +include Serverspec::Helper::Gentoo + +describe 'Serverspec cron matchers of Gentoo family' do + it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh' + it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root' +end diff --git a/spec/redhat/cron_spec.rb b/spec/redhat/cron_spec.rb new file mode 100644 index 00000000..3d4ae92a --- /dev/null +++ b/spec/redhat/cron_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +include Serverspec::Helper::RedHat + +describe 'Serverspec cron matchers of Red Hat family' do + it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh' + it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root' +end diff --git a/spec/redhat/file_spec.rb b/spec/redhat/file_spec.rb index 73429c8b..bd2463d2 100644 --- a/spec/redhat/file_spec.rb +++ b/spec/redhat/file_spec.rb @@ -2,7 +2,7 @@ include Serverspec::Helper::RedHat -describe 'Serverspec service matchers of Red Hat family' do +describe 'Serverspec file matchers of Red Hat family' do it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config' it_behaves_like 'support file be_directory matcher', '/etc/ssh' it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file' diff --git a/spec/solaris/cron_spec.rb b/spec/solaris/cron_spec.rb new file mode 100644 index 00000000..7bc15601 --- /dev/null +++ b/spec/solaris/cron_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +include Serverspec::Helper::Solaris + +describe 'Serverspec cron matchers of Solaris family' do + it_behaves_like 'support cron have_entry matcher', '* * * * * /usr/local/bin/batch.sh' + it_behaves_like 'support cron have_entry with user matcher', '* * * * * /usr/local/bin/batch.sh', 'root' +end diff --git a/spec/support/shared_cron_examples.rb b/spec/support/shared_cron_examples.rb new file mode 100644 index 00000000..35fb83f5 --- /dev/null +++ b/spec/support/shared_cron_examples.rb @@ -0,0 +1,23 @@ +shared_examples_for 'support cron have_entry matcher' do |entry| + describe 'have_cron_entry' do + describe cron do + it { should have_cron_entry entry } + end + + describe cron do + it { should_not have_cron_entry 'invalid entry' } + end + end +end + +shared_examples_for 'support cron have_entry with user matcher' do |entry, user| + describe 'have_cron_entry' do + describe cron do + it { should have_cron_entry(entry).with_user(user) } + end + + describe cron do + it { should_not have_cron_entry('invalid entry').with_user(user) } + end + end +end