tconsole 1.0.1pre5 → 1.1.0pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/tconsole.rb +5 -2
- data/lib/tconsole/minitest_handler.rb +50 -2
- data/lib/tconsole/server.rb +51 -3
- data/lib/tconsole/test_result.rb +27 -0
- data/lib/tconsole/version.rb +1 -1
- metadata +3 -5
data/lib/tconsole.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "tconsole/version"
|
2
2
|
require "tconsole/server"
|
3
|
+
require "tconsole/test_result"
|
3
4
|
|
4
5
|
require "readline"
|
5
6
|
require "benchmark"
|
@@ -36,7 +37,7 @@ module TConsole
|
|
36
37
|
|
37
38
|
# A little welcome
|
38
39
|
puts
|
39
|
-
puts "Welcome to tconsole. Type 'help' for help or 'exit' to quit."
|
40
|
+
puts "Welcome to tconsole (v#{TConsole::VERSION}). Type 'help' for help or 'exit' to quit."
|
40
41
|
|
41
42
|
# Set up our console input handling and history
|
42
43
|
console = Console.new
|
@@ -133,6 +134,8 @@ module TConsole
|
|
133
134
|
server.run_uncommitted(args[1])
|
134
135
|
elsif args[0] == "all"
|
135
136
|
server.run_tests(["test/unit/**/*_test.rb", "test/functional/**/*_test.rb", "test/integration/**/*_test.rb"], args[1])
|
137
|
+
elsif args[0] == "!failed"
|
138
|
+
server.run_failed
|
136
139
|
elsif args[0] == "info"
|
137
140
|
server.run_info
|
138
141
|
else
|
@@ -154,11 +157,11 @@ module TConsole
|
|
154
157
|
puts "integration [test_pattern] # Run integration tests"
|
155
158
|
puts "recent [test_pattern] # Run tests for recently changed files"
|
156
159
|
puts "uncommitted [test_pattern] # Run tests for uncommitted changes"
|
160
|
+
puts "!failed # Runs the last set of failing tests"
|
157
161
|
puts "[filename] [test_pattern] # Run the tests contained in the given file"
|
158
162
|
puts "reload # Reload your Rails environment"
|
159
163
|
puts "exit # Exit the console"
|
160
164
|
puts
|
161
|
-
puts
|
162
165
|
puts "Working with test patterns:"
|
163
166
|
puts
|
164
167
|
puts "All of the test execution commands include an optional test_pattern argument. A"
|
@@ -6,9 +6,21 @@ module TConsole
|
|
6
6
|
args = ["--name", name_pattern]
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
# Make sure we have a recent version of minitest, and use it
|
10
|
+
if ::MiniTest::Unit.respond_to?(:runner=)
|
11
|
+
::MiniTest::Unit.runner = TConsole::MiniTestUnit.new
|
12
|
+
else
|
13
|
+
raise "MiniTest v#{MiniTest::Unit::VERSION} is not compatible with tconsole. Please load a more recent version of MiniTest"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Run it
|
17
|
+
runner = MiniTest::Unit.runner
|
18
|
+
runner.run(args)
|
10
19
|
|
20
|
+
# Make sure that minitest doesn't run automatically when the process exits
|
11
21
|
patch_minitest
|
22
|
+
|
23
|
+
runner.results
|
12
24
|
end
|
13
25
|
|
14
26
|
# We're basically breaking MiniTest autorun here, since we want to manually run our
|
@@ -18,7 +30,7 @@ module TConsole
|
|
18
30
|
# rather than rebuilding all of the code in Rake just to get test prep happening
|
19
31
|
# correctly.
|
20
32
|
def self.patch_minitest
|
21
|
-
MiniTest::Unit.class_eval do
|
33
|
+
::MiniTest::Unit.class_eval do
|
22
34
|
alias_method :old_run, :run
|
23
35
|
def run(args = [])
|
24
36
|
# do nothing
|
@@ -26,4 +38,40 @@ module TConsole
|
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
41
|
+
|
42
|
+
# Custom minitest runner for tconsole
|
43
|
+
class MiniTestUnit < ::MiniTest::Unit
|
44
|
+
attr_accessor :results
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
self.results = TConsole::TestResult.new
|
48
|
+
|
49
|
+
super
|
50
|
+
end
|
51
|
+
|
52
|
+
def puke(klass, meth, e)
|
53
|
+
e = case e
|
54
|
+
when MiniTest::Skip then
|
55
|
+
@skips += 1
|
56
|
+
results.skips += 1
|
57
|
+
return "S" unless @verbose
|
58
|
+
"Skipped:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
|
59
|
+
when MiniTest::Assertion then
|
60
|
+
@failures += 1
|
61
|
+
results.failures += 1
|
62
|
+
results.append_failure_details(klass, meth)
|
63
|
+
"Failure:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
|
64
|
+
else
|
65
|
+
@errors += 1
|
66
|
+
results.errors += 1
|
67
|
+
results.append_failure_details(klass, meth)
|
68
|
+
bt = MiniTest::filter_backtrace(e.backtrace).join "\n "
|
69
|
+
"Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n #{bt}\n"
|
70
|
+
end
|
71
|
+
@report << e
|
72
|
+
e[0, 1]
|
73
|
+
end
|
74
|
+
end
|
29
75
|
end
|
76
|
+
|
77
|
+
|
data/lib/tconsole/server.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module TConsole
|
2
2
|
class Server
|
3
|
-
attr_accessor :config
|
3
|
+
attr_accessor :config, :last_result
|
4
4
|
|
5
5
|
def initialize(config)
|
6
6
|
self.config = config
|
7
|
+
self.last_result = TConsole::TestResult.new
|
7
8
|
end
|
8
9
|
|
9
10
|
def stop
|
@@ -48,7 +49,11 @@ module TConsole
|
|
48
49
|
|
49
50
|
def run_tests(globs, name_pattern, message = "Running tests...")
|
50
51
|
time = Benchmark.realtime do
|
52
|
+
# Pipe for communicating with child so we can get its results back
|
53
|
+
read, write = IO.pipe
|
54
|
+
|
51
55
|
fork do
|
56
|
+
read.close
|
52
57
|
|
53
58
|
puts message
|
54
59
|
puts
|
@@ -63,13 +68,17 @@ module TConsole
|
|
63
68
|
end
|
64
69
|
|
65
70
|
if defined? ::ActiveRecord
|
66
|
-
::ActiveRecord::Base.
|
71
|
+
::ActiveRecord::Base.clear_active_connections!
|
72
|
+
::ActiveRecord::Base.establish_connection
|
67
73
|
end
|
68
74
|
|
69
75
|
if defined?(::MiniTest)
|
70
76
|
require File.join(File.dirname(__FILE__), "minitest_handler")
|
71
77
|
|
72
|
-
MiniTestHandler.run(name_pattern)
|
78
|
+
result = MiniTestHandler.run(name_pattern)
|
79
|
+
|
80
|
+
write.puts([Marshal.dump(result)].pack("m"))
|
81
|
+
|
73
82
|
elsif defined?(::Test::Unit)
|
74
83
|
puts "Sorry, but tconsole doesn't support Test::Unit yet"
|
75
84
|
return
|
@@ -79,6 +88,17 @@ module TConsole
|
|
79
88
|
end
|
80
89
|
end
|
81
90
|
|
91
|
+
write.close
|
92
|
+
response = read.read
|
93
|
+
begin
|
94
|
+
self.last_result = Marshal.load(response.unpack("m")[0])
|
95
|
+
rescue
|
96
|
+
# Just in case anything crazy goes down with marshalling
|
97
|
+
self.last_result = TConsole::TestResult.new
|
98
|
+
end
|
99
|
+
|
100
|
+
read.close
|
101
|
+
|
82
102
|
Process.waitall
|
83
103
|
end
|
84
104
|
|
@@ -97,6 +117,15 @@ module TConsole
|
|
97
117
|
run_tests(files, test_pattern, message)
|
98
118
|
end
|
99
119
|
|
120
|
+
def run_failed
|
121
|
+
# TODO: We probably shouldn't use built in Rails methods here if we can help it
|
122
|
+
file_names = last_result.failure_details.map { |detail| filenameify(detail[:class]) }
|
123
|
+
files_to_rerun = []
|
124
|
+
|
125
|
+
files_to_rerun << file_names.map {|file| (file.match(/controller/)) ? "test/functional/#{file}.rb" : "test/unit/#{file}.rb"}
|
126
|
+
run_tests(files_to_rerun, nil, "Running last failed tests: #{files_to_rerun.join(", ")}")
|
127
|
+
end
|
128
|
+
|
100
129
|
def recent_files(touched_since, source_pattern, test_path)
|
101
130
|
Dir.glob(source_pattern).map do |path|
|
102
131
|
if File.mtime(path) > touched_since
|
@@ -149,5 +178,24 @@ module TConsole
|
|
149
178
|
puts
|
150
179
|
puts
|
151
180
|
end
|
181
|
+
|
182
|
+
def filenameify(klass_name)
|
183
|
+
result = ""
|
184
|
+
first = true
|
185
|
+
klass_name.chars do |char|
|
186
|
+
new = char.downcase!
|
187
|
+
if new.nil?
|
188
|
+
result << char
|
189
|
+
elsif first
|
190
|
+
result << new
|
191
|
+
else
|
192
|
+
result << "_#{new}"
|
193
|
+
end
|
194
|
+
|
195
|
+
first = false
|
196
|
+
end
|
197
|
+
|
198
|
+
result
|
199
|
+
end
|
152
200
|
end
|
153
201
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module TConsole
|
2
|
+
class TestResult
|
3
|
+
# The number of failed tests in the last run
|
4
|
+
attr_accessor :failures
|
5
|
+
|
6
|
+
# The number of errors that occurred in the last run
|
7
|
+
attr_accessor :errors
|
8
|
+
|
9
|
+
# The number of skipped tests
|
10
|
+
attr_accessor :skips
|
11
|
+
|
12
|
+
# Details about the failures in the last run
|
13
|
+
attr_accessor :failure_details
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
self.failures = 0
|
17
|
+
self.errors = 0
|
18
|
+
self.skips = 0
|
19
|
+
self.failure_details = []
|
20
|
+
end
|
21
|
+
|
22
|
+
# Adds to the failure details that we know about
|
23
|
+
def append_failure_details(klass, meth)
|
24
|
+
failure_details << { :class => klass.to_s, :method => meth.to_s }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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: 1.
|
4
|
+
version: 1.1.0pre1
|
5
5
|
prerelease: 5
|
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: 2012-
|
12
|
+
date: 2012-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! " tconsole allows Rails developers to easily and quickly run their
|
15
15
|
tests as a whole or in subsets. It forks the testing processes from\n a preloaded
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- lib/tconsole.rb
|
32
32
|
- lib/tconsole/minitest_handler.rb
|
33
33
|
- lib/tconsole/server.rb
|
34
|
+
- lib/tconsole/test_result.rb
|
34
35
|
- lib/tconsole/version.rb
|
35
36
|
- tconsole.gemspec
|
36
37
|
homepage: ''
|
@@ -45,9 +46,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
46
|
- - ! '>='
|
46
47
|
- !ruby/object:Gem::Version
|
47
48
|
version: '0'
|
48
|
-
segments:
|
49
|
-
- 0
|
50
|
-
hash: 3424980306917930953
|
51
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
50
|
none: false
|
53
51
|
requirements:
|