Class: Fitlibrary::Spec::SpecifyFixture
Overview
Uses embedded tables to specify how fixtures work, based on simple subclasses of those fixtures. The test and the report can be in two separate rows, or in a single row.
Constant Summary
Constants inherited
from Fit::Fixture
Fit::Fixture::GRAY, Fit::Fixture::GREEN, Fit::Fixture::RED, Fit::Fixture::YELLOW
Instance Attribute Summary
Attributes inherited from Fit::Fixture
#args, #counts, #listener, #summary
Instance Method Summary
collapse
-
#add_table_to_better_show_differences(table, actual, expected) ⇒ Object
-
#canonical_string(body) ⇒ Object
-
#do_table(table) ⇒ Object
-
#equal_bodies(actual, expected) ⇒ Object
-
#equal_bodies_22(actual, expected) ⇒ Object
-
#equal_strings(actual, expected) ⇒ Object
-
#equal_strings_22(actual, expected) ⇒ Object
-
#equal_tags(p1, p2) ⇒ Object
-
#massage_body_to_table(actual) ⇒ Object
-
#no_tags(value) ⇒ Object
-
#print_parse(tables, title) ⇒ Object
FIXME This should go in Fitlibrary::ParseUtility.
-
#reports_equal(actual, expected) ⇒ Object
-
#show(parse) ⇒ Object
-
#show_field(field, value) ⇒ Object
camel, #check, #do_cell, #do_cells, #do_row, #do_rows, #do_tables, #error, escape, #exception, #find_class, #fixture_name, #get_args_for_table, #get_linked_fixture_with_args, gray, #ignore, #info, #initialize, #interpret_following_tables, #interpret_tables, label, metadata, #parse, #right, #total_errors, #totals, #wrong
Constructor Details
This class inherits a constructor from Fit::Fixture
Instance Method Details
#add_table_to_better_show_differences(table, actual, expected) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 30
def add_table_to_better_show_differences table, actual, expected
parse_end = table.last
cells1 = Fit::ParseHolder.create('td', 'fitlibrary.CommentFixture', nil, nil)
cells2 = Fit::ParseHolder.create('td', 'actual', nil, Fit::ParseHolder.create('td', 'expected', nil, nil))
cells3 = Fit::ParseHolder.create('td', show(actual), nil, Fit::ParseHolder.create('td', show(expected), nil, nil))
rows = Fit::ParseHolder.create('tr', '', cells1, Fit::ParseHolder.create('tr', '', cells2, Fit::ParseHolder.create('tr', '', cells3, nil)))
parse_end.more = Fit::ParseHolder.create('table', '', rows, nil)
end
|
#canonical_string(body) ⇒ Object
122
123
124
125
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 122
def canonical_string body
s = body.nil? ? '' : body.strip
s
end
|
#do_table(table) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 14
def do_table table
first_row = table.parts.more
actual = first_row.parts.parts
second_row = first_row.more
expected_cell = second_row.nil? ? first_row.parts.more : second_row.parts
expected = expected_cell.parts
Fit::Fixture.new.do_tables(actual)
if reports_equal(actual, expected)
right expected_cell
else
wrong expected_cell
print_parse actual, 'actual'
add_table_to_better_show_differences table, actual, expected
end
end
|
#equal_bodies(actual, expected) ⇒ Object
93
94
95
96
97
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 93
def equal_bodies actual, expected
result = equal_bodies_22 actual, expected
puts "!SpecifyFixture#equal_bodies(\"#{actual.body}\",\"#{expected.body}\")" unless result
result
end
|
#equal_bodies_22(actual, expected) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 99
def equal_bodies_22 actual, expected
expected_body = canonical_string expected.body
actual_body = canonical_string actual.body
return true if expected_body == 'IGNORE'
return true if actual_body == expected_body
stack_trace = 'class="fit_stacktrace">'
start = expected_body.index stack_trace
unless start.nil?
pattern = expected_body[0, start + stack_trace.size]
return actual.body =~ pattern
end
error_message = '<span class="fit_label">'
start = expected_body.index error_message
unless start.nil?
end_span = expected_body.index '</span>', start
unless end_span.nil?
pattern = expected_body[0, end_span - 1]
return actual.body =~ pattern
end
end
false
end
|
#equal_strings(actual, expected) ⇒ Object
131
132
133
134
135
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 131
def equal_strings actual, expected
result = equal_strings_22 actual, expected
puts "!SpecifyFixture#equal_strings(\"#{actual}\",\"#{expected}\")" unless result
result
end
|
#equal_strings_22(actual, expected) ⇒ Object
137
138
139
140
141
142
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 137
def equal_strings_22 actual, expected
return (expected.nil? or expected.strip.empty? or expected == "\n") if actual.nil?
return (actual.strip.empty? or actual == "\n") if expected.nil?
return true if expected == 'IGNORE'
actual.strip == expected.strip
end
|
127
128
129
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 127
def equal_tags p1, p2
p1.tag == p2.tag
end
|
#massage_body_to_table(actual) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 80
def massage_body_to_table actual
if (not actual.body.nil?) and (not actual.body.index('<table').nil?)
if actual.parts.nil?
begin
actual.parts = Fit::Parse.new actual.body
rescue Exception => e end
end
actual.body = ''
end
end
|
58
59
60
61
62
63
64
65
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 58
def no_tags value
while true
index = value.index '<'
break if index < 0
value = value[0..index] + '<' + value[index + 1..-1]
end
value
end
|
#print_parse(tables, title) ⇒ Object
FIXME This should go in Fitlibrary::ParseUtility
145
146
147
148
149
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 145
def print_parse tables, title
puts "---------Parse tables for #{title}:----------"
tables.print(STDOUT) unless tables.nil?
puts "-------------------"
end
|
#reports_equal(actual, expected) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 67
def reports_equal actual, expected
return expected.nil? if actual.nil?
return false if expected.nil?
massage_body_to_table actual
result = equal_tags(actual, expected) and
equal_strings(actual.leader, expected.leader) and
equal_bodies(actual, expected) and
equal_strings(actual.trailer, expected.trailer) and
reports_equal(actual.more, expected.more) and
reports_equal(actual.parts, expected.parts)
result
end
|
#show(parse) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 39
def show parse
return 'nil' if parse.nil?
result = "<#{parse.tag[0..-2]}><ul>"
result += show_field('leader', parse.leader)
result += parse.parts.nil? ? show_field('body', parse.body) : show(parse.parts)
result += show_field('trailer', parse.trailer)
result += '</ul>'
result += show(parse.more) unless parse.more.nil?
result
end
|
#show_field(field, value) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/fitlibrary/spec/specify_fixture.rb', line 50
def show_field field, value
if (not value.nil?) and (not value.strip.empty?)
"<li>#{field}: '#{no_tags(value)}'"
else
""
end
end
|