about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-06-06 06:41:29 +0000
committerzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-06-06 06:41:29 +0000
commita79c54448411cc596fb0d2354bd685d76831504b (patch)
treefd8c74a4650867f63a7609419efeb7f7e1f9bbdb /test
parentdd782065433f4d9a141e40f96668f3a7bbe4f7de (diff)
downloadunicorn-a79c54448411cc596fb0d2354bd685d76831504b.tar.gz
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@230 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'test')
-rw-r--r--test/test_command.rb101
1 files changed, 101 insertions, 0 deletions
diff --git a/test/test_command.rb b/test/test_command.rb
new file mode 100644
index 0000000..85793b2
--- /dev/null
+++ b/test/test_command.rb
@@ -0,0 +1,101 @@
+# Mongrel Web Server - A Mostly Ruby Webserver and Library
+#
+# Copyright (C) 2005 Zed A. Shaw zedshaw AT zedshaw dot com
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+require 'test/unit'
+require 'mongrel'
+require File.dirname(__FILE__) + '/testhelp.rb'
+
+
+class TestCommand < GemPlugin::Plugin "/commands"
+  include Mongrel::Command::Base
+
+  def configure
+    options [
+      ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
+      ['', '--user USER', "User to run as", :@user, nil],
+      ["-d", "--daemonize", "Whether to run in the background or not", :@daemon, false],
+      ["-x", "--test", "Used to let the test run failures", :@test, false],
+    ]
+  end
+
+  def validate
+    valid_dir? ".", "Can't validate current directory."
+    valid_exists? "Rakefile", "Rakefile not there, test is invalid."
+    if @test
+      valid_exist? "BADFILE", "Yeah, badfile"
+      valid_file? "BADFILE", "Not even a file"
+      valid_dir? "BADDIR", "No dir here"
+      valid? false, "Total failure"
+    end
+
+    return @valid
+  end
+
+
+  def run
+    $test_command_ran = true
+  end
+end
+
+class CommandTest < Test::Unit::TestCase
+
+  def setup
+    $test_command_ran = false
+  end
+
+  def teardown
+  end
+
+  def run_cmd(args)
+    Mongrel::Command::Registry.instance.run args
+  end
+
+  def test_run_command
+    redirect_test_io do
+      run_cmd ["testcommand"]
+      assert $test_command_ran, "command didn't run"
+    end
+  end
+
+  def test_command_error
+    redirect_test_io do
+      run_cmd ["crapcommand"]
+    end
+  end
+
+  def test_command_listing
+    redirect_test_io do
+      run_cmd ["help"]
+    end
+  end
+
+  def test_options
+    redirect_test_io do
+      run_cmd ["testcommand","-h"]
+      run_cmd ["testcommand","--help"]
+      run_cmd ["testcommand","-e","test","-d","--user"]
+    end
+  end
+
+  def test_version
+    redirect_test_io do
+      run_cmd ["testcommand", "--version"]
+    end
+  end
+
+end