Class: Splot::TestUnitCommand
Constant Summary
collapse
- ACTIVE_SUPPORT_TEST_CASE_MATCHER =
%r{
\A\s*test\s+ # test
(?: #
"(?<double_quote>.*)" # "it should work"
| # OR
'(?<single_quote>.*)' # 'it should work'
) #
\s+do\s*\Z # do\n
}x
- TEST_UNIT_MATCHER =
%r{
\A\s*def\s+ # def
(?<test_name> #
test_ # test_
[a-zA-Z_]+ # it_should_work
[\?!=]? # ?
) #
\s*\Z # \n
}x
Instance Attribute Summary
Attributes inherited from Command
#file, #include_path, #line_no, #preloader
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
#command, for, #include_args
Constructor Details
Returns a new instance of TestUnitCommand.
97
98
99
100
|
# File 'lib/splot/command.rb', line 97
def initialize(params = {})
@runner = params.fetch(:runner) { "rake test" }
super
end
|
Class Method Details
.match?(file) ⇒ Boolean
102
103
104
|
# File 'lib/splot/command.rb', line 102
def self.match?(file)
file.match /\_test\.rb/
end
|
Instance Method Details
#fetch_test_name ⇒ Object
129
130
131
132
133
134
135
136
|
# File 'lib/splot/command.rb', line 129
def fetch_test_name
return nil if line_no.nil?
current_test_name = nil
read_file do |current_line_no, line|
match_test_method(line) { |match| current_test_name = match }
throw :test_name, current_test_name if current_line_no == line_no
end
end
|
#file_arg ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/splot/command.rb', line 106
def file_arg
if rake?
"TEST=#{file}"
else
super
end
end
|
#line_no_arg ⇒ Object
122
123
124
125
126
127
|
# File 'lib/splot/command.rb', line 122
def line_no_arg
test_name = catch(:test_name) { fetch_test_name }
return nil if test_name.nil?
arg = "--name=#{test_name}"
rake? ? "TESTOPTS=#{arg.inspect}" : arg
end
|
#match_active_support(line) ⇒ Object
143
144
145
146
147
148
|
# File 'lib/splot/command.rb', line 143
def match_active_support(line)
line.match ACTIVE_SUPPORT_TEST_CASE_MATCHER do |matches|
quoted_bit = matches[:double_quote] || matches[:single_quote]
yield "test_#{quoted_bit.gsub(/\s+/, '_')}"
end
end
|
#match_test_method(line, &block) ⇒ Object
138
139
140
141
|
# File 'lib/splot/command.rb', line 138
def match_test_method(line, &block)
match_active_support line, &block
match_test_unit line, &block
end
|
#match_test_unit(line) ⇒ Object
150
151
152
153
154
|
# File 'lib/splot/command.rb', line 150
def match_test_unit(line)
line.match TEST_UNIT_MATCHER do |matches|
yield matches[:test_name]
end
end
|
#rake? ⇒ Boolean
114
115
116
|
# File 'lib/splot/command.rb', line 114
def rake?
runner == "rake test"
end
|
#read_file ⇒ Object
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/splot/command.rb', line 156
def read_file
current_line_no = 0
File.open file do |io|
until io.eof?
current_line_no += 1
line_text = io.gets
yield current_line_no, line_text
end
end
end
|
#runner ⇒ Object
118
119
120
|
# File 'lib/splot/command.rb', line 118
def runner
@runner
end
|