Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit fcc68c7cf4787b42a43a1e2cc0204e6c9a3f5d07 0 parents
@commondream commondream authored
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in tconsole.gemspec
+gemspec
1  Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
5 bin/tconsole
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require "tconsole"
+
+TConsole::Runner.run
99 lib/tconsole.rb
@@ -0,0 +1,99 @@
+require "tconsole/version"
+
+require 'readline'
+require 'benchmark'
+
+module TConsole
+ class Runner
+ # Spawns a new environment. Looks at the results of the environment to determine whether to stop or
+ # keep running
+ def self.run
+ running = true
+
+ while running
+ read, write = IO.pipe
+ pid = fork do
+ response = run_environment(write)
+ write.puts [Marshal.dump(response)].pack("m")
+ end
+ write.close
+
+ response = read.read
+ Process.wait2(pid)
+ running = Marshal.load(response.unpack("m")[0])
+ read.close
+ end
+
+ puts
+ puts "Exiting. Bye!"
+ end
+
+ # Starts our Rails environment and listens for console commands
+ # Returns true if we should keep running or false if we need to exit
+ def self.run_environment(write)
+
+ puts
+ puts "Loading Ruby environment..."
+ time = Benchmark.realtime do
+ # Ruby environment loading is shamelessly borrowed from spork
+ ENV["RAILS_ENV"] ||= "test"
+ $:.unshift("./test")
+
+ require "./config/application"
+ ::Rails.application
+ end
+
+ puts "Environment loaded in #{time}s."
+ puts
+
+ # Store the state of the terminal
+ stty_save = `stty -g`.chomp
+ #trap('INT') { system('stty', stty_save); exit }
+
+
+ while line = Readline.readline('> ', true)
+ if line == "exit"
+ return false
+ elsif line == "reload"
+ return true
+ elsif line == "units"
+ run_tests(["test/unit/**/*_test.rb"])
+ elsif line == "functionals"
+ run_tests(["test/functional/**/*_test.rb"])
+ elsif line == "integration"
+ run_tests(["test/integration/**/*_test.rb"])
+ elsif line == "all"
+ run_tests(["test/unit/**/*_test.rb", "test/functional/**/*_test.rb", "test/integration/**/*_test.rb"])
+ else
+ run_tests([line])
+ end
+ end
+ end
+
+ # Taks an array of globs and loads all of the files in the globs
+ # and then runs the tests in those files
+ def self.run_tests(globs)
+ time = Benchmark.realtime do
+ pid = fork do
+ puts "Running tests..."
+ puts
+
+ paths = []
+ globs.each do |glob|
+ paths.concat(Dir.glob(glob))
+ end
+
+ paths.each do |path|
+ require File.realpath(path)
+ end
+ end
+
+ Process.wait2(pid)
+ end
+
+ puts
+ puts "Test time (including load): #{time}s"
+ puts
+ end
+ end
+end
3  lib/tconsole/version.rb
@@ -0,0 +1,3 @@
+module TConsole
+ VERSION = "0.0.1"
+end
24 tconsole.gemspec
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "tconsole/version"
+
+Gem::Specification.new do |s|
+ s.name = "tconsole"
+ s.version = TConsole::VERSION
+ s.authors = ["Alan Johnson"]
+ s.email = ["alan@commondream.net"]
+ s.homepage = ""
+ s.summary = %q{tconsole gives you a helpful console for running Rails tests}
+ s.description = %q{tconsole gives you a helpful console for running Rails tests}
+
+ s.rubyforge_project = "tconsole"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.