From 533b79a56f88cf0daf507a79b17d560be39b1280 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 7 May 2010 13:56:49 -0400 Subject: [PATCH] more spec coverage --- lib/apache/directory.rb | 9 +++++++-- lib/apache/master.rb | 4 ++-- spec/config_spec.rb | 5 ++++- spec/directory_spec.rb | 15 +++++++++++++++ spec/master_spec.rb | 18 ++++++++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 spec/directory_spec.rb diff --git a/lib/apache/directory.rb b/lib/apache/directory.rb index 0fcf28f..7ef36c3 100644 --- a/lib/apache/directory.rb +++ b/lib/apache/directory.rb @@ -1,11 +1,16 @@ module Apache module Directories def options(*opt) - self << "Options #{apachify(opt) * " "}" + create_options_list('Options', *opt) end def index_options(*opt) - self << "IndexOptions #{apachify(opt) * " "}" + create_options_list('IndexOptions', *opt) end + + private + def create_options_list(tag, *opt) + self << "#{tag} #{apachify(opt) * " "}" + end end end diff --git a/lib/apache/master.rb b/lib/apache/master.rb index cd46b7d..04dc31a 100644 --- a/lib/apache/master.rb +++ b/lib/apache/master.rb @@ -42,7 +42,7 @@ module Apache def script_alias(uri, path) directory? path - self << %{ScriptAlias "#{uri}" "#{path}"} + self << %{ScriptAlias #{quoteize(uri, path) * ' '}} end alias :script_alias! :script_alias @@ -66,7 +66,7 @@ module Apache hash.each do |key, value| output = "Header set #{quoteize(key)}" case value - when String + when String, Symbol output += " #{quoteize(value)}" when Array output += " #{quoteize(value.first)} #{value.last}" diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 23ec020..0808e3e 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -1,4 +1,5 @@ require 'apache/config' +require 'fileutils' describe Apache::Config, "builds configurations" do let(:apache) { Apache::Config } @@ -75,7 +76,9 @@ describe Apache::Config, "builds configurations" do end it "should handle a build" do - apache.build { my_test "this" }.should == [ 'MyTest "this"' ] + FileUtils.mkdir_p 'test' + apache.build('test/fake.conf') { my_test "this" }.should == [ 'MyTest "this"' ] + FileUtils.rm 'test/fake.conf' end it "should handle building if the environment is correct" do diff --git a/spec/directory_spec.rb b/spec/directory_spec.rb new file mode 100644 index 0000000..8d835ac --- /dev/null +++ b/spec/directory_spec.rb @@ -0,0 +1,15 @@ +require 'apache/config' + +describe Apache::Master, "should provide basic helpers for configuration" do + let(:apache) { Apache::Config } + + before { apache.reset! } + + it "should create the list of options" do + { :options => 'Options', :index_options => 'IndexOptions' }.each do |method, tag| + apache.reset! + apache.send(method, :test, 'test2') + apache.to_a.should == [ "#{tag} Test Test2" ] + end + end +end diff --git a/spec/master_spec.rb b/spec/master_spec.rb index 2c03ec9..f7bd8c0 100644 --- a/spec/master_spec.rb +++ b/spec/master_spec.rb @@ -63,4 +63,22 @@ describe Apache::Master, "should provide basic helpers for configuration" do apache.comment(["This is", "a comment"]) apache.to_a.should == [ '#', '# This is', '# a comment', '#' ] end + + it "should create & check a script alias" do + dir = File.dirname(__FILE__) + + apache.script_alias '/script/', dir + apache.to_a.should == [ %{ScriptAlias "/script/" "#{dir}"} ] + end + + it "should add a type with some other options" do + apache.add_type! 'text/html', '.html', :handler => 'html-handler' + apache.to_a.should == [ 'AddType text/html .html', 'AddHandler html-handler .html' ] + end + + it "should create headers" do + apache.set_header :test => :test2 + apache.set_header 'test3' => [ 'test4', "test5=test6" ] + apache.to_a.should == [ 'Header set test test2', 'Header set "test3" "test4" test5=test6' ] + end end