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
#bundle, #cmd, #console, #db, #flag, #generate, #irb, #issue, #log, #note, #omit, #overview, #popen3, #rails, #rails_epoc, #rake, #restart_server, #ruby, #runner, #secinclude, #secsplit, #section, #section_head, stop_server, #test, #unbundle
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
144
145
146
|
# File 'lib/gorp/test.rb', line 144
def raw
@raw
end
|
Class Method Details
.herald(instance, name) ⇒ Object
59
60
|
# File 'lib/gorp/test.rb', line 59
def self.herald instance, name
end
|
read and pre-process $input.html (only done once, and cached)
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/gorp/test.rb', line 93
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
124
125
126
127
|
# File 'lib/gorp/test.rb', line 124
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/gorp/test.rb', line 63
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
158
159
160
|
# File 'lib/gorp/test.rb', line 158
def self.sections
@@sections
end
|
.suite ⇒ Object
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/gorp/test.rb', line 10
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 'rails-dom-testing'
include Rails::Dom::Testing::Assertions::SelectorAssertions
ActiveSupport.test_order = :random rescue nil
rescue LoadError
require 'action_dispatch/testing/assertions'
require 'action_dispatch/testing/assertions/selector'
include ActionDispatch::Assertions::SelectorAssertions
begin
require 'action_controller/vendor/html-scanner/html/tokenizer'
require 'action_controller/vendor/html-scanner/html/document'
rescue LoadError
require 'action_view/vendor/html-scanner/html/tokenizer'
require 'action_view/vendor/html-scanner/html/document'
end
end
super
end
|
.test(name, &block) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/gorp/test.rb', line 52
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
146
147
148
149
150
|
# File 'lib/gorp/test.rb', line 146
def collect_stdout
css_select('.stdout').map do |tag|
tag.children.join.gsub('<','<').gsub('>','>')
end
end
|
#parse_for_select(raw) ⇒ Object
129
130
131
132
133
134
135
|
# File 'lib/gorp/test.rb', line 129
def parse_for_select raw
if defined? Rails::Dom::Testing::Assertions::SelectorAssertions
Nokogiri::HTML::DocumentFragment.parse(raw)
else
HTML::Document.new(raw).root.children
end
end
|
#select(number) ⇒ Object
select an individual section from the HTML
138
139
140
141
142
|
# File 'lib/gorp/test.rb', line 138
def select number
raise "Section #{number} not found" unless @@sections.has_key? number.to_s
@raw = @@sections[number.to_s]
@selected = parse_for_select @raw
end
|
#sort_hash(line) ⇒ Object
152
153
154
155
156
|
# File 'lib/gorp/test.rb', line 152
def sort_hash line
line.sub(/^(=> )?\{.*\}$/) do |match|
"#{$1}{#{match.scan(/:?"?\w+"?=>[^\[].*?(?=, |\})/).sort.join(', ')}}"
end
end
|
#ticket(number, info) ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/gorp/test.rb', line 83
def ticket number, info
return if Gorp::Config[:ignore_tickets]
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
|