Permalink
Browse files

more test tidying

  • Loading branch information...
1 parent bbc9162 commit 2ed0956c65e27338af9377e1fd6e246eb47c1140 @fujin committed Jan 31, 2012
Showing with 117 additions and 17 deletions.
  1. +0 −1 Gemfile
  2. +2 −3 Guardfile
  3. +2 −2 NOTICE
  4. +2 −1 Rakefile
  5. +4 −9 lib/pylon/application.rb
  6. +2 −0 lib/pylon/exceptions.rb
  7. +99 −0 spec/pylon/application_spec.rb
  8. +6 −1 spec/spec_helper.rb
View
@@ -2,7 +2,6 @@ source "http://rubygems.org"
group :test do
gem "rspec", "~> 2.8.0"
- gem "libnotify"
gem "guard"
gem "guard-rspec"
end
View
@@ -1,8 +1,7 @@
# -*- mode: ruby -*-
-guard 'rspec', :version => 2 do
+guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
-end
-
+end
View
4 NOTICE
@@ -1,8 +1,8 @@
Pylon Notice
===========
-Developed by AJ Christensen (http://junglist.gen.nz)
+Developed by AJ Christensen (http://junglist.gen.nz) under the Apache V2 license, per LICENSE file.
-* Copyright 2011, AJ Christensen <aj@junglist.gen.nz>
+* Copyright 2012, AJ Christensen <aj@junglist.gen.nz>
View
@@ -15,7 +15,8 @@ require "bundler/gem_tasks"
desc "run specs"
Rake::TestTask.new do |spec|
- spec.verbose = false
+ spec.loader = :direct
+ spec.verbose = true
spec.name = "spec"
spec.test_files = FileList["spec/**/*_spec.rb"]
end
View
@@ -67,16 +67,11 @@ def initialize
Pylon::Application.fatal!("SIGINT received, stopping", 2)
end
- unless RUBY_PLATFORM =~ /mswin|mingw32|windows/
- trap("QUIT") do
- Pylon::Log.info("SIGQUIT received, call stack:\n " + caller.join("\n "))
- end
-
- trap("HUP") do
- Pylon::Log.info("SIGHUP received, reconfiguring")
- # reconfigure
- end
+ trap("HUP") do
+ Pylon::Log.info("SIGHUP received, reconfiguring")
+ # reconfigure
end
+
end
option :config_file,
View
@@ -20,6 +20,8 @@
class Pylon
class Exceptions
+ class Application < StandardError; end
+
class DCell
class Respawn < StandardError; end
end
@@ -0,0 +1,99 @@
+#
+# Author:: AJ Christensen (<aj@junglist.gen.nz>)
+# Copyright:: Copyright (c) 2012 AJ Christensen
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require_relative "../spec_helper"
+
+describe Pylon::Application do
+ before do
+ Pylon::Log.logger = Logger.new(StringIO.new)
+ @app = Pylon::Application.new
+ Dir.stub!(:chdir).and_return(0)
+ @app.stub!(:reconfigure)
+ end
+
+ describe "run" do
+ it "needs tests"
+ end
+
+ describe "configure_logging" do
+ before do
+ @app = Pylon::Application.new
+ Pylon::Log.stub!(:init)
+ Pylon::Log.stub!(:level=)
+ end
+
+ it "should initialise the pylon logger" do
+ Pylon::Log.should_receive(:init).with(Pylon::Config[:log_location]).and_return(true)
+ @app.configure_logging
+ end
+
+ it "should initialise the pylon logger level" do
+ Pylon::Log.should_receive(:level=).with(Pylon::Config[:log_level]).and_return(true)
+ @app.configure_logging
+ end
+
+ end
+
+ describe "class method: fatal!" do
+ before do
+ STDERR.stub!(:puts).with("FATAL: blah").and_return(true)
+ Pylon::Log.stub!(:fatal).with("blah").and_return(true)
+ Process.stub!(:exit).and_return(true)
+ end
+
+ it "should log an error message to the logger" do
+ Pylon::Log.should_receive(:fatal).with("blah").and_return(true)
+ Pylon::Application.fatal! "blah"
+ end
+
+ describe "when an exit code is supplied" do
+ it "should exit with the given exit code" do
+ Process.should_receive(:exit).with(-100).and_return(true)
+ Pylon::Application.fatal! "blah", -100
+ end
+ end
+
+ describe "when an exit code is not supplied" do
+ it "should exit with the default exit code" do
+ Process.should_receive(:exit).with(-1).and_return(true)
+ Pylon::Application.fatal! "blah"
+ end
+ end
+
+ end
+
+ describe "setup_application" do
+ before do
+ @app = Pylon::Application.new
+ end
+
+ it "should raise an error" do
+ lambda { @app.setup_application }.should raise_error(Pylon::Exceptions::Application)
+ end
+ end
+
+ describe "run_application" do
+ before do
+ @app = Pylon::Application.new
+ end
+
+ it "should raise an error" do
+ lambda { @app.run_application }.should raise_error(Pylon::Exceptions::Application)
+ end
+ end
+end
View
@@ -1,3 +1,8 @@
require "rspec/autorun"
+require "rspec/mocks"
-require_relative "../lib/pylon"
+$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
+$:.unshift(File.expand_path("../lib", __FILE__))
+$:.unshift(File.dirname(__FILE__))
+
+Dir[File.join(File.dirname(__FILE__), "..", "lib", "**", "*.rb")].sort.each { |lib| require lib }

0 comments on commit 2ed0956

Please sign in to comment.