diff --git a/sandbox/serverspec/getting-started/.rspec b/sandbox/serverspec/getting-started/.rspec new file mode 100644 index 0000000..16f9cdb --- /dev/null +++ b/sandbox/serverspec/getting-started/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/sandbox/serverspec/getting-started/Gemfile b/sandbox/serverspec/getting-started/Gemfile new file mode 100644 index 0000000..9b288d0 --- /dev/null +++ b/sandbox/serverspec/getting-started/Gemfile @@ -0,0 +1 @@ +gem 'serverspec' diff --git a/sandbox/serverspec/getting-started/Rakefile b/sandbox/serverspec/getting-started/Rakefile new file mode 100644 index 0000000..11ba867 --- /dev/null +++ b/sandbox/serverspec/getting-started/Rakefile @@ -0,0 +1,27 @@ +require 'rake' +require 'rspec/core/rake_task' + +task :spec => 'spec:all' +task :default => :spec + +namespace :spec do + targets = [] + Dir.glob('./spec/*').each do |dir| + next unless File.directory?(dir) + target = File.basename(dir) + target = "_#{target}" if target == "default" + targets << target + end + + task :all => targets + task :default => :all + + targets.each do |target| + original_target = target == "_default" ? target[1..-1] : target + desc "Run serverspec tests to #{original_target}" + RSpec::Core::RakeTask.new(target.to_sym) do |t| + ENV['TARGET_HOST'] = original_target + t.pattern = "spec/#{original_target}/*_spec.rb" + end + end +end diff --git a/sandbox/serverspec/getting-started/spec/localhost/sample_spec.rb b/sandbox/serverspec/getting-started/spec/localhost/sample_spec.rb new file mode 100644 index 0000000..53754ac --- /dev/null +++ b/sandbox/serverspec/getting-started/spec/localhost/sample_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe package('apache'), if: os[:family] == 'arch' do + it { should be_installed } +end + +describe service('httpd'), if: os[:family] == 'arch' do + it { should be_enabled } + it { should be_running } +end + +describe package('httpd'), if: os[:family] == 'redhat' do + it { should be_installed } +end + +describe package('apache2'), if: os[:family] == 'ubuntu' do + it { should be_installed } +end + +describe service('httpd'), if: os[:family] == 'redhat' do + it { should be_enabled } + it { should be_running } +end + +describe service('apache2'), if: os[:family] == 'ubuntu' do + it { should be_enabled } + it { should be_running } +end + +describe service('org.apache.httpd'), if: os[:family] == 'darwin' do + it { should be_enabled } + it { should be_running } +end + +describe port(80) do + it { should be_listening } +end diff --git a/sandbox/serverspec/getting-started/spec/spec_helper.rb b/sandbox/serverspec/getting-started/spec/spec_helper.rb new file mode 100644 index 0000000..677ae95 --- /dev/null +++ b/sandbox/serverspec/getting-started/spec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'serverspec' + +set :backend, :exec +