tconsole 0.0.2.pre → 0.0.3.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tconsole.rb +61 -71
- data/lib/tconsole/server.rb +62 -0
- data/lib/tconsole/version.rb +1 -1
- metadata +3 -2
data/lib/tconsole.rb
CHANGED
@@ -1,110 +1,100 @@
|
|
1
1
|
require "tconsole/version"
|
2
|
+
require "tconsole/server"
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require "readline"
|
5
|
+
require "benchmark"
|
6
|
+
require "drb/drb"
|
5
7
|
|
6
8
|
module TConsole
|
7
9
|
class Runner
|
10
|
+
|
11
|
+
SERVER_URI = "druby://localhost:8788"
|
8
12
|
# Spawns a new environment. Looks at the results of the environment to determine whether to stop or
|
9
13
|
# keep running
|
10
14
|
def self.run
|
11
|
-
|
12
15
|
stty_save = `stty -g`.chomp
|
13
16
|
|
14
|
-
# We're only going to handle interrupts on the inner process
|
15
|
-
trap("SIGINT", "IGNORE");
|
16
17
|
running = true
|
18
|
+
trap("SIGINT", "SYSTEM_DEFAULT")
|
19
|
+
|
20
|
+
# A little welcome
|
21
|
+
puts
|
22
|
+
puts "Welcome to tconsole. Type 'help' for help or 'exit' to quit."
|
17
23
|
|
24
|
+
# Start the server
|
18
25
|
while running
|
26
|
+
# ignore ctrl-c during load, since things can get kind of messy if we don't
|
27
|
+
|
19
28
|
pid = fork do
|
20
|
-
|
21
|
-
|
29
|
+
begin
|
30
|
+
server = Server.new
|
22
31
|
|
23
|
-
|
24
|
-
running = false if status.exitstatus != 0
|
25
|
-
end
|
32
|
+
DRb.start_service(SERVER_URI, server)
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
# Starts our Rails environment and listens for console commands
|
33
|
-
# Returns true if we should keep running or false if we need to exit
|
34
|
-
def self.run_environment
|
34
|
+
DRb.thread.join
|
35
|
+
rescue Interrupt
|
36
|
+
# do nothing here since the outer process will shut things down for us
|
37
|
+
end
|
38
|
+
end
|
35
39
|
|
36
|
-
|
40
|
+
# Set up our client connection to the server
|
41
|
+
server = DRbObject.new_with_uri(SERVER_URI)
|
42
|
+
|
43
|
+
loaded = false
|
44
|
+
wait_until = Time.now + 10
|
45
|
+
until loaded || Time.now > wait_until
|
46
|
+
begin
|
47
|
+
running = server.load_environment
|
48
|
+
loaded = true
|
49
|
+
rescue
|
50
|
+
loaded = false
|
51
|
+
rescue Interrupt
|
52
|
+
# do nothing if we get an interrupt
|
53
|
+
puts "Interrupted in client"
|
54
|
+
end
|
55
|
+
end
|
37
56
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# Ruby environment loading is shamelessly borrowed from spork
|
43
|
-
ENV["RAILS_ENV"] ||= "test"
|
44
|
-
$:.unshift("./test")
|
45
|
-
|
46
|
-
require 'rake'
|
47
|
-
Rake.application.init
|
48
|
-
Rake.application.load_rakefile
|
49
|
-
Rake.application.invoke_task("test:prepare")
|
50
|
-
rescue Exception => e
|
51
|
-
puts "Error: Loading your environment failed."
|
52
|
-
puts " #{e.message}"
|
53
|
-
return false
|
57
|
+
if !loaded
|
58
|
+
puts
|
59
|
+
puts "Couldn't connect to test environment. Exiting."
|
60
|
+
exit(1)
|
54
61
|
end
|
62
|
+
|
63
|
+
running = command_loop(server) if running
|
64
|
+
|
65
|
+
server.stop
|
66
|
+
Process.wait2(pid)
|
55
67
|
end
|
56
68
|
|
57
|
-
puts "Environment loaded in #{time}s."
|
58
69
|
puts
|
70
|
+
puts "Exiting. Bye!"
|
71
|
+
system("stty", stty_save);
|
72
|
+
end
|
59
73
|
|
60
|
-
|
61
|
-
|
74
|
+
def self.command_loop(server)
|
75
|
+
while line = Readline.readline("tconsole> ", true)
|
76
|
+
if line == ""
|
77
|
+
# do nothing
|
78
|
+
elsif line == "exit"
|
62
79
|
return false
|
63
80
|
elsif line == "reload"
|
64
81
|
return true
|
65
82
|
elsif line == "help"
|
66
83
|
help
|
67
84
|
elsif line == "units"
|
68
|
-
run_tests(["test/unit/**/*_test.rb"])
|
85
|
+
server.run_tests(["test/unit/**/*_test.rb"])
|
69
86
|
elsif line == "functionals"
|
70
|
-
run_tests(["test/functional/**/*_test.rb"])
|
87
|
+
server.run_tests(["test/functional/**/*_test.rb"])
|
71
88
|
elsif line == "integration"
|
72
|
-
run_tests(["test/integration/**/*_test.rb"])
|
89
|
+
server.run_tests(["test/integration/**/*_test.rb"])
|
73
90
|
elsif line == "all"
|
74
|
-
run_tests(["test/unit/**/*_test.rb", "test/functional/**/*_test.rb", "test/integration/**/*_test.rb"])
|
91
|
+
server.run_tests(["test/unit/**/*_test.rb", "test/functional/**/*_test.rb", "test/integration/**/*_test.rb"])
|
75
92
|
else
|
76
|
-
run_tests([line])
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
return false
|
81
|
-
end
|
82
|
-
|
83
|
-
# Taks an array of globs and loads all of the files in the globs
|
84
|
-
# and then runs the tests in those files
|
85
|
-
def self.run_tests(globs)
|
86
|
-
time = Benchmark.realtime do
|
87
|
-
pid = fork do
|
88
|
-
|
89
|
-
puts "Running tests..."
|
90
|
-
puts
|
91
|
-
|
92
|
-
paths = []
|
93
|
-
globs.each do |glob|
|
94
|
-
paths.concat(Dir.glob(glob))
|
95
|
-
end
|
96
|
-
|
97
|
-
paths.each do |path|
|
98
|
-
require File.realpath(path)
|
99
|
-
end
|
93
|
+
server.run_tests([line])
|
100
94
|
end
|
101
|
-
|
102
|
-
Process.wait2(pid)
|
103
95
|
end
|
104
96
|
|
105
|
-
|
106
|
-
puts "Test time (including load): #{time}s"
|
107
|
-
puts
|
97
|
+
return true
|
108
98
|
end
|
109
99
|
|
110
100
|
# Prints a list of available commands
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module TConsole
|
2
|
+
class Server
|
3
|
+
def stop
|
4
|
+
DRb.stop_service
|
5
|
+
end
|
6
|
+
|
7
|
+
def load_environment
|
8
|
+
puts
|
9
|
+
puts "Loading Rails environment..."
|
10
|
+
time = Benchmark.realtime do
|
11
|
+
begin
|
12
|
+
# Ruby environment loading is shamelessly borrowed from spork
|
13
|
+
ENV["RAILS_ENV"] ||= "test"
|
14
|
+
$:.unshift("./test")
|
15
|
+
|
16
|
+
require 'rake'
|
17
|
+
Rake.application.init
|
18
|
+
Rake.application.load_rakefile
|
19
|
+
Rake.application.invoke_task("test:prepare")
|
20
|
+
rescue Exception => e
|
21
|
+
puts "Error: Loading your environment failed."
|
22
|
+
puts " #{e.message}"
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "Environment loaded in #{time}s."
|
28
|
+
puts
|
29
|
+
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
|
33
|
+
def run_tests(globs)
|
34
|
+
time = Benchmark.realtime do
|
35
|
+
pid = fork do
|
36
|
+
|
37
|
+
puts "Running tests..."
|
38
|
+
puts
|
39
|
+
|
40
|
+
paths = []
|
41
|
+
globs.each do |glob|
|
42
|
+
paths.concat(Dir.glob(glob))
|
43
|
+
end
|
44
|
+
|
45
|
+
paths.each do |path|
|
46
|
+
require File.realpath(path)
|
47
|
+
end
|
48
|
+
|
49
|
+
if defined? ActiveRecord
|
50
|
+
ActiveRecord::Base.connection.reconnect!
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Process.wait2(pid)
|
55
|
+
end
|
56
|
+
|
57
|
+
puts
|
58
|
+
puts "Test time (including load): #{time}s"
|
59
|
+
puts
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/tconsole/version.rb
CHANGED
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: 0.0.
|
4
|
+
version: 0.0.3.pre
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: tconsole gives you a helpful console for running Rails tests
|
15
15
|
email:
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- bin/tconsole
|
27
27
|
- lib/tconsole.rb
|
28
|
+
- lib/tconsole/server.rb
|
28
29
|
- lib/tconsole/version.rb
|
29
30
|
- tconsole.gemspec
|
30
31
|
homepage: ''
|