tconsole 1.1.0pre3 → 1.1.0pre4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tconsole.rb +14 -5
- data/lib/tconsole/config.rb +94 -0
- data/lib/tconsole/server.rb +28 -47
- data/lib/tconsole/version.rb +1 -1
- data/test/config_test.rb +3 -0
- metadata +7 -4
data/lib/tconsole.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "tconsole/version"
|
2
|
+
require "tconsole/config"
|
2
3
|
require "tconsole/server"
|
3
4
|
require "tconsole/test_result"
|
4
5
|
require "tconsole/util"
|
@@ -45,8 +46,10 @@ module TConsole
|
|
45
46
|
console = Console.new
|
46
47
|
|
47
48
|
# set up the config
|
48
|
-
config =
|
49
|
-
config
|
49
|
+
config = Config.configure
|
50
|
+
config.trace = true if argv.include?("--trace")
|
51
|
+
|
52
|
+
socket_path = "/tmp/tconsole.#{Process.pid}"
|
50
53
|
|
51
54
|
# Start the server
|
52
55
|
while running
|
@@ -56,18 +59,24 @@ module TConsole
|
|
56
59
|
begin
|
57
60
|
server = Server.new(config)
|
58
61
|
|
59
|
-
drb_server = DRb.start_service("drbunix
|
62
|
+
drb_server = DRb.start_service("drbunix:#{socket_path}", server)
|
60
63
|
DRb.thread.join
|
61
64
|
rescue Interrupt
|
62
65
|
# do nothing here since the outer process will shut things down for us
|
63
66
|
end
|
64
67
|
end
|
65
68
|
|
69
|
+
# Wait for the server to be fully started
|
70
|
+
wait_until = Time.now + 10
|
71
|
+
until(File.exist?(socket_path) || Time.now > wait_until)
|
72
|
+
sleep(1)
|
73
|
+
end
|
74
|
+
|
66
75
|
# Set up our client connection to the server
|
67
|
-
|
76
|
+
DRb.start_service
|
77
|
+
server = DRbObject.new_with_uri("drbunix:#{socket_path}")
|
68
78
|
|
69
79
|
loaded = false
|
70
|
-
wait_until = Time.now + 10
|
71
80
|
until loaded || Time.now > wait_until
|
72
81
|
# Give drb a second to get set up
|
73
82
|
sleep(1)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module TConsole
|
2
|
+
class Config
|
3
|
+
# Lets us know if we should include trace output
|
4
|
+
attr_accessor :trace
|
5
|
+
|
6
|
+
# Test directory for the app we're testing
|
7
|
+
attr_accessor :test_dir
|
8
|
+
|
9
|
+
# Paths to add to the ruby include path
|
10
|
+
attr_accessor :include_paths
|
11
|
+
|
12
|
+
# Paths we want to preload
|
13
|
+
attr_accessor :preload_paths
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
self.trace = false
|
17
|
+
self.test_dir = "./test"
|
18
|
+
self.include_paths = ["./test", "./lib"]
|
19
|
+
self.preload_paths = []
|
20
|
+
|
21
|
+
@after_load = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def trace?
|
25
|
+
self.trace
|
26
|
+
end
|
27
|
+
|
28
|
+
# Code to run before loading the environment
|
29
|
+
def before_load(&block)
|
30
|
+
@before_load = block
|
31
|
+
end
|
32
|
+
|
33
|
+
# Calls the before load callback
|
34
|
+
def before_load!
|
35
|
+
@before_load.call unless @before_load.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
# Code to run after loading the environment
|
39
|
+
def after_load(&block)
|
40
|
+
@after_load = block
|
41
|
+
end
|
42
|
+
|
43
|
+
# Calls the after load callback
|
44
|
+
def after_load!
|
45
|
+
@after_load.call unless @after_load.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
# Calls before each test execution
|
49
|
+
def before_test_run(&block)
|
50
|
+
@before_test_run = block
|
51
|
+
end
|
52
|
+
|
53
|
+
def before_test_run!
|
54
|
+
@before_test_run.call unless @before_test_run.nil?
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns an appropriate tconsole config based on the environment
|
58
|
+
def self.configure
|
59
|
+
if is_rails?
|
60
|
+
config = Config.new
|
61
|
+
config.preload_paths = ["./config/application"]
|
62
|
+
config.include_paths = ["./test"]
|
63
|
+
|
64
|
+
config.before_load do
|
65
|
+
ENV["RAILS_ENV"] ||= "test"
|
66
|
+
end
|
67
|
+
|
68
|
+
config.after_load do
|
69
|
+
::Rails.application
|
70
|
+
::Rails::Engine.class_eval do
|
71
|
+
def eager_load!
|
72
|
+
# turn off eager_loading
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
config.before_test_run do
|
78
|
+
if defined? ::ActiveRecord
|
79
|
+
::ActiveRecord::Base.clear_active_connections!
|
80
|
+
::ActiveRecord::Base.establish_connection
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
config
|
85
|
+
else
|
86
|
+
Config.new
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.is_rails?
|
91
|
+
@rails ||= !!File.exist?("./config/application.rb")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/tconsole/server.rb
CHANGED
@@ -15,16 +15,28 @@ module TConsole
|
|
15
15
|
result = false
|
16
16
|
|
17
17
|
time = Benchmark.realtime do
|
18
|
+
puts
|
19
|
+
puts "Loading environment..."
|
18
20
|
|
19
21
|
begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
result = load_non_rails_environment
|
22
|
+
# Append our include paths
|
23
|
+
config.include_paths.each do |include_path|
|
24
|
+
$:.unshift(include_path)
|
24
25
|
end
|
26
|
+
|
27
|
+
config.before_load!
|
28
|
+
|
29
|
+
# Load our preload files
|
30
|
+
config.preload_paths.each do |preload_path|
|
31
|
+
require preload_path
|
32
|
+
end
|
33
|
+
|
34
|
+
config.after_load!
|
35
|
+
|
36
|
+
result = true
|
25
37
|
rescue Exception => e
|
26
38
|
puts "Error - Loading your environment failed: #{e.message}"
|
27
|
-
if config
|
39
|
+
if config.trace?
|
28
40
|
puts
|
29
41
|
puts " #{e.backtrace.join("\n ")}"
|
30
42
|
end
|
@@ -39,42 +51,6 @@ module TConsole
|
|
39
51
|
result
|
40
52
|
end
|
41
53
|
|
42
|
-
def is_rails?
|
43
|
-
@rails ||= !!File.exist?("./config/application.rb")
|
44
|
-
end
|
45
|
-
|
46
|
-
def load_rails_environment
|
47
|
-
puts
|
48
|
-
puts "Loading Rails environment..."
|
49
|
-
|
50
|
-
# Ruby environment loading is shamelessly borrowed from spork
|
51
|
-
ENV["RAILS_ENV"] ||= "test"
|
52
|
-
$:.unshift("./test")
|
53
|
-
|
54
|
-
# This is definitely based on Sporks rails startup code. I tried initially to use Rake to get things done
|
55
|
-
# and match the test environment a bit better, but it didn't work out well at all
|
56
|
-
# TODO: Figure out how ot get rake db:test:load and rake test:prepare working in this context
|
57
|
-
require "./config/application"
|
58
|
-
::Rails.application
|
59
|
-
::Rails::Engine.class_eval do
|
60
|
-
def eager_load!
|
61
|
-
# turn off eager_loading
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
true
|
66
|
-
end
|
67
|
-
|
68
|
-
def load_non_rails_environment
|
69
|
-
$:.unshift("./lib")
|
70
|
-
$:.unshift("./test")
|
71
|
-
|
72
|
-
puts
|
73
|
-
puts "Loading environment..."
|
74
|
-
|
75
|
-
true
|
76
|
-
end
|
77
|
-
|
78
54
|
def run_tests(globs, name_pattern, message = "Running tests...")
|
79
55
|
time = Benchmark.realtime do
|
80
56
|
# Pipe for communicating with child so we can get its results back
|
@@ -90,16 +66,12 @@ module TConsole
|
|
90
66
|
globs.each do |glob|
|
91
67
|
paths.concat(Dir.glob(glob))
|
92
68
|
end
|
93
|
-
puts "Paths: #{paths.join(", ")}"
|
94
69
|
|
95
70
|
paths.each do |path|
|
96
71
|
require File.expand_path(path)
|
97
72
|
end
|
98
73
|
|
99
|
-
|
100
|
-
::ActiveRecord::Base.clear_active_connections!
|
101
|
-
::ActiveRecord::Base.establish_connection
|
102
|
-
end
|
74
|
+
config.before_test_run!
|
103
75
|
|
104
76
|
if defined?(::MiniTest)
|
105
77
|
require File.join(File.dirname(__FILE__), "minitest_handler")
|
@@ -150,7 +122,6 @@ module TConsole
|
|
150
122
|
end
|
151
123
|
|
152
124
|
def run_failed
|
153
|
-
# TODO: We probably shouldn't use built in Rails methods here if we can help it
|
154
125
|
file_names = last_result.failure_details.map { |detail| filenameify(detail[:class]) }
|
155
126
|
files_to_rerun = []
|
156
127
|
|
@@ -251,5 +222,15 @@ module TConsole
|
|
251
222
|
|
252
223
|
result
|
253
224
|
end
|
225
|
+
|
226
|
+
# Totally yanked from the Rails test tasks
|
227
|
+
def silence_stderr
|
228
|
+
old_stderr = STDERR.dup
|
229
|
+
STDERR.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
|
230
|
+
STDERR.sync = true
|
231
|
+
yield
|
232
|
+
ensure
|
233
|
+
STDERR.reopen(old_stderr)
|
234
|
+
end
|
254
235
|
end
|
255
236
|
end
|
data/lib/tconsole/version.rb
CHANGED
data/test/config_test.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tconsole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.0pre4
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70233285449540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 1.0.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70233285449540
|
25
25
|
description: ! " tconsole allows Rails developers to easily and quickly run their
|
26
26
|
tests as a whole or in subsets. It forks the testing processes from\n a preloaded
|
27
27
|
test environment to ensure that developers don't have to reload their entire Rails
|
@@ -40,12 +40,14 @@ files:
|
|
40
40
|
- Rakefile
|
41
41
|
- bin/tconsole
|
42
42
|
- lib/tconsole.rb
|
43
|
+
- lib/tconsole/config.rb
|
43
44
|
- lib/tconsole/minitest_handler.rb
|
44
45
|
- lib/tconsole/server.rb
|
45
46
|
- lib/tconsole/test_result.rb
|
46
47
|
- lib/tconsole/util.rb
|
47
48
|
- lib/tconsole/version.rb
|
48
49
|
- tconsole.gemspec
|
50
|
+
- test/config_test.rb
|
49
51
|
homepage: ''
|
50
52
|
licenses: []
|
51
53
|
post_install_message:
|
@@ -70,4 +72,5 @@ rubygems_version: 1.8.11
|
|
70
72
|
signing_key:
|
71
73
|
specification_version: 3
|
72
74
|
summary: tconsole is a helpful console for running Rails tests
|
73
|
-
test_files:
|
75
|
+
test_files:
|
76
|
+
- test/config_test.rb
|