Permalink
Browse files

Did a tiny bit of cleanup.

  • Loading branch information...
1 parent b3fed41 commit 9b4a39361384ad916e1f13096372928b43d7af00 @commondream commondream committed Mar 2, 2012
Showing with 91 additions and 39 deletions.
  1. +3 −1 Rakefile
  2. +14 −19 lib/tconsole.rb
  3. +0 −19 lib/tconsole/server.rb
  4. +71 −0 test/unit/config_test.rb
  5. +3 −0 test/unit/sample_config
View
@@ -1,8 +1,10 @@
require "bundler/gem_tasks"
require "rake/testtask"
+task :default => [:test]
+
Rake::TestTask.new do |t|
t.libs << "test"
- t.test_files = FileList['test/**/*_test.rb']
+ t.test_files = FileList['test/unit/**/*_test.rb']
t.verbose = true
end
View
@@ -53,26 +53,21 @@ def self.run(argv)
server_pid = fork do
pipe_server.callee!
- begin
- server = Server.new(config)
-
- while message = pipe_server.read
- config.trace("Server Received Message: #{message[:action]}")
- begin
- result = server.handle(message)
- pipe_server.write(result)
- rescue => e
- puts
- puts "An error occured: #{e.message}"
- config.trace("===========")
- config.trace(e.backtrace.join("\n"))
- config.trace("===========")
- pipe_server.write(nil)
- end
+ server = Server.new(config)
+
+ while message = pipe_server.read
+ config.trace("Server Received Message: #{message[:action]}")
+ begin
+ result = server.handle(message)
+ pipe_server.write(result)
+ rescue => e
+ puts
+ puts "An error occured: #{e.message}"
+ config.trace("===========")
+ config.trace(e.backtrace.join("\n"))
+ config.trace("===========")
+ pipe_server.write(nil)
end
-
- rescue Interrupt
- # do nothing here since the outer process will shut things down for us
end
end
View
@@ -13,25 +13,6 @@ def handle(message)
args = message[:args]
send(action, *args)
- # if action == "load_environment"
- # load_environment
- # elsif action == "run_failed"
- # run_failed
- # elsif action == "show_performance"
- # show_performance(message[:limit])
- # elsif action == "run_info"
- # run_info
- # elsif action == "set"
- # set(message[:var], message[:value])
- # elsif action == "run_file_set"
- # run_file_set(message[:set])
- # elsif action == "run_all_tests"
- # run_all_tests(message[:args])
- # elsif action == "autocomplete"
- # autocomplete(message[:text])
- # elsif action == "exit"
- # exit(0)
- # end
end
def stop
View
@@ -0,0 +1,71 @@
+require 'test_helper'
+
+module TConsole
+ class ConfigTest < MiniTest::Unit::TestCase
+
+ a "Config" do
+ setup do
+ @config = TConsole::Config.new
+ end
+
+ it "should have appropriate defaults" do
+ assert_equal false, @config.trace_execution
+ assert_equal "./test", @config.test_dir
+ assert_equal ["./test", "./lib"], @config.include_paths
+ assert_equal [], @config.preload_paths
+ assert_equal false, @config.fail_fast
+ assert_equal({ "all" => ["./test/**/*_test.rb"] }, @config.file_sets)
+ end
+
+ it "should have a validation error if the configured test directory doesn't exist" do
+ @config.test_dir = "./monkey_business"
+
+ errors = @config.validation_errors
+ refute_nil errors
+ assert_equal "Couldn't find test directory `./monkey_business`. Exiting.", errors[0]
+ end
+
+ it "should have a validation error if the configuration doesn't include an all file set" do
+ @config.file_sets = {}
+
+ errors = @config.validation_errors
+ refute_nil errors
+ assert_equal "No `all` file set is defined in your configuration. Exiting.", errors[0]
+ end
+ end
+
+ the "Config class" do
+ setup do
+ TConsole::Config.clear_loaded_configs
+ end
+
+ it "should save the proc passed to run when it's called" do
+ TConsole::Config.run do |config|
+ config.test_dir = "./awesome_sauce"
+ end
+
+ assert_equal 1, TConsole::Config.instance_variable_get(:@loaded_configs).length
+ end
+
+ it "should apply the loaded configs from first to last when configure is called" do
+ TConsole::Config.run do |config|
+ config.test_dir = "./awesome_sauce"
+ end
+
+ TConsole::Config.run do |config|
+ config.test_dir = "./awesomer_sauce"
+ end
+
+ config = TConsole::Config.configure
+
+ assert_equal "./awesomer_sauce", config.test_dir
+ end
+
+ it "should load a config file when load_config is called" do
+ TConsole::Config.load_config(File.join(File.dirname(__FILE__), "sample_config"))
+
+ assert_equal 1, TConsole::Config.instance_variable_get(:@loaded_configs).length
+ end
+ end
+ end
+end
View
@@ -0,0 +1,3 @@
+TConsole::Config.run do |config|
+ config.test_dir = "./awesome_sauce"
+end

0 comments on commit 9b4a393

Please sign in to comment.