quick_test_runner 0.0.1 → 0.0.2
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 +184 -1
- data/lib/quick_test_runner/version.rb +1 -1
- metadata +2 -2
data/lib/quick_test_runner.rb
CHANGED
|
@@ -1,3 +1,186 @@
|
|
|
1
|
-
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'test/unit/ui/console/testrunner'
|
|
3
|
+
#module QuickTestRunner
|
|
2
4
|
# Your code goes here...
|
|
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 QuickTestRunner
|
|
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] || {}
|
|
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
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
if tn.nil? and not tp.nil?
|
|
76
|
+
run_suite tp
|
|
77
|
+
return
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
self.test_path = tp ? tp : self.test_path
|
|
81
|
+
self.test_name = tn ? tn : self.test_name
|
|
82
|
+
self.options = opts
|
|
83
|
+
|
|
84
|
+
internal_run
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def run_suite tp=nil
|
|
88
|
+
self.test_path = tp ? tp : self.test_path
|
|
89
|
+
self.test_name = nil
|
|
90
|
+
|
|
91
|
+
internal_run
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def run_test tn
|
|
95
|
+
self.test_name = tn
|
|
96
|
+
|
|
97
|
+
internal_run
|
|
98
|
+
end
|
|
99
|
+
|
|
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
|
|
108
|
+
|
|
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
|
|
112
|
+
|
|
113
|
+
self.test_names.each do |tn|
|
|
114
|
+
self.klass.send(:remove_method, tn.to_sym)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
self.klass = nil
|
|
118
|
+
self.test_names = nil
|
|
119
|
+
console_puts "Successfully cleaned test names" if verbose
|
|
120
|
+
end
|
|
121
|
+
|
|
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
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def add_to_buffer path, name
|
|
130
|
+
self.test_buffer << [self.test_path, self.test_name]
|
|
131
|
+
self.test_buffer.uniq!
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def console_puts text
|
|
135
|
+
puts ""
|
|
136
|
+
puts " *** #{text} *** "
|
|
137
|
+
puts ""
|
|
138
|
+
end
|
|
139
|
+
|
|
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
|
|
155
|
+
|
|
156
|
+
suite = Test::Unit::TestSuite.new(self.klass.to_s)
|
|
157
|
+
|
|
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?
|
|
160
|
+
|
|
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
|
|
171
|
+
end
|
|
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
|
|
184
|
+
end
|
|
185
|
+
end
|
|
3
186
|
end
|