test_console 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -1
- data/lib/action_view/resolver.rb +5 -1
- data/lib/test_console/config.rb +14 -2
- data/lib/test_console/output.rb +11 -0
- data/lib/test_console/runner.rb +21 -2
- data/lib/test_console/utility.rb +33 -4
- data/lib/test_console/version.rb +1 -1
- data/test/dummy/log/test.log +37 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
1
|
= TestConsole
|
2
2
|
|
3
|
-
|
3
|
+
Interactive console for running TestUnit tests against a Rails application.
|
4
|
+
|
5
|
+
Please note : This console was written specifically to aid with testing a specific application and so has only been tested in a small number of environments. Please report any issues via the [Github issues](https://github.com/adamphillips/test_console/issues) page.
|
6
|
+
|
7
|
+
For more information see
|
8
|
+
|
9
|
+
https://github.com/adamphillips/test_console
|
data/lib/action_view/resolver.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# In order to be able to run our tests with cache_classes enabled, we need to be able to control when our views are reloaded.
|
2
|
+
# Otherwise view changes won't take effect in our console
|
3
|
+
# This sets ActionView to use our custom test when checking whether to cache view templates meaning that we can use this function to expire the view cache as necessary.
|
2
4
|
module ActionView
|
3
5
|
class Resolver
|
6
|
+
|
7
|
+
# Wether to cache view templates
|
4
8
|
def caching?
|
5
9
|
@caching = TestConsole.views_changed?
|
6
10
|
end
|
data/lib/test_console/config.rb
CHANGED
@@ -3,11 +3,20 @@ module TestConsole
|
|
3
3
|
yield Config
|
4
4
|
end
|
5
5
|
|
6
|
+
# Returns an array of commands for the specfied function.
|
7
|
+
# Valid commands are:
|
8
|
+
#
|
9
|
+
# :run
|
10
|
+
# :rerun
|
11
|
+
# :quit
|
12
|
+
# :help
|
13
|
+
#
|
6
14
|
def self.commands(type)
|
7
15
|
command = "#{type}_commands".to_sym # Deliberately not to_s-ing to avoid :
|
8
16
|
TestConsole::Config.send(command) if TestConsole::Config.respond_to?(command)
|
9
17
|
end
|
10
18
|
|
19
|
+
# Configuration options for the test console.
|
11
20
|
module Config
|
12
21
|
|
13
22
|
# Folders to watch
|
@@ -23,6 +32,9 @@ module TestConsole
|
|
23
32
|
mattr_accessor :stop_folders
|
24
33
|
@@stop_folders = ['test/fixtures', 'config/environments']
|
25
34
|
|
35
|
+
# These folders are dropped from class paths when determining a class from a filename
|
36
|
+
mattr_accessor :drop_folders
|
37
|
+
@@drop_folders = ['test', 'unit', 'functional', 'helpers', 'integration']
|
26
38
|
|
27
39
|
# CLI Commands
|
28
40
|
#
|
@@ -62,11 +74,11 @@ module TestConsole
|
|
62
74
|
@@backtrace_local_color = @@error_color
|
63
75
|
@@backtrace_gem_color = :magenta
|
64
76
|
|
65
|
-
#
|
77
|
+
# Failed test runs
|
66
78
|
mattr_accessor :fail_color
|
67
79
|
@@fail_color = :magenta
|
68
80
|
|
69
|
-
#
|
81
|
+
# Successful test runs
|
70
82
|
mattr_accessor :success_color
|
71
83
|
@@success_color = :green
|
72
84
|
|
data/lib/test_console/output.rb
CHANGED
@@ -9,6 +9,14 @@ module TestConsole
|
|
9
9
|
# =================
|
10
10
|
# Functions to format and display output
|
11
11
|
|
12
|
+
# Writes content out to the terminal
|
13
|
+
# Use Hirb to format tables.
|
14
|
+
# Can specify a color using one of the defined color constants
|
15
|
+
#
|
16
|
+
# Examples
|
17
|
+
#
|
18
|
+
# out 'some_text', :blue # Prints out the text in blue
|
19
|
+
#
|
12
20
|
def out(text, text_color=nil, *opts)
|
13
21
|
extend Hirb::Console
|
14
22
|
text = text.to_a if text.kind_of? ActiveRecord::Base
|
@@ -24,6 +32,8 @@ module TestConsole
|
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
35
|
+
# Puts out an error.
|
36
|
+
# The error is written to STDERR and colored in the error color.
|
27
37
|
def error(message, backtrace=nil)
|
28
38
|
STDERR.puts color(message, error_color)
|
29
39
|
backtrace.each {|line| line_color = (line[0..1] == '/') ? backtrace_local_color : backtrace_gem_color; STDERR.puts color(line, line_color)} unless backtrace.nil? || backtrace.empty?
|
@@ -37,6 +47,7 @@ module TestConsole
|
|
37
47
|
end
|
38
48
|
end
|
39
49
|
|
50
|
+
# Outputs a summary of the results
|
40
51
|
def print_result_summary(result, time_taken=0)
|
41
52
|
if result.failure_count == 0 && result.error_count == 0
|
42
53
|
final_color = success_color
|
data/lib/test_console/runner.rb
CHANGED
@@ -3,8 +3,16 @@ module TestConsole
|
|
3
3
|
include TestConsole::Colors
|
4
4
|
include TestConsole::Config
|
5
5
|
|
6
|
-
# Checks that the specified path is valid
|
7
|
-
# If so it creates a test suite from the path and runs it
|
6
|
+
# Checks that the specified path is valid.
|
7
|
+
# If so it creates a test suite from the path and runs it.
|
8
|
+
# If a filter is passed as a string or regex, individual test names are filtered by the expression.
|
9
|
+
#
|
10
|
+
# Examples:
|
11
|
+
#
|
12
|
+
# run './unit' # Run every test in the unit folder
|
13
|
+
# run './unit/a_model_test.rb' # Run the specific test file
|
14
|
+
# run './unit', 'update' # Run every test in the unit folder that has update in the test name
|
15
|
+
# run './unit/a_model_test.rb' /update/i # Run every test in specified file whose name contains a case-insensitve version of 'update'
|
8
16
|
def run path, filter=nil
|
9
17
|
begin
|
10
18
|
unless path && !path.empty?
|
@@ -36,6 +44,14 @@ module TestConsole
|
|
36
44
|
end
|
37
45
|
|
38
46
|
# Reruns previous failures or errors
|
47
|
+
# Can either just run errors or failures
|
48
|
+
#
|
49
|
+
# Examples:
|
50
|
+
#
|
51
|
+
# rerun # Rerun everything
|
52
|
+
# rerun :errors # Rerun errors
|
53
|
+
# rerun :failures # Rerun failures
|
54
|
+
#
|
39
55
|
def rerun type=nil
|
40
56
|
return false unless @last_run_path
|
41
57
|
|
@@ -66,6 +82,7 @@ module TestConsole
|
|
66
82
|
end
|
67
83
|
|
68
84
|
# Runs a defined suite of tests
|
85
|
+
# Outputs the results
|
69
86
|
def run_suite(suite)
|
70
87
|
@abort = false
|
71
88
|
@running = true
|
@@ -107,6 +124,8 @@ module TestConsole
|
|
107
124
|
@last_run_time = Time.now
|
108
125
|
end
|
109
126
|
|
127
|
+
# If there is a test suite running, the run is aborted
|
128
|
+
# Otherwise the console is killed
|
110
129
|
def abort
|
111
130
|
(@running) ? @abort = true : die
|
112
131
|
end
|
data/lib/test_console/utility.rb
CHANGED
@@ -4,9 +4,17 @@ module TestConsole
|
|
4
4
|
base.extend(ClassMethods)
|
5
5
|
end
|
6
6
|
|
7
|
+
# Returns an array of class components from a filename
|
8
|
+
#
|
9
|
+
# Common folder names are dropped from the array to avoid confusion.
|
10
|
+
#
|
11
|
+
# Examples:
|
12
|
+
#
|
13
|
+
# class_from_filename module/controller # ['Module', 'Controller']
|
14
|
+
# class_from_filename unit/module/controller # ['Module', 'Controller']
|
15
|
+
# class_from_filename parent/module/controller # ['Parent', 'Module', 'Controller']
|
16
|
+
#
|
7
17
|
module ClassMethods
|
8
|
-
## Returns an array of class components from a filename
|
9
|
-
## eg for module/controller => ['Module', 'Controller']
|
10
18
|
def class_from_filename(filename)
|
11
19
|
segs = filename.split('/')
|
12
20
|
segs.delete ''
|
@@ -14,13 +22,20 @@ module TestConsole
|
|
14
22
|
segs.last.gsub!('.rb', '')
|
15
23
|
|
16
24
|
# drop the test folder
|
17
|
-
segs = segs[1..-1] while segs[0]
|
18
|
-
segs = segs[1..-1] while ['unit', 'functional', 'helpers', 'integration'].include?(segs[0])
|
25
|
+
segs = segs[1..-1] while TestConsole.drop_folders.include?(segs[0])
|
19
26
|
ret = segs.map {|seg| seg.camelize}
|
20
27
|
|
21
28
|
return ret
|
22
29
|
end
|
23
30
|
|
31
|
+
# Returns boolean as to wether the specified constant is defined.
|
32
|
+
#
|
33
|
+
# Examples:
|
34
|
+
#
|
35
|
+
# const_defined? 'String' # true
|
36
|
+
# const_defined? 'WierdClass' # false
|
37
|
+
# const_defined? ['ActiveRecord', 'Base'] # true (assuming Active Record is installed)
|
38
|
+
#
|
24
39
|
def const_defined?(klass)
|
25
40
|
klass = [klass] unless klass.kind_of? Array
|
26
41
|
klass.inject(Object) do |context, scope|
|
@@ -32,6 +47,13 @@ module TestConsole
|
|
32
47
|
end
|
33
48
|
end
|
34
49
|
|
50
|
+
# Returns the specified class.
|
51
|
+
#
|
52
|
+
# Examples:
|
53
|
+
#
|
54
|
+
# const_get 'String' # String
|
55
|
+
# const_get ['ActiveRecord', 'Base'] # ActiveRecord::Base
|
56
|
+
#
|
35
57
|
def const_get(klass)
|
36
58
|
klass = [klass] unless klass.kind_of? Array
|
37
59
|
klass.inject(Object) do |context, scope|
|
@@ -39,6 +61,13 @@ module TestConsole
|
|
39
61
|
end
|
40
62
|
end
|
41
63
|
|
64
|
+
# Removes the specified class.
|
65
|
+
#
|
66
|
+
# Examples:
|
67
|
+
#
|
68
|
+
# const_get 'String' # String
|
69
|
+
# const_get ['ActiveRecord', 'Base'] # ActiveRecord::Base
|
70
|
+
#
|
42
71
|
def const_remove(klass)
|
43
72
|
klass = [klass] unless klass.kind_of? Array
|
44
73
|
if klass.length > 1
|
data/lib/test_console/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -1738,3 +1738,40 @@ Connecting to database specified by database.yml
|
|
1738
1738
|
[1m[35m (0.0ms)[0m rollback transaction
|
1739
1739
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1740
1740
|
[1m[35m (0.0ms)[0m rollback transaction
|
1741
|
+
Connecting to database specified by database.yml
|
1742
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1743
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1744
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1745
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1746
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1747
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1748
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1749
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1750
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1751
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1752
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1753
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1754
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1755
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1756
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1757
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1758
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1759
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1760
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1761
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1762
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1763
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1764
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1765
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1766
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1767
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1768
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1769
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1770
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1771
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1772
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1773
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1774
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1775
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
1776
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
1777
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Phillips
|