Class: Fit::Fixture
- Inherits:
-
Object
show all
- Defined in:
- lib/fit/fixture.rb
Direct Known Subclasses
Eg::AllFiles, Eg::Book::ChatServerActions, Eg::Music::Browser, Eg::Music::Dialog, Eg::Net::Simulator, Fat::Table, ActionFixture, ColumnFixture, ImportFixture, PrimitiveFixture, Summary, Fitlibrary::CommentFixture, Fitlibrary::Spec::SpecifyFixture
Constant Summary
collapse
- GREEN =
'#cfffcf'
- RED =
'#ffcfcf'
- GRAY =
'#efefef'
- YELLOW =
'#ffffcf'
- @@metadata =
{}
- @@loader =
FixtureLoader.new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Fixture.
68
69
70
71
72
73
|
# File 'lib/fit/fixture.rb', line 68
def initialize
@summary = {}
@counts = Counts.new
@listener = FixtureListener.new
@args = []
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
66
67
68
|
# File 'lib/fit/fixture.rb', line 66
def args
@args
end
|
#counts ⇒ Object
Returns the value of attribute counts.
66
67
68
|
# File 'lib/fit/fixture.rb', line 66
def counts
@counts
end
|
#listener ⇒ Object
Returns the value of attribute listener.
66
67
68
|
# File 'lib/fit/fixture.rb', line 66
def listener
@listener
end
|
#summary ⇒ Object
Returns the value of attribute summary.
66
67
68
|
# File 'lib/fit/fixture.rb', line 66
def summary
@summary
end
|
Class Method Details
.camel(name) ⇒ Object
Originally, this method built the name of a Java method from multiple, space-separated, downcased words, morphing them into a single camelcased word. Ruby just needs those words to be joined with an underscore. For historical reasons, this method still maintains its original name.
268
269
270
|
# File 'lib/fit/fixture.rb', line 268
def Fixture.camel name
name.gsub(/ /, '_')
end
|
.escape(s) ⇒ Object
258
259
260
261
262
|
# File 'lib/fit/fixture.rb', line 258
def Fixture.escape s
str = s.gsub(/&/, '&').gsub(/</, '<').gsub(/ /, ' ')
str.gsub(/\r\n/, '<br />').gsub(/\r/, '<br />').gsub(/\n/, '<br />')
end
|
.gray(s) ⇒ Object
254
255
256
|
# File 'lib/fit/fixture.rb', line 254
def Fixture.gray s
' <font color="#808080">' + s + '</font>'
end
|
.label(s) ⇒ Object
250
251
252
|
# File 'lib/fit/fixture.rb', line 250
def Fixture.label s
' <font size=-1 color="#c08080"><i>' + s + '</i></font>'
end
|
62
|
# File 'lib/fit/fixture.rb', line 62
def Fixture.metadata; @@metadata; end
|
Instance Method Details
#check(cell, adapter) ⇒ Object
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/fit/fixture.rb', line 282
def check cell, adapter
text = cell.text
if text.empty?
begin
info cell, adapter.to_s(adapter.get)
rescue Exception
info cell, 'error'
end
elsif adapter.nil?
ignore cell
elsif text == 'error'
begin
result = adapter.invoke wrong cell, adapter.to_s(result)
rescue Exception => e
right cell end
else
begin
result = adapter.get
if adapter.equals(adapter.parse(text), result)
right cell
else
wrong cell, adapter.to_s(result)
end
rescue Exception => e
exception cell, e
end
end
end
|
#do_cell(cell, column_number) ⇒ Object
193
194
195
|
# File 'lib/fit/fixture.rb', line 193
def do_cell cell, column_number
ignore cell
end
|
#do_cells(cells) ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/fit/fixture.rb', line 180
def do_cells cells
i = 0
until cells.nil?
begin
do_cell cells, i
rescue Exception => e
exception cells, e
end
cells = cells.more
i += 1
end
end
|
#do_row(row) ⇒ Object
176
177
178
|
# File 'lib/fit/fixture.rb', line 176
def do_row row
do_cells row.parts
end
|
#do_rows(rows) ⇒ Object
168
169
170
171
172
173
174
|
# File 'lib/fit/fixture.rb', line 168
def do_rows rows
until rows.nil?
more = rows.more
do_row rows
rows = more
end
end
|
#do_table(table) ⇒ Object
164
165
166
|
# File 'lib/fit/fixture.rb', line 164
def do_table table
do_rows table.parts.more
end
|
#do_tables(tables) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/fit/fixture.rb', line 85
def do_tables tables
@summary['run date'] = Time.now.to_s
@summary['run elapsed time'] = RunTime.new
unless tables.nil?
fixture_name = fixture_name tables
unless fixture_name.nil?
begin
fixture = get_linked_fixture_with_args tables
fixture.interpret_tables tables
rescue Exception => e
exception fixture_name, e
@listener.table_finished(tables)
interpret_following_tables tables
end
end
end
@listener.tables_finished(@counts)
end
|
#error(cell, message) ⇒ Object
235
236
237
238
239
240
|
# File 'lib/fit/fixture.rb', line 235
def error cell, message
cell.body = Fixture.escape(cell.text)
cell.add_to_body('<hr><pre>' + Fixture.escape(message) + '</pre>')
cell.add_to_tag(' bgcolor="' + YELLOW + '"')
@counts.exceptions += 1
end
|
#exception(cell, e) ⇒ Object
222
223
224
225
226
227
228
|
# File 'lib/fit/fixture.rb', line 222
def exception cell, e
stacktrace = e.backtrace.join "\n"
message = e.message.gsub(/>/, '>').gsub(/</, '<')
cell.add_to_body "<hr><font size=-2><pre>#{message}\n#{stacktrace}</pre></font>"
cell.add_to_tag(' bgcolor="' + YELLOW + '"')
@counts.exceptions += 1
end
|
#find_class(class_name) ⇒ Object
81
82
83
|
# File 'lib/fit/fixture.rb', line 81
def find_class class_name
@@loader.find_fixture_class class_name
end
|
#fixture_name(tables) ⇒ Object
160
161
162
|
# File 'lib/fit/fixture.rb', line 160
def fixture_name tables
tables.at 0, 0, 0
end
|
#get_args_for_table(table) ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/fit/fixture.rb', line 150
def get_args_for_table table
arg = table.parts.parts.more
args = []
while arg
args << arg.text
arg = arg.more
end
@args = args
end
|
#get_linked_fixture_with_args(tables) ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/fit/fixture.rb', line 134
def get_linked_fixture_with_args tables
= fixture_name tables
unless .nil?
begin
fixture = (find_class .text).new fixture.summary = @summary
fixture.counts = @counts
fixture.listener = @listener
fixture.get_args_for_table tables
return fixture
rescue Exception => e
exception , e
end
end
end
|
#ignore(cell) ⇒ Object
217
218
219
220
|
# File 'lib/fit/fixture.rb', line 217
def ignore cell
cell.add_to_tag(' bgcolor="' + GRAY + '"')
@counts.ignores += 1
end
|
#info(cell, message) ⇒ Object
230
231
232
233
|
# File 'lib/fit/fixture.rb', line 230
def info cell, message
string = ' <font color="#808080">' + Fixture.escape(message) + '</font>'
cell.add_to_body string
end
|
#interpret_following_tables(tables) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/fit/fixture.rb', line 117
def interpret_following_tables tables
tables = tables.more
until tables.nil?
fixture_name = fixture_name(tables)
unless fixture_name.nil?
begin
fixture = get_linked_fixture_with_args tables
fixture.do_table tables
rescue Exception => e
exception fixture_name, e
end
end
@listener.table_finished(tables)
tables = tables.more
end
end
|
#interpret_tables(tables) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/fit/fixture.rb', line 104
def interpret_tables tables
begin
get_args_for_table(tables) do_table tables
rescue Exception => e
exception fixture_name(tables), e
return
end
@listener.table_finished(tables)
interpret_following_tables tables
end
|
#parse(string, klass) ⇒ Object
272
273
274
275
276
277
278
279
280
|
# File 'lib/fit/fixture.rb', line 272
def parse string, klass
if klass == Date
d = Date._parse string
return [d[:year], d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:zone], d[:wday]]
end
return ScientificDouble.value_of(string) if klass == ScientificDouble
return string if klass == String
nil
end
|
#right(cell) ⇒ Object
203
204
205
206
|
# File 'lib/fit/fixture.rb', line 203
def right cell
cell.add_to_tag(' bgcolor="' + GREEN + '"')
@counts.right += 1
end
|
#total_errors ⇒ Object
75
76
77
|
# File 'lib/fit/fixture.rb', line 75
def total_errors
@counts.total_errors
end
|
#totals ⇒ Object
This method was originally called counts, but the name has been changed to avoid shadowing the counts accessor attribute.
246
247
248
|
# File 'lib/fit/fixture.rb', line 246
def totals
@counts.to_s
end
|
#wrong(cell, actual = nil) ⇒ Object
208
209
210
211
212
213
214
215
|
# File 'lib/fit/fixture.rb', line 208
def wrong cell, actual = nil
cell.add_to_tag(' bgcolor="' + RED + '"')
cell.body = Fixture.escape(cell.text)
@counts.wrong += 1
unless actual.nil?
cell.add_to_body(Fixture.label('expected') + '<hr>' + Fixture.escape(actual) + Fixture.label('actual'))
end
end
|