quick_test_runner 0.0.2 → 0.0.3
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/quick_test_runner.rb +150 -149
- data/lib/quick_test_runner/version.rb +1 -1
- metadata +2 -2
data/lib/quick_test_runner.rb
CHANGED
@@ -3,184 +3,185 @@ require 'test/unit/ui/console/testrunner'
|
|
3
3
|
#module QuickTestRunner
|
4
4
|
# Your code goes here...
|
5
5
|
#end
|
6
|
-
|
7
|
-
# TODO: run tests that failed the last time
|
8
|
-
# TODO: figure out how to reload helpers
|
9
|
-
# TODO: get functional tests to work
|
10
|
-
# TODO: blueprints don't get updated
|
11
|
-
# TODO: reports2_test doesn't seem to work the second time around
|
12
|
-
class
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.readme
|
25
|
-
puts ""
|
26
|
-
puts " **************************************************************************** "
|
27
|
-
puts " * * "
|
28
|
-
puts " * Type tr.help to see all available commands for the Quick Test Runner * "
|
29
|
-
puts " * * "
|
30
|
-
puts " * * "
|
31
|
-
puts " * NOTE that you will need to restart console if you: * "
|
32
|
-
puts " * * "
|
33
|
-
puts " * 1. modify helper implementation code * "
|
34
|
-
puts " * * "
|
35
|
-
puts " * 2. modify blueprint code * "
|
36
|
-
puts " * * "
|
37
|
-
puts " **************************************************************************** "
|
38
|
-
puts ""
|
39
|
-
end
|
40
|
-
|
41
|
-
def help
|
42
|
-
console_puts "Quick Test Runner Help"
|
43
|
-
puts " run 'path', 'keyword' : runs the tests filtered by keyword of test path"
|
44
|
-
puts " path does not need the '_test' appended"
|
45
|
-
puts " example: tr.run 'helper/jobs_helper', 'search'"
|
46
|
-
puts ""
|
47
|
-
puts " run 'path' : runs the tests filtered by keyword of test path"
|
48
|
-
puts " example: tr.run 'vendor'"
|
49
|
-
puts ""
|
50
|
-
puts " run number : rerun a test from the buffer - use tr.list to see buffer"
|
51
|
-
puts " example: tr.run 2"
|
52
|
-
puts ""
|
53
|
-
puts " run : rerun the last test"
|
54
|
-
puts " example: tr.run"
|
55
|
-
puts ""
|
56
|
-
puts " run_suite 'path' : run all tests in a suite specified by the path"
|
57
|
-
puts " example: tr.run_suite 'vendor'"
|
58
|
-
puts ""
|
59
|
-
puts " run_test 'keyword' : runs the tests filtered to keyword of a previously specified test suite (use tr.run_suite or tr.run to set the suite)"
|
60
|
-
puts " example: tr.run_test 'search'"
|
61
|
-
puts ""
|
62
|
-
puts " list : list buffer of previous run tests"
|
63
|
-
puts " example: tr.list"
|
64
|
-
puts ""
|
65
|
-
puts " Feel free too look at /test/test_runner.rb and offer improvements, suggestions or complaints!"
|
66
|
-
puts ""
|
67
|
-
end
|
68
|
-
|
69
|
-
def run tp=nil, tn=nil, opts={}
|
70
|
-
if tp.is_a? Integer
|
71
|
-
rerun tp
|
72
|
-
return
|
6
|
+
module QuickTestRunner
|
7
|
+
# TODO: run tests that failed the last time
|
8
|
+
# TODO: figure out how to reload helpers
|
9
|
+
# TODO: get functional tests to work
|
10
|
+
# TODO: blueprints don't get updated
|
11
|
+
# TODO: reports2_test doesn't seem to work the second time around
|
12
|
+
class Runner
|
13
|
+
attr_accessor :test_path, :test_name, :options
|
14
|
+
attr_accessor :klass, :test_names
|
15
|
+
attr_accessor :test_buffer
|
16
|
+
|
17
|
+
def initialize args={}
|
18
|
+
self.test_path = args[:test_path]
|
19
|
+
self.test_name = args[:test_name]
|
20
|
+
self.test_buffer = []
|
21
|
+
self.options = args[:options] || {}
|
73
22
|
end
|
74
23
|
|
75
|
-
|
76
|
-
|
77
|
-
|
24
|
+
def self.readme
|
25
|
+
puts ""
|
26
|
+
puts " **************************************************************************** "
|
27
|
+
puts " * * "
|
28
|
+
puts " * Type tr.help to see all available commands for the Quick Test Runner * "
|
29
|
+
puts " * * "
|
30
|
+
puts " * * "
|
31
|
+
puts " * NOTE that you will need to restart console if you: * "
|
32
|
+
puts " * * "
|
33
|
+
puts " * 1. modify helper implementation code * "
|
34
|
+
puts " * * "
|
35
|
+
puts " * 2. modify blueprint code * "
|
36
|
+
puts " * * "
|
37
|
+
puts " **************************************************************************** "
|
38
|
+
puts ""
|
78
39
|
end
|
79
40
|
|
80
|
-
|
81
|
-
|
82
|
-
|
41
|
+
def help
|
42
|
+
console_puts "Quick Test Runner Help"
|
43
|
+
puts " run 'path', 'keyword' : runs the tests filtered by keyword of test path"
|
44
|
+
puts " path does not need the '_test' appended"
|
45
|
+
puts " example: tr.run 'helper/jobs_helper', 'search'"
|
46
|
+
puts ""
|
47
|
+
puts " run 'path' : runs the tests filtered by keyword of test path"
|
48
|
+
puts " example: tr.run 'vendor'"
|
49
|
+
puts ""
|
50
|
+
puts " run number : rerun a test from the buffer - use tr.list to see buffer"
|
51
|
+
puts " example: tr.run 2"
|
52
|
+
puts ""
|
53
|
+
puts " run : rerun the last test"
|
54
|
+
puts " example: tr.run"
|
55
|
+
puts ""
|
56
|
+
puts " run_suite 'path' : run all tests in a suite specified by the path"
|
57
|
+
puts " example: tr.run_suite 'vendor'"
|
58
|
+
puts ""
|
59
|
+
puts " run_test 'keyword' : runs the tests filtered to keyword of a previously specified test suite (use tr.run_suite or tr.run to set the suite)"
|
60
|
+
puts " example: tr.run_test 'search'"
|
61
|
+
puts ""
|
62
|
+
puts " list : list buffer of previous run tests"
|
63
|
+
puts " example: tr.list"
|
64
|
+
puts ""
|
65
|
+
puts " Feel free too look at /test/test_runner.rb and offer improvements, suggestions or complaints!"
|
66
|
+
puts ""
|
67
|
+
end
|
83
68
|
|
84
|
-
|
85
|
-
|
69
|
+
def run tp=nil, tn=nil, opts={}
|
70
|
+
if tp.is_a? Integer
|
71
|
+
rerun tp
|
72
|
+
return
|
73
|
+
end
|
86
74
|
|
87
|
-
|
88
|
-
|
89
|
-
|
75
|
+
if tn.nil? and not tp.nil?
|
76
|
+
run_suite tp
|
77
|
+
return
|
78
|
+
end
|
90
79
|
|
91
|
-
|
92
|
-
|
80
|
+
self.test_path = tp ? tp : self.test_path
|
81
|
+
self.test_name = tn ? tn : self.test_name
|
82
|
+
self.options = opts
|
93
83
|
|
94
|
-
|
95
|
-
|
84
|
+
internal_run
|
85
|
+
end
|
96
86
|
|
97
|
-
|
98
|
-
|
87
|
+
def run_suite tp=nil
|
88
|
+
self.test_path = tp ? tp : self.test_path
|
89
|
+
self.test_name = nil
|
99
90
|
|
100
|
-
|
101
|
-
self.test_buffer.each_with_index do |test_entry, i|
|
102
|
-
txt = "#{i+1}. #{test_entry[0]}"
|
103
|
-
txt << " - #{test_entry[1]}" if test_entry[1]
|
104
|
-
puts txt
|
91
|
+
internal_run
|
105
92
|
end
|
106
|
-
puts ""
|
107
|
-
end
|
108
93
|
|
109
|
-
|
110
|
-
|
111
|
-
return unless self.klass
|
94
|
+
def run_test tn
|
95
|
+
self.test_name = tn
|
112
96
|
|
113
|
-
|
114
|
-
self.klass.send(:remove_method, tn.to_sym)
|
97
|
+
internal_run
|
115
98
|
end
|
116
99
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
100
|
+
def list
|
101
|
+
self.test_buffer.each_with_index do |test_entry, i|
|
102
|
+
txt = "#{i+1}. #{test_entry[0]}"
|
103
|
+
txt << " - #{test_entry[1]}" if test_entry[1]
|
104
|
+
puts txt
|
105
|
+
end
|
106
|
+
puts ""
|
107
|
+
end
|
121
108
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
self.test_name = self.test_buffer[number-1][1]
|
126
|
-
internal_run
|
127
|
-
end
|
109
|
+
# necessary to "undef" test methods so that we can reload them again (via load "test/unit...") so that any changes made to the test file get through
|
110
|
+
def clean verbose=true
|
111
|
+
return unless self.klass
|
128
112
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
113
|
+
self.test_names.each do |tn|
|
114
|
+
self.klass.send(:remove_method, tn.to_sym)
|
115
|
+
end
|
133
116
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
117
|
+
self.klass = nil
|
118
|
+
self.test_names = nil
|
119
|
+
console_puts "Successfully cleaned test names" if verbose
|
120
|
+
end
|
139
121
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
122
|
+
private
|
123
|
+
def rerun number
|
124
|
+
self.test_path = self.test_buffer[number-1][0]
|
125
|
+
self.test_name = self.test_buffer[number-1][1]
|
126
|
+
internal_run
|
144
127
|
end
|
145
128
|
|
146
|
-
|
147
|
-
|
148
|
-
|
129
|
+
def add_to_buffer path, name
|
130
|
+
self.test_buffer << [self.test_path, self.test_name]
|
131
|
+
self.test_buffer.uniq!
|
132
|
+
end
|
149
133
|
|
150
|
-
|
151
|
-
"
|
152
|
-
|
153
|
-
"
|
134
|
+
def console_puts text
|
135
|
+
puts ""
|
136
|
+
puts " *** #{text} *** "
|
137
|
+
puts ""
|
154
138
|
end
|
155
139
|
|
156
|
-
|
140
|
+
def internal_run
|
141
|
+
if self.test_path.nil?
|
142
|
+
console_puts "ERROR: a test path needs to be specified"
|
143
|
+
return
|
144
|
+
end
|
145
|
+
|
146
|
+
# reload needs to be done before load otherwise can't load the unit tests that are nested in modules/folders
|
147
|
+
reload!
|
148
|
+
load "test/unit/#{self.test_path}_test.rb"
|
149
|
+
|
150
|
+
self.klass = begin
|
151
|
+
"#{self.test_path.split('/').last.camelize}Test".constantize
|
152
|
+
rescue NameError
|
153
|
+
"#{self.test_path.camelize}Test".constantize
|
154
|
+
end
|
157
155
|
|
158
|
-
|
159
|
-
console_puts "Running tests filtered by '#{self.test_name}' keyword in #{self.klass} suite." unless self.test_name.blank?
|
156
|
+
suite = Test::Unit::TestSuite.new(self.klass.to_s)
|
160
157
|
|
161
|
-
|
162
|
-
|
158
|
+
console_puts "Running all tests in #{self.klass} suite." if self.test_name.blank?
|
159
|
+
console_puts "Running tests filtered by '#{self.test_name}' keyword in #{self.klass} suite." unless self.test_name.blank?
|
163
160
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
161
|
+
self.test_names = self.klass.suite.tests.collect {|t| t.method_name}
|
162
|
+
add_to_buffer self.test_path, self.test_name
|
163
|
+
|
164
|
+
begin
|
165
|
+
if self.test_name
|
166
|
+
self.test_names.each do |t|
|
167
|
+
suite << self.klass.new(t) if t.include?(self.test_name)
|
168
|
+
end
|
169
|
+
else
|
170
|
+
suite << self.klass.suite
|
168
171
|
end
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
172
|
+
runner = Test::Unit::UI::Console::TestRunner.new(suite)
|
173
|
+
runner.start
|
174
|
+
|
175
|
+
if test_name
|
176
|
+
puts "\n\nTests ran: "
|
177
|
+
suite.tests.each {|t| puts " #{t.method_name}"}
|
178
|
+
""
|
179
|
+
else
|
180
|
+
""
|
181
|
+
end
|
182
|
+
ensure
|
183
|
+
clean false
|
181
184
|
end
|
182
|
-
ensure
|
183
|
-
clean false
|
184
185
|
end
|
185
186
|
end
|
186
187
|
end
|