From c28918d9050f93d36b7fb27269e0b770dffe4095 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 4 May 2010 17:04:44 -0400 Subject: [PATCH] more testing setup --- Rakefile | 3 ++- lib/apache/config.rb | 4 +--- lib/apache/master.rb | 2 +- lib/apache/modules.rb | 8 +++++++- spec/config_spec.rb | 10 ++++++++++ spec/master_spec.rb | 19 +++++++++++++++++++ spec/modules_spec.rb | 23 +++++++++++++++++++++++ 7 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 spec/master_spec.rb create mode 100644 spec/modules_spec.rb diff --git a/Rakefile b/Rakefile index fc574b7..c795371 100644 --- a/Rakefile +++ b/Rakefile @@ -17,6 +17,7 @@ namespace :spec do Spec::Rake::SpecTask.new('rcov') do |t| t.spec_files = FileList['spec/*.rb'] t.rcov = true - t.rcov_opts = ['--exclude', 'spec'] + t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems'] + t.spec_opts = ['-b'] end end diff --git a/lib/apache/config.rb b/lib/apache/config.rb index e610045..fe37268 100644 --- a/lib/apache/config.rb +++ b/lib/apache/config.rb @@ -9,12 +9,10 @@ module Apache include Apache::Quoteize include Apache::Permissions - def build(target, &block) + def build(target = nil, &block) reset! self.instance_eval(&block) - - puts @config * "\n" end # Reset the current settings diff --git a/lib/apache/master.rb b/lib/apache/master.rb index e04fe0e..0a97bee 100644 --- a/lib/apache/master.rb +++ b/lib/apache/master.rb @@ -1,7 +1,7 @@ module Apache module Master def modules(*modules, &block) - @config << Modules.build(*modules, &block) + @config += Modules.build(*modules, &block) end def runner(user, group = nil) diff --git a/lib/apache/modules.rb b/lib/apache/modules.rb index 5a63441..c080ab8 100644 --- a/lib/apache/modules.rb +++ b/lib/apache/modules.rb @@ -5,8 +5,14 @@ module Apache class << self include Apache::Quoteize - def build(*modules, &block) + attr_accessor :modules + + def reset! @modules = [] + end + + def build(*modules, &block) + reset! modules.each { |m| self.send(m) } self.instance_eval(&block) if block diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 1cc4e70..9c3f946 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -47,4 +47,14 @@ describe Apache::Config, "should handle the basics of Apache config" do something "goes here" end.should == ['', ' Something "goes here"', ''] end + + it "should handle a build" do + Apache::Config.build do + my_test "this" + end + + Apache::Config.config.should == [ + 'MyTest "this"' + ] + end end diff --git a/spec/master_spec.rb b/spec/master_spec.rb new file mode 100644 index 0000000..50964cc --- /dev/null +++ b/spec/master_spec.rb @@ -0,0 +1,19 @@ +require 'apache/config' + +describe Apache::Master, "should provide basic helpers for configuration" do + before do + Apache::Config.reset! + end + + it "should build the modules with the provided block" do + Apache::Config.modules(:this, :that) do + my "is here" + end + + Apache::Config.config.should == [ + 'LoadModule "this_module" "modules/mod_this.so"', + 'LoadModule "that_module" "modules/mod_that.so"', + 'LoadModule "my_module" "is here"', + ] + end +end diff --git a/spec/modules_spec.rb b/spec/modules_spec.rb new file mode 100644 index 0000000..2c6f1ec --- /dev/null +++ b/spec/modules_spec.rb @@ -0,0 +1,23 @@ +require 'apache/modules' + +describe Apache::Modules, "should build a list of modules" do + before do + Apache::Modules.reset! + end + + it "should handle method_missing" do + Apache::Modules.mine + + Apache::Modules.modules.should == [ 'LoadModule "mine_module" "modules/mod_mine.so"' ] + end + + it "should build a set of modules" do + Apache::Modules.build(:this, :that) do + mine "my_path" + end.should == [ + 'LoadModule "this_module" "modules/mod_this.so"', + 'LoadModule "that_module" "modules/mod_that.so"', + 'LoadModule "mine_module" "my_path"' + ] + end +end