apache-config-generator/spec/apache/config_spec.rb

119 lines
3.1 KiB
Ruby
Raw Normal View History

2010-05-04 15:48:59 +00:00
require 'apache/config'
2010-05-07 17:56:49 +00:00
require 'fileutils'
2010-05-04 15:48:59 +00:00
2010-05-07 15:26:40 +00:00
describe Apache::Config, "builds configurations" do
let(:apache) { Apache::Config }
before { apache.reset! }
def set_apache_env(env)
Object.send(:remove_const, :APACHE_ENV) if Object.const_defined? :APACHE_ENV
Object.send(:const_set, :APACHE_ENV, env)
2010-05-04 15:48:59 +00:00
end
it "should handle indent" do
2010-05-07 15:26:40 +00:00
apache.line_indent = 1
2010-05-04 15:48:59 +00:00
2010-05-07 15:26:40 +00:00
[
[ 'hello', ' hello' ],
[ [ 'hello', 'goodbye' ], [ ' hello', ' goodbye' ] ]
].each do |input, output|
apache.indent(input).should == output
end
2010-05-04 15:48:59 +00:00
end
it "should add a line to the config" do
2010-05-07 15:26:40 +00:00
apache << "hello"
apache.to_a.should == [ 'hello' ]
apache + [ 'goodbye' ]
apache.to_a.should == [ 'hello', 'goodbye' ]
2010-05-04 15:48:59 +00:00
end
it "should handle method_missing" do
2010-05-07 15:26:40 +00:00
apache.test "test2", "test3"
apache.test_again! "test2", "test3"
2010-05-04 15:48:59 +00:00
2010-05-07 15:26:40 +00:00
apache.to_a.should == [
2010-05-04 15:48:59 +00:00
'Test "test2" "test3"',
'TestAgain test2 test3'
]
end
it "should quoteize properly" do
2010-05-18 17:08:17 +00:00
["test", "test2"].quoteize.should == %w{"test" "test2"}
[:test, :test2].quoteize.should == %w{test test2}
2010-05-04 15:48:59 +00:00
end
it "should blockify a block" do
2010-05-07 15:26:40 +00:00
apache.blockify("Tag", [ 'part', 'part2' ]) do
2010-05-04 15:48:59 +00:00
something "goes here"
2010-05-06 14:40:45 +00:00
end.should == ['', '<Tag "part" "part2">', ' Something "goes here"', '</Tag>', '']
2010-05-07 15:26:40 +00:00
end
2010-05-04 15:51:06 +00:00
2010-05-07 15:26:40 +00:00
it "should blockify the name of a block" do
[
[ 'part', '"part"' ],
[ :part, 'part' ],
[ [ 'part', 'part2' ], '"part" "part2"' ]
].each do |name, attribute|
2010-05-18 17:20:49 +00:00
name.blockify.should == attribute
2010-05-07 15:26:40 +00:00
end
2010-05-04 15:48:59 +00:00
end
2010-05-04 21:04:44 +00:00
it "should handle a build" do
2010-05-07 17:56:49 +00:00
FileUtils.mkdir_p 'test'
apache.build('test/fake.conf') { my_test "this" }.should == [ 'MyTest "this"' ]
FileUtils.rm 'test/fake.conf'
2010-05-07 15:26:40 +00:00
end
2010-05-04 21:04:44 +00:00
2010-05-07 15:26:40 +00:00
it "should handle building if the environment is correct" do
set_apache_env(:test)
2010-05-18 16:43:57 +00:00
apache.build_and_return_if(:other) { my_test 'this' }.should == nil
apache.build_and_return_if(:test) { my_test 'this' }.should == [ 'MyTest "this"' ]
2010-05-07 15:26:40 +00:00
end
it "should only execute a block if the environment is correct" do
set_apache_env(:test)
test = 0
apache.if_environment(:other) { test = 1 }
test.should == 0
test = 0
apache.if_environment(:test) { test = 1 }
test.should == 1
end
it "should create an IfModule block" do
apache.if_module("test") { my_test }
apache.to_a.should == [ '', '<IfModule test_module>', ' MyTest', '</IfModule>', '' ]
end
it "should create a Directory block" do
dir = File.dirname(__FILE__)
apache.directory(dir) { my_test }
apache.to_a.should == [ '', %{<Directory "#{dir}">}, ' MyTest', '</Directory>', '' ]
apache.reset!
apache.directory('/does/not/exist') { my_test }
apache.to_a.should == [ '', %{<Directory "/does/not/exist">}, ' MyTest', '</Directory>', '' ]
end
it "should create a LocationMatch block" do
apache.location_match(%r{^/$}) { my_test }
apache.to_a.should == [ '', '<LocationMatch "^/$">', ' MyTest', '</LocationMatch>', '' ]
2010-05-04 21:04:44 +00:00
end
2010-05-04 15:48:59 +00:00
end
2010-11-24 19:36:09 +00:00
describe "Apache::Config used separately" do
context "it works" do
subject { Apache::Config.build_and_return { this_works }.first }
it { should == "ThisWorks" }
end
end