tconsole 1.1.0pre11 → 1.1.0pre12
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/Gemfile +2 -1
- data/Rakefile +7 -0
- data/lib/tconsole.rb +20 -1
- data/lib/tconsole/config.rb +41 -4
- data/lib/tconsole/console.rb +11 -11
- data/lib/tconsole/minitest_handler.rb +35 -10
- data/lib/tconsole/server.rb +39 -56
- data/lib/tconsole/version.rb +1 -1
- data/tconsole.gemspec +1 -0
- data/test/config_test.rb +69 -1
- data/test/sample_config +3 -0
- data/test/test_helper.rb +7 -0
- metadata +19 -4
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/tconsole.rb
CHANGED
@@ -28,9 +28,18 @@ module TConsole
|
|
28
28
|
puts "Welcome to tconsole (v#{TConsole::VERSION}). Type 'help' for help or 'exit' to quit."
|
29
29
|
|
30
30
|
# set up the config
|
31
|
+
Config.load_config(File.join(Dir.home, ".tconsole"))
|
32
|
+
Config.load_config(File.join(Dir.pwd, ".tconsole"))
|
31
33
|
config = Config.configure
|
32
34
|
config.trace_execution = true if argv.include?("--trace")
|
33
35
|
|
36
|
+
config_errors = config.validation_errors
|
37
|
+
if config_errors.length > 0
|
38
|
+
puts
|
39
|
+
puts config_errors.first
|
40
|
+
exit(1)
|
41
|
+
end
|
42
|
+
|
34
43
|
# Set up our console input handling and history
|
35
44
|
console = Console.new(config)
|
36
45
|
|
@@ -49,7 +58,17 @@ module TConsole
|
|
49
58
|
|
50
59
|
while message = pipe_server.read
|
51
60
|
config.trace("Server Received Message: #{message[:action]}")
|
52
|
-
|
61
|
+
begin
|
62
|
+
result = server.handle(message)
|
63
|
+
pipe_server.write(result)
|
64
|
+
rescue => e
|
65
|
+
puts
|
66
|
+
puts "An error occured: #{e.message}"
|
67
|
+
config.trace("===========")
|
68
|
+
config.trace(e.backtrace.join("\n"))
|
69
|
+
config.trace("===========")
|
70
|
+
pipe_server.write(nil)
|
71
|
+
end
|
53
72
|
end
|
54
73
|
|
55
74
|
rescue Interrupt
|
data/lib/tconsole/config.rb
CHANGED
@@ -91,10 +91,44 @@ module TConsole
|
|
91
91
|
self.cached_elements = result.elements
|
92
92
|
end
|
93
93
|
|
94
|
+
# Returns true if this config is valid or false otherwise
|
95
|
+
def validation_errors
|
96
|
+
errors = []
|
97
|
+
|
98
|
+
unless Dir.exists?(test_dir)
|
99
|
+
errors << "Couldn't find test directory `#{test_dir}`. Exiting."
|
100
|
+
end
|
101
|
+
|
102
|
+
unless file_sets.is_a?(Hash) && !file_sets["all"].nil?
|
103
|
+
errors << "No `all` file set is defined in your configuration. Exiting."
|
104
|
+
end
|
105
|
+
|
106
|
+
errors
|
107
|
+
end
|
108
|
+
|
109
|
+
# Loads up a config file
|
110
|
+
def self.load_config(path)
|
111
|
+
if File.exist?(path)
|
112
|
+
load path
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Saves a configuration block that we can apply to the configuration once it's
|
117
|
+
# loaded
|
118
|
+
def self.run(&block)
|
119
|
+
@loaded_configs ||= []
|
120
|
+
@loaded_configs << block
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.clear_loaded_configs
|
124
|
+
@loaded_configs = nil
|
125
|
+
end
|
126
|
+
|
94
127
|
# Returns an appropriate tconsole config based on the environment
|
95
128
|
def self.configure
|
129
|
+
config = Config.new
|
130
|
+
|
96
131
|
if is_rails?
|
97
|
-
config = Config.new
|
98
132
|
config.preload_paths = ["./config/application"]
|
99
133
|
config.include_paths = ["./test"]
|
100
134
|
config.file_sets = {
|
@@ -127,11 +161,14 @@ module TConsole
|
|
127
161
|
::ActiveRecord::Base.establish_connection
|
128
162
|
end
|
129
163
|
end
|
164
|
+
end
|
130
165
|
|
131
|
-
|
132
|
-
|
133
|
-
|
166
|
+
@loaded_configs ||= []
|
167
|
+
@loaded_configs.each do |block|
|
168
|
+
block.call(config)
|
134
169
|
end
|
170
|
+
|
171
|
+
config
|
135
172
|
end
|
136
173
|
|
137
174
|
def self.is_rails?
|
data/lib/tconsole/console.rb
CHANGED
@@ -21,7 +21,7 @@ module TConsole
|
|
21
21
|
|
22
22
|
known_elements = []
|
23
23
|
unless pipe_server.nil?
|
24
|
-
known_elements =
|
24
|
+
known_elements = send_message(:autocomplete, str)
|
25
25
|
end
|
26
26
|
|
27
27
|
known_commands.concat(known_elements)
|
@@ -47,34 +47,34 @@ module TConsole
|
|
47
47
|
if line == ""
|
48
48
|
# do nothing
|
49
49
|
elsif args[0] == "exit"
|
50
|
-
|
50
|
+
send_message(:stop)
|
51
51
|
self.pipe_server = nil
|
52
52
|
return false
|
53
53
|
elsif args[0] == "reload"
|
54
|
-
|
54
|
+
send_message(:stop)
|
55
55
|
return true
|
56
56
|
elsif args[0] == "help"
|
57
57
|
print_help
|
58
58
|
elsif args[0] == "!failed"
|
59
|
-
|
59
|
+
send_message(:run_failed)
|
60
60
|
elsif args[0] == "!timings"
|
61
|
-
|
61
|
+
send_message(:show_performance, args[1])
|
62
62
|
elsif args[0] == "info"
|
63
|
-
|
63
|
+
send_message(:run_info)
|
64
64
|
elsif args[0] == "set"
|
65
|
-
|
65
|
+
send_message(:set, args[1], args[2])
|
66
66
|
elsif @config.file_sets.has_key?(args[0])
|
67
|
-
|
67
|
+
send_message(:run_file_set, args[0])
|
68
68
|
else
|
69
|
-
|
69
|
+
send_message(:run_all_tests, args)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
true
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
77
|
-
pipe_server.write(message)
|
76
|
+
def send_message(message, *args)
|
77
|
+
pipe_server.write({:action => message.to_sym, :args => args})
|
78
78
|
pipe_server.read
|
79
79
|
end
|
80
80
|
|
@@ -9,7 +9,7 @@ module TConsole
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# Run it
|
12
|
-
runner = MiniTest::Unit.runner
|
12
|
+
runner = ::MiniTest::Unit.runner
|
13
13
|
runner.run
|
14
14
|
|
15
15
|
# Make sure that minitest doesn't run automatically when the process exits
|
@@ -60,7 +60,7 @@ module TConsole
|
|
60
60
|
"P" => ::Term::ANSIColor.green
|
61
61
|
}
|
62
62
|
|
63
|
-
attr_accessor :match_patterns, :config, :results
|
63
|
+
attr_accessor :match_patterns, :config, :results, :passes
|
64
64
|
|
65
65
|
def initialize(match_patterns, config)
|
66
66
|
self.match_patterns = match_patterns
|
@@ -69,10 +69,15 @@ module TConsole
|
|
69
69
|
self.config = config
|
70
70
|
self.results = TConsole::TestResult.new
|
71
71
|
|
72
|
+
self.passes = 0
|
73
|
+
|
72
74
|
results.suite_counts = config.cached_suite_counts
|
73
75
|
results.elements = config.cached_elements
|
74
76
|
|
75
77
|
super()
|
78
|
+
|
79
|
+
# We do this since plugins like turn may have tweaked it
|
80
|
+
@@out = $stdout
|
76
81
|
end
|
77
82
|
|
78
83
|
def _run_anything(type)
|
@@ -109,8 +114,25 @@ module TConsole
|
|
109
114
|
end
|
110
115
|
|
111
116
|
def status(io = self.output)
|
112
|
-
format = "%d tests, %d assertions,
|
113
|
-
|
117
|
+
format = "%d tests, %d assertions, "
|
118
|
+
|
119
|
+
format << COLOR_MAP["P"] if passes > 0
|
120
|
+
format << "%d passes, "
|
121
|
+
format << ::Term::ANSIColor.reset if passes > 0
|
122
|
+
|
123
|
+
format << COLOR_MAP["F"] if failures > 0
|
124
|
+
format << "%d failures, "
|
125
|
+
format << ::Term::ANSIColor.reset if failures > 0
|
126
|
+
|
127
|
+
format << COLOR_MAP["E"] if errors > 0
|
128
|
+
format << "%d errors, "
|
129
|
+
format << ::Term::ANSIColor.reset if errors > 0
|
130
|
+
|
131
|
+
format << COLOR_MAP["S"] if skips > 0
|
132
|
+
format << "%d skips"
|
133
|
+
format << ::Term::ANSIColor.reset if skips > 0
|
134
|
+
|
135
|
+
io.puts format % [test_count, assertion_count, passes, failures, errors, skips]
|
114
136
|
end
|
115
137
|
|
116
138
|
def _run_suite(suite, type)
|
@@ -154,7 +176,10 @@ module TConsole
|
|
154
176
|
time = Time.now - @start_time
|
155
177
|
results.add_timing(suite, method, time)
|
156
178
|
|
157
|
-
|
179
|
+
if result == "."
|
180
|
+
result = "P"
|
181
|
+
self.passes += 1
|
182
|
+
end
|
158
183
|
|
159
184
|
results.failures << id unless result == "P"
|
160
185
|
|
@@ -184,19 +209,19 @@ module TConsole
|
|
184
209
|
@skips += 1
|
185
210
|
results.skip_count += 1
|
186
211
|
return "S" unless @verbose
|
187
|
-
"Skipped:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
|
212
|
+
["S", COLOR_MAP["S"] + "Skipped:\n#{meth}(#{klass})" + ::Term::ANSIColor.reset + " [#{location e}]:\n#{e.message}\n"]
|
188
213
|
when MiniTest::Assertion then
|
189
214
|
@failures += 1
|
190
215
|
results.failure_count += 1
|
191
|
-
"Failure:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
|
216
|
+
["F", COLOR_MAP["F"] + "Failure:\n#{meth}(#{klass})" + ::Term::ANSIColor.reset + " [#{location e}]:\n#{e.message}\n"]
|
192
217
|
else
|
193
218
|
@errors += 1
|
194
219
|
results.error_count += 1
|
195
220
|
bt = MiniTest::filter_backtrace(e.backtrace).join "\n "
|
196
|
-
"Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n #{bt}\n"
|
221
|
+
["E", COLOR_MAP["E"] + "Error:\n#{meth}(#{klass}):\n" + ::Term::ANSIColor.reset + "#{e.class}: #{e.message}\n #{bt}\n"]
|
197
222
|
end
|
198
|
-
@report << e
|
199
|
-
e[0
|
223
|
+
@report << e[1]
|
224
|
+
e[0]
|
200
225
|
end
|
201
226
|
end
|
202
227
|
end
|
data/lib/tconsole/server.rb
CHANGED
@@ -10,25 +10,32 @@ module TConsole
|
|
10
10
|
# Processes the message sent from the console
|
11
11
|
def handle(message)
|
12
12
|
action = message[:action]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
args = message[:args]
|
14
|
+
|
15
|
+
send(action, *args)
|
16
|
+
# if action == "load_environment"
|
17
|
+
# load_environment
|
18
|
+
# elsif action == "run_failed"
|
19
|
+
# run_failed
|
20
|
+
# elsif action == "show_performance"
|
21
|
+
# show_performance(message[:limit])
|
22
|
+
# elsif action == "run_info"
|
23
|
+
# run_info
|
24
|
+
# elsif action == "set"
|
25
|
+
# set(message[:var], message[:value])
|
26
|
+
# elsif action == "run_file_set"
|
27
|
+
# run_file_set(message[:set])
|
28
|
+
# elsif action == "run_all_tests"
|
29
|
+
# run_all_tests(message[:args])
|
30
|
+
# elsif action == "autocomplete"
|
31
|
+
# autocomplete(message[:text])
|
32
|
+
# elsif action == "exit"
|
33
|
+
# exit(0)
|
34
|
+
# end
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop
|
38
|
+
Kernel.exit(0)
|
32
39
|
end
|
33
40
|
|
34
41
|
def load_environment
|
@@ -228,48 +235,24 @@ module TConsole
|
|
228
235
|
|
229
236
|
def set(key, value)
|
230
237
|
if key == "fast"
|
231
|
-
value.
|
232
|
-
|
233
|
-
|
238
|
+
if !value.nil?
|
239
|
+
value.downcase!
|
240
|
+
if ["on", "true", "yes"].include?(value)
|
241
|
+
config.fail_fast = true
|
242
|
+
else
|
243
|
+
config.fail_fast = false
|
244
|
+
end
|
245
|
+
|
246
|
+
puts ::Term::ANSIColor.green + "Fail Fast is now #{config.fail_fast ? "on" : "off"}" + ::Term::ANSIColor.reset
|
247
|
+
puts
|
234
248
|
else
|
235
|
-
config.fail_fast
|
249
|
+
puts ::Term::ANSIColor.green + "Fail fast is currently #{config.fail_fast ? "on" : "off"}" + ::Term::ANSIColor.reset
|
250
|
+
puts
|
236
251
|
end
|
237
|
-
|
238
|
-
puts "Fail Fast is now #{config.fail_fast ? "on" : "off"}"
|
239
|
-
puts
|
240
252
|
else
|
241
|
-
puts "
|
253
|
+
puts ::Term::ANSIColor.yellow + "I don't know how to set `#{key}`." + ::Term::ANSIColor.reset + " Usage: set {key} {value}"
|
242
254
|
puts
|
243
255
|
end
|
244
256
|
end
|
245
|
-
|
246
|
-
def filenameify(klass_name)
|
247
|
-
result = ""
|
248
|
-
first = true
|
249
|
-
klass_name.chars do |char|
|
250
|
-
new = char.downcase!
|
251
|
-
if new.nil?
|
252
|
-
result << char
|
253
|
-
elsif first
|
254
|
-
result << new
|
255
|
-
else
|
256
|
-
result << "_#{new}"
|
257
|
-
end
|
258
|
-
|
259
|
-
first = false
|
260
|
-
end
|
261
|
-
|
262
|
-
result
|
263
|
-
end
|
264
|
-
|
265
|
-
# Totally yanked from the Rails test tasks
|
266
|
-
def silence_stderr
|
267
|
-
old_stderr = STDERR.dup
|
268
|
-
STDERR.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
|
269
|
-
STDERR.sync = true
|
270
|
-
yield
|
271
|
-
ensure
|
272
|
-
STDERR.reopen(old_stderr)
|
273
|
-
end
|
274
257
|
end
|
275
258
|
end
|
data/lib/tconsole/version.rb
CHANGED
data/tconsole.gemspec
CHANGED
data/test/config_test.rb
CHANGED
@@ -1,3 +1,71 @@
|
|
1
|
-
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
+
module TConsole
|
4
|
+
class ConfigTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
a "Config" do
|
7
|
+
setup do
|
8
|
+
@config = TConsole::Config.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have appropriate defaults" do
|
12
|
+
assert_equal false, @config.trace_execution
|
13
|
+
assert_equal "./test", @config.test_dir
|
14
|
+
assert_equal ["./test", "./lib"], @config.include_paths
|
15
|
+
assert_equal [], @config.preload_paths
|
16
|
+
assert_equal false, @config.fail_fast
|
17
|
+
assert_equal({ "all" => ["./test/**/*_test.rb"] }, @config.file_sets)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a validation error if the configured test directory doesn't exist" do
|
21
|
+
@config.test_dir = "./monkey_business"
|
22
|
+
|
23
|
+
errors = @config.validation_errors
|
24
|
+
refute_nil errors
|
25
|
+
assert_equal "Couldn't find test directory `./monkey_business`. Exiting.", errors[0]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have a validation error if the configuration doesn't include an all file set" do
|
29
|
+
@config.file_sets = {}
|
30
|
+
|
31
|
+
errors = @config.validation_errors
|
32
|
+
refute_nil errors
|
33
|
+
assert_equal "No `all` file set is defined in your configuration. Exiting.", errors[0]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
the "Config class" do
|
38
|
+
setup do
|
39
|
+
TConsole::Config.clear_loaded_configs
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should save the proc passed to run when it's called" do
|
43
|
+
TConsole::Config.run do |config|
|
44
|
+
config.test_dir = "./awesome_sauce"
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_equal 1, TConsole::Config.instance_variable_get(:@loaded_configs).length
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should apply the loaded configs from first to last when configure is called" do
|
51
|
+
TConsole::Config.run do |config|
|
52
|
+
config.test_dir = "./awesome_sauce"
|
53
|
+
end
|
54
|
+
|
55
|
+
TConsole::Config.run do |config|
|
56
|
+
config.test_dir = "./awesomer_sauce"
|
57
|
+
end
|
58
|
+
|
59
|
+
config = TConsole::Config.configure
|
60
|
+
|
61
|
+
assert_equal "./awesomer_sauce", config.test_dir
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should load a config file when load_config is called" do
|
65
|
+
TConsole::Config.load_config(File.join(File.dirname(__FILE__), "sample_config"))
|
66
|
+
|
67
|
+
assert_equal 1, TConsole::Config.instance_variable_get(:@loaded_configs).length
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
3
71
|
end
|
data/test/sample_config
ADDED
data/test/test_helper.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.0pre12
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70138167691280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,18 @@ dependencies:
|
|
21
21
|
version: 1.0.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70138167691280
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &70138167690780 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.11.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70138167690780
|
25
36
|
description: ! " tconsole allows Rails developers to easily and quickly run their
|
26
37
|
tests as a whole or in subsets. It forks the testing processes from\n a preloaded
|
27
38
|
test environment to ensure that developers don't have to reload their entire Rails
|
@@ -50,6 +61,8 @@ files:
|
|
50
61
|
- lib/tconsole/version.rb
|
51
62
|
- tconsole.gemspec
|
52
63
|
- test/config_test.rb
|
64
|
+
- test/sample_config
|
65
|
+
- test/test_helper.rb
|
53
66
|
homepage: ''
|
54
67
|
licenses: []
|
55
68
|
post_install_message:
|
@@ -76,3 +89,5 @@ specification_version: 3
|
|
76
89
|
summary: tconsole is a helpful console for running Rails tests
|
77
90
|
test_files:
|
78
91
|
- test/config_test.rb
|
92
|
+
- test/sample_config
|
93
|
+
- test/test_helper.rb
|