Class: Gorp::TestCase
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- Gorp::TestCase
show all
- Includes:
- Commands
- Defined in:
- lib/gorp/test.rb
Constant Summary
collapse
- @@base =
Object.new.extend(Gorp::Commands)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Commands
#cmd, #console, #db, #generate, #head, #irb, #issue, #log, #note, #omit, #overview, #popen3, #rails, #rake, #restart_server, #ruby, #runner, #secinclude, #secsplit, #section, stop_server
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
120
121
122
|
# File 'lib/gorp/test.rb', line 120
def raw
@raw
end
|
Class Method Details
.herald(instance, name) ⇒ Object
44
45
|
# File 'lib/gorp/test.rb', line 44
def self.herald instance, name
end
|
read and pre-process $input.html (only done once, and cached)
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/gorp/test.rb', line 77
def self.input filename
input = open(File.join($WORK, "#{filename}.html")).read
input.force_encoding('utf-8') if input.respond_to? :force_encoding
head, body, tail = input.split /<body>\s+|\s+<\/body>/m
body.gsub! /<a (id="[-.\w]+") (class="\w+")>/,'<a \2 \1>'
@@sections = body.split(/<a class="toc" id="section-(.*?)">/)
@@sections[-1], env = @@sections.last.split(/<a class="toc" id="env">/)
env, todos = env.split(/<a class="toc" id="todos">/)
@@omit = body.split(/<a class="omit" id="section-(.*?)">/)
@@sections = Hash[*@@sections.unshift(:contents)]
@@sections[:head] = head
@@sections[:todos] = todos
@@sections[:env] = env
@@sections[:tail] = tail
@@sections.each do |key,value|
next unless key =~ /^\d/
@@sections[key] = "<a class=\"toc\" id=\"section-#{key}\">#{value}"
end
end
|
.output(filename) ⇒ Object
108
109
110
111
|
# File 'lib/gorp/test.rb', line 108
def self.output filename
$output = filename
at_exit { HTMLRunner.run(self) }
end
|
.section(number, title, &tests) ⇒ Object
micro DSL allowing the definition of optional tests
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/gorp/test.rb', line 48
def self.section number, title, &tests
number = (sprintf "%f", number).sub(/0+$/,'') if number.kind_of? Float
return if @@omit.include? number.to_s
test "#{number} #{title}" do
instance_eval {select number}
begin
instance_eval &tests
ensure
unless $!.instance_of? RuntimeError
@raw =~ /<pre\sclass="stdin">edit\s([\w\/.]+)<\/pre>\s+
<pre\sclass="traceback">\s+
\#<IndexError:\sregexp\snot\smatched>\s+
(.*gorp\/lib\/gorp\/edit.rb.*\n\s+)*
([\w\/.]+:\d+)/x
fail "Edit #{$1} failed at #{$3}" if $1
end
end
end
end
|
.sections ⇒ Object
134
135
136
|
# File 'lib/gorp/test.rb', line 134
def self.sections
@@sections
end
|
.suite ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/gorp/test.rb', line 9
def self.suite
if File.exist? "#{$WORK}/.bundle/environment.rb"
require "#{$WORK}/.bundle/environment.rb"
end
require 'active_support'
require 'active_support/version'
require 'active_support/test_case'
require 'action_controller'
begin
require 'action_controller/assertions/selector_assertions'
include ActionController::Assertions::SelectorAssertions
rescue LoadError
require 'action_dispatch/testing/assertions'
require 'action_dispatch/testing/assertions/selector'
include ActionDispatch::Assertions::SelectorAssertions
end
require 'action_controller/vendor/html-scanner/html/tokenizer'
require 'action_controller/vendor/html-scanner/html/document'
super
end
|
.test(name, &block) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/gorp/test.rb', line 37
def self.test(name, &block)
define_method("test_#{name.gsub(/\s+/,'_')}".to_sym) do
self.class.herald self, name
instance_eval &block
end
end
|
Instance Method Details
#collect_stdout ⇒ Object
122
123
124
125
126
|
# File 'lib/gorp/test.rb', line 122
def collect_stdout
css_select('.stdout').map do |tag|
tag.children.join.gsub('<','<').gsub('>','>')
end
end
|
#select(number) ⇒ Object
select an individual section from the HTML
114
115
116
117
118
|
# File 'lib/gorp/test.rb', line 114
def select number
raise "Section #{number} not found" unless @@sections.has_key? number.to_s
@raw = @@sections[number.to_s]
@selected = HTML::Document.new(@raw).root.children
end
|
#sort_hash(line) ⇒ Object
128
129
130
131
132
|
# File 'lib/gorp/test.rb', line 128
def sort_hash line
line.sub(/^(=> )?\{.*\}$/) do |match|
"#{$1}{#{match.scan(/:?"?\w+"?=>[^\[].*?(?=, |\})/).sort.join(', ')}}"
end
end
|
#ticket(number, info) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/gorp/test.rb', line 68
def ticket number, info
return if info[:match] and not @raw =~ info[:match]
return if block_given? and not yield(@raw)
info[:list] ||= :rails
fail "Ticket #{info[:list]}:#{number}: #{info[:title]}"
end
|