Skip to content

Instantly share code, notes, and snippets.

@plexus
Created May 17, 2013 14:52
Show Gist options
  • Save plexus/5599561 to your computer and use it in GitHub Desktop.
Save plexus/5599561 to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
# spec_helper.rb
require 'open3'
class Command
attr_reader :stdin, :stdout, :stderr, :thread
def initialize(cmd)
@stdin, @stdout, @stderr, @thread = Open3.popen3 cmd
end
def successful?
thread.value.to_i == 0
end
def must_succeed
successful?.must_equal true
end
def grep(reg)
@stdout.lines.map(&:chomp).grep(reg)
end
end
def command(cmd)
Command.new(cmd)
end
describe 'custom apache setup' do
it "should install the Debian style apache helpers" do
command('which a2enmod').must_succeed
command('which a2ensite').must_succeed
end
%w[ alias auth_basic authn_file authz_default authz_groupfile authz_host
authz_user autoindex cache cgi deflate dir env headers mime negotiation
proxy_balancer proxy_http proxy rewrite setenvif ssl status ].each do |mod|
it "should install the necessary apache module `#{mod}'" do
File.exist?("/etc/apache2/mods-enabled/#{mod}.load").must_equal true
end
end
it "should install exactly the packages we want" do
command("dpkg -l | awk '{print $2}'").grep(/apache/).sort.must_equal %w[
apache2 apache2-mpm-prefork
apache2-prefork-dev apache2-utils
apache2.2-common apache2.2-bin ].sort
end
it "should have the apache service running" do
command('service apache2 status').must_be :=~, /is running/
end
it 'should contain custom configuration' do
apache_conf = File.read('/etc/apache2/apache2.conf')
[
/^\s*KeepAliveTimeout\s2\s*$/,
/ServerTokens Prod/
].each do |regexp|
apache_conf.must_be :=~, regexp
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment