html-table 1.6.3 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGES.rdoc → CHANGES.md} +76 -68
- data/Gemfile +2 -0
- data/MANIFEST.md +57 -0
- data/{README.rdoc → README.md} +80 -71
- data/Rakefile +122 -146
- data/doc/attributes.md +160 -0
- data/doc/table.md +173 -0
- data/doc/table_body.md +9 -0
- data/doc/table_caption.md +10 -0
- data/doc/table_colgroup.md +8 -0
- data/doc/table_colgroup_col.md +7 -0
- data/doc/table_content.md +17 -0
- data/doc/table_foot.md +8 -0
- data/doc/table_head.md +10 -0
- data/doc/table_row.md +114 -0
- data/doc/table_row_data.md +100 -0
- data/doc/table_row_header.md +6 -0
- data/examples/simple1.rb +7 -5
- data/html-table.gemspec +16 -11
- data/lib/html/body.rb +9 -7
- data/lib/html/caption.rb +4 -2
- data/lib/html/col.rb +37 -34
- data/lib/html/colgroup.rb +90 -97
- data/lib/html/content.rb +3 -6
- data/lib/html/data.rb +3 -1
- data/lib/html/foot.rb +53 -45
- data/lib/html/head.rb +54 -47
- data/lib/html/header.rb +5 -3
- data/lib/html/mixin/attribute_handler.rb +59 -55
- data/lib/html/mixin/html_handler.rb +33 -35
- data/lib/html/mixin/strongtyping.rb +6 -6
- data/lib/html/mixin/tag_handler.rb +6 -2
- data/lib/html/row.rb +156 -183
- data/lib/html/table.rb +45 -45
- data/lib/html/tablesection.rb +51 -46
- data/spec/attribute_handler_spec.rb +374 -0
- data/spec/body_spec.rb +98 -0
- data/spec/caption_spec.rb +83 -0
- data/spec/colgroup_col_spec.rb +34 -0
- data/spec/colgroup_spec.rb +97 -0
- data/spec/data_spec.rb +88 -0
- data/spec/foot_spec.rb +116 -0
- data/spec/head_spec.rb +116 -0
- data/spec/header_spec.rb +85 -0
- data/spec/html_handler_spec.rb +35 -0
- data/spec/row_spec.rb +163 -0
- data/spec/table_spec.rb +186 -0
- data/spec/tablesection_spec.rb +36 -0
- data/spec/tag_handler_spec.rb +85 -0
- data.tar.gz.sig +0 -0
- metadata +118 -92
- metadata.gz.sig +0 -0
- data/MANIFEST.rdoc +0 -56
- data/doc/attributes.rdoc +0 -143
- data/doc/table.rdoc +0 -156
- data/doc/table_body.rdoc +0 -9
- data/doc/table_caption.rdoc +0 -9
- data/doc/table_colgroup.rdoc +0 -8
- data/doc/table_colgroup_col.rdoc +0 -9
- data/doc/table_content.rdoc +0 -15
- data/doc/table_foot.rdoc +0 -8
- data/doc/table_head.rdoc +0 -11
- data/doc/table_row.rdoc +0 -105
- data/doc/table_row_data.rdoc +0 -92
- data/doc/table_row_header.rdoc +0 -7
- data/test/test_attribute_handler.rb +0 -361
- data/test/test_body.rb +0 -87
- data/test/test_caption.rb +0 -80
- data/test/test_col.rb +0 -40
- data/test/test_colgroup.rb +0 -89
- data/test/test_data.rb +0 -77
- data/test/test_foot.rb +0 -111
- data/test/test_head.rb +0 -104
- data/test/test_header.rb +0 -77
- data/test/test_html_handler.rb +0 -37
- data/test/test_row.rb +0 -141
- data/test/test_table.rb +0 -159
- data/test/test_tablesection.rb +0 -42
- data/test/test_tag_handler.rb +0 -90
data/spec/header_spec.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#####################################################
|
2
|
+
# header_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HTML::Table::Row::Header class.
|
5
|
+
#####################################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'html/table'
|
8
|
+
|
9
|
+
RSpec.describe HTML::Table::Row::Header do
|
10
|
+
before do
|
11
|
+
@theader = described_class.new
|
12
|
+
end
|
13
|
+
|
14
|
+
example 'basic' do
|
15
|
+
html = '<th></th>'
|
16
|
+
expect(@theader.html.gsub(/\s+/, '')).to eq(html)
|
17
|
+
end
|
18
|
+
|
19
|
+
example 'constructor' do
|
20
|
+
expect{ described_class.new }.not_to raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
example 'constructor with string' do
|
24
|
+
expect{ described_class.new('foo') }.not_to raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
example 'constructor with numeric' do
|
28
|
+
expect{ described_class.new(1) }.not_to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
example 'constructor with arrays' do
|
32
|
+
expect{ described_class.new(%w[foo bar baz]) }.not_to raise_error
|
33
|
+
expect{ described_class.new([1, 2, 3]) }.not_to raise_error
|
34
|
+
expect{ described_class.new([[1, 2, 3], %w[foo bar]]) }.not_to raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
example 'with_attributes' do
|
38
|
+
html = "<th align='left' colspan=3 nowrap></th>"
|
39
|
+
@theader.align = 'left'
|
40
|
+
@theader.colspan = 3
|
41
|
+
@theader.nowrap = true
|
42
|
+
expect(@theader.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
43
|
+
end
|
44
|
+
|
45
|
+
example 'configure_not_allowed' do
|
46
|
+
expect{ @theader.configure }.to raise_error(NoMethodError)
|
47
|
+
end
|
48
|
+
|
49
|
+
example 'add_content' do
|
50
|
+
html = '<th>hello world</th>'
|
51
|
+
@theader.content = 'hello world'
|
52
|
+
expect(@theader.html.gsub(/\s{2,}/, '')).to eq(html)
|
53
|
+
end
|
54
|
+
|
55
|
+
example 'add_multiple_content_items' do
|
56
|
+
html = '<th>hello world</th>'
|
57
|
+
@theader.content = 'hello', ' world'
|
58
|
+
expect(@theader.html.gsub(/\s{2,}/, '')).to eq(html)
|
59
|
+
end
|
60
|
+
|
61
|
+
example 'add_content_in_constructor' do
|
62
|
+
html = '<th>hello world</th>'
|
63
|
+
@theader = described_class.new('hello world')
|
64
|
+
expect(@theader.html.gsub(/\s{2,}/, '')).to eq(html)
|
65
|
+
end
|
66
|
+
|
67
|
+
example 'indent_level' do
|
68
|
+
expect(described_class).to respond_to(:indent_level)
|
69
|
+
expect(described_class).to respond_to(:indent_level=)
|
70
|
+
expect{ described_class.indent_level = 'foo' }.to raise_error(ArgumentTypeError)
|
71
|
+
expect{ described_class.indent_level = 6 }.not_to raise_error
|
72
|
+
end
|
73
|
+
|
74
|
+
example 'end_tags? basic functionality' do
|
75
|
+
expect(described_class).to respond_to(:end_tags?)
|
76
|
+
expect(described_class.end_tags?).to be(true)
|
77
|
+
end
|
78
|
+
|
79
|
+
example 'end_tags= only accepts valid types' do
|
80
|
+
expect(described_class).to respond_to(:end_tags=)
|
81
|
+
expect{ described_class.end_tags = 'foo' }.to raise_error(ArgumentTypeError)
|
82
|
+
expect{ described_class.end_tags = 1 }.to raise_error(ArgumentTypeError)
|
83
|
+
expect{ described_class.end_tags = true }.not_to raise_error
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
############################################################################
|
2
|
+
# html_handler_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HtmlHandler module. For these tests, we'll use an
|
5
|
+
# instance of the Table class where the module has been mixed in.
|
6
|
+
############################################################################
|
7
|
+
require 'rspec'
|
8
|
+
require 'html/table'
|
9
|
+
|
10
|
+
RSpec.describe HTML::Mixin::HtmlHandler do
|
11
|
+
before do
|
12
|
+
@table = HTML::Table.new(['foo', 1, 'bar'])
|
13
|
+
end
|
14
|
+
|
15
|
+
example 'html basic functionality' do
|
16
|
+
expect(@table).to respond_to(:html)
|
17
|
+
expect{ @table.html }.not_to raise_error
|
18
|
+
expect(@table.html).to be_a(String)
|
19
|
+
expect(!@table.html.empty?).to be(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
example 'there is no html= method' do
|
23
|
+
expect{ @table.html = 'foo' }.to raise_error(NoMethodError)
|
24
|
+
end
|
25
|
+
|
26
|
+
example 'modify_html' do
|
27
|
+
expect{ @table.send(:modify_html) }.to raise_error(ArgumentError)
|
28
|
+
expect{ @table.send(:modify_html, 'nowrap') }.not_to raise_error
|
29
|
+
expect{ @table.send(:modify_html, 'align', 'top') }.not_to raise_error
|
30
|
+
expect do
|
31
|
+
@table.send(:modify_html, 'align', 'top')
|
32
|
+
@table.send(:modify_html, 'align', 'top')
|
33
|
+
end.not_to raise_error
|
34
|
+
end
|
35
|
+
end
|
data/spec/row_spec.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
############################################
|
2
|
+
# row_spec.rb
|
3
|
+
#
|
4
|
+
# Specs for the HTML::Table::Row class.
|
5
|
+
############################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'html/table'
|
8
|
+
|
9
|
+
RSpec.describe HTML::Table::Row do
|
10
|
+
before do
|
11
|
+
@trow = described_class.new
|
12
|
+
end
|
13
|
+
|
14
|
+
example 'constructor' do
|
15
|
+
expect{ described_class.new }.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
example 'constructor with string argument' do
|
19
|
+
expect{ described_class.new('foo') }.not_to raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
example 'constructor with numeric argument' do
|
23
|
+
expect{ described_class.new(1) }.not_to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
example 'constructor with array arguments' do
|
27
|
+
expect{ described_class.new([1, 2, 3]) }.not_to raise_error
|
28
|
+
expect{ described_class.new([[1, 2, 3], %w[foo bar]]) }.not_to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
example 'basic' do
|
32
|
+
html = '<tr></tr>'
|
33
|
+
expect(@trow.html.gsub(/\s+/, '')).to eq(html)
|
34
|
+
end
|
35
|
+
|
36
|
+
example 'header' do
|
37
|
+
expect(@trow).to respond_to(:header?)
|
38
|
+
expect(@trow).to respond_to(:header=)
|
39
|
+
expect{ @trow.header? }.not_to raise_error
|
40
|
+
expect{ @trow.header = true }.not_to raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
example 'with attributes' do
|
44
|
+
html = "<tr align='center'></tr>"
|
45
|
+
@trow.align = 'center'
|
46
|
+
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
47
|
+
end
|
48
|
+
|
49
|
+
example 'index assignment allows valid types' do
|
50
|
+
expect{ @trow[0] = HTML::Table::Row::Data.new }.not_to raise_error
|
51
|
+
expect{ @trow[0] = HTML::Table::Row::Header.new }.not_to raise_error
|
52
|
+
end
|
53
|
+
|
54
|
+
example 'index assignment raises an error for invalid types' do
|
55
|
+
expect{ @trow[0] = 'foo' }.to raise_error(ArgumentTypeError)
|
56
|
+
expect{ @trow[0] = 1 }.to raise_error(ArgumentTypeError)
|
57
|
+
expect{ @trow[0] = HTML::Table::Caption.new }.to raise_error(ArgumentTypeError)
|
58
|
+
end
|
59
|
+
|
60
|
+
example 'push allows valid types' do
|
61
|
+
expect{ @trow.push('test') }.not_to raise_error
|
62
|
+
expect{ @trow.push(7) }.not_to raise_error
|
63
|
+
expect{ @trow.push(HTML::Table::Row::Data.new) }.not_to raise_error
|
64
|
+
expect{ @trow.push(HTML::Table::Row::Header.new) }.not_to raise_error
|
65
|
+
end
|
66
|
+
|
67
|
+
example 'push raises an error for invalid types' do
|
68
|
+
expect{ @trow.push(HTML::Table::Caption.new) }.to raise_error(ArgumentTypeError)
|
69
|
+
expect{ @trow.push(nil) }.to raise_error(ArgumentTypeError)
|
70
|
+
end
|
71
|
+
|
72
|
+
example 'double arrow allows valid types' do
|
73
|
+
expect{ @trow << 'test' }.not_to raise_error
|
74
|
+
expect{ @trow << 'test' << 'foo' }.not_to raise_error
|
75
|
+
expect{ @trow << HTML::Table::Row::Data.new }.not_to raise_error
|
76
|
+
expect{ @trow << HTML::Table::Row::Header.new }.not_to raise_error
|
77
|
+
end
|
78
|
+
|
79
|
+
example 'double arrow raises an error for invalid types' do
|
80
|
+
expect{ @trow << HTML::Table::Caption.new }.to raise_error(ArgumentTypeError)
|
81
|
+
end
|
82
|
+
|
83
|
+
example 'header in constructor' do
|
84
|
+
expect{ @trow = described_class.new('test', true) }.not_to raise_error
|
85
|
+
html = '<tr><th>test</th></tr>'
|
86
|
+
expect(@trow.html.gsub(/\s+/, '')).to eq(html)
|
87
|
+
end
|
88
|
+
|
89
|
+
example 'push single data element' do
|
90
|
+
html = '<tr><td>hello</td></tr>'
|
91
|
+
@trow.push(HTML::Table::Row::Data.new{ |d| d.content = 'hello' })
|
92
|
+
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
93
|
+
end
|
94
|
+
|
95
|
+
example 'push multiple data element' do
|
96
|
+
html = '<tr><td>hello</td><td>world</td></tr>'
|
97
|
+
d1 = HTML::Table::Row::Data.new{ |d| d.content = 'hello' }
|
98
|
+
d2 = HTML::Table::Row::Data.new{ |d| d.content = 'world' }
|
99
|
+
@trow.push d1, d2
|
100
|
+
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
101
|
+
end
|
102
|
+
|
103
|
+
example 'add content directly' do
|
104
|
+
html = '<tr><td>hello</td><td>world</td></tr>'
|
105
|
+
@trow.content = 'hello', 'world'
|
106
|
+
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
107
|
+
end
|
108
|
+
|
109
|
+
example 'add content in constructor' do
|
110
|
+
html = '<tr><td>hello</td><td>world</td></tr>'
|
111
|
+
@trow = described_class.new(%w[hello world])
|
112
|
+
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
113
|
+
end
|
114
|
+
|
115
|
+
example 'configure column' do
|
116
|
+
html = "<tr><td>hello</td><td abbr='test' width=3 nowrap>world</td></tr>"
|
117
|
+
@trow.content = 'hello', 'world'
|
118
|
+
@trow.configure(1) do |d|
|
119
|
+
d.abbr = 'test'
|
120
|
+
d.width = 3
|
121
|
+
d.nowrap = true
|
122
|
+
end
|
123
|
+
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
124
|
+
end
|
125
|
+
|
126
|
+
example 'unshift does not allow invalid types' do
|
127
|
+
expect{ @trow.unshift(HTML::Table::Caption.new) }.to raise_error(ArgumentTypeError)
|
128
|
+
expect{ @trow.unshift(nil) }.to raise_error(ArgumentTypeError)
|
129
|
+
end
|
130
|
+
|
131
|
+
example 'unshift allows proper types' do
|
132
|
+
expect{ @trow.unshift('test') }.not_to raise_error
|
133
|
+
expect{ @trow.unshift(7) }.not_to raise_error
|
134
|
+
expect{ @trow.unshift(HTML::Table::Row::Data.new) }.not_to raise_error
|
135
|
+
expect{ @trow.unshift(HTML::Table::Row::Header.new) }.not_to raise_error
|
136
|
+
end
|
137
|
+
|
138
|
+
example 'configure error' do
|
139
|
+
expect{ @trow.configure(0, 0){} }.to raise_error(ArgumentError)
|
140
|
+
end
|
141
|
+
|
142
|
+
example 'indent_level' do
|
143
|
+
expect(described_class).to respond_to(:indent_level)
|
144
|
+
expect(described_class).to respond_to(:indent_level=)
|
145
|
+
expect{ described_class.indent_level = 'foo' }.to raise_error(ArgumentTypeError)
|
146
|
+
expect{ described_class.indent_level = 3 }.not_to raise_error
|
147
|
+
end
|
148
|
+
|
149
|
+
example 'end_tags?' do
|
150
|
+
expect(described_class).to respond_to(:end_tags?)
|
151
|
+
expect(described_class.end_tags?).to be(true)
|
152
|
+
end
|
153
|
+
|
154
|
+
example 'end_tags= basic functionality' do
|
155
|
+
expect(described_class).to respond_to(:end_tags=)
|
156
|
+
expect{ described_class.end_tags = true }.not_to raise_error
|
157
|
+
end
|
158
|
+
|
159
|
+
example 'end_tags= rejects invalid values' do
|
160
|
+
expect{ described_class.end_tags = 'foo' }.to raise_error(ArgumentTypeError)
|
161
|
+
expect{ described_class.end_tags = 1 }.to raise_error(ArgumentTypeError)
|
162
|
+
end
|
163
|
+
end
|
data/spec/table_spec.rb
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
#######################################################################
|
2
|
+
# table_spec.rb
|
3
|
+
#
|
4
|
+
# Specs for the HTML::Table class. These specs should be run via the
|
5
|
+
# 'rake spec' or 'rake spec:table' task.
|
6
|
+
#######################################################################
|
7
|
+
require 'rspec'
|
8
|
+
require 'html/table'
|
9
|
+
|
10
|
+
RSpec.describe HTML::Table do
|
11
|
+
before do
|
12
|
+
@table = described_class.new
|
13
|
+
@original_case = described_class.html_case
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
described_class.html_case = @original_case
|
18
|
+
end
|
19
|
+
|
20
|
+
example 'version' do
|
21
|
+
expect(described_class::VERSION).to eq('1.7.1')
|
22
|
+
expect(described_class::VERSION).to be_frozen
|
23
|
+
end
|
24
|
+
|
25
|
+
example 'constructor' do
|
26
|
+
expect{ described_class.new }.not_to raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
example 'constructor with string' do
|
30
|
+
expect{ described_class.new('foo') }.not_to raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
example 'constructor with numeric' do
|
34
|
+
expect{ described_class.new(1) }.not_to raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
example 'constructor with arrays' do
|
38
|
+
expect{ described_class.new(%w[foo bar baz]) }.not_to raise_error
|
39
|
+
expect{ described_class.new([1, 2, 3]) }.not_to raise_error
|
40
|
+
expect{ described_class.new([[1, 2, 3], %w[foo bar]]) }.not_to raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
example 'constructor_with_attributes' do
|
44
|
+
expect{ described_class.new(%w[foo bar baz], border: 1) }.not_to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
example 'html_case method basic functionality' do
|
48
|
+
expect(described_class).to respond_to(:html_case)
|
49
|
+
expect(described_class).to respond_to(:html_case=)
|
50
|
+
end
|
51
|
+
|
52
|
+
example "html_case writer method only accepts 'upper' and 'lower'" do
|
53
|
+
expect{ described_class.html_case = 'upper' }.not_to raise_error
|
54
|
+
expect{ described_class.html_case = 'lower' }.not_to raise_error
|
55
|
+
expect{ described_class.html_case = 'foo' }.to raise_error(ArgumentError)
|
56
|
+
expect{ described_class.html_case = 7 }.to raise_error(ArgumentTypeError)
|
57
|
+
end
|
58
|
+
|
59
|
+
example 'html_case causes uppercased output as expected' do
|
60
|
+
html = '<TABLE><TR><TD>hello</TD></TR></TABLE>'
|
61
|
+
described_class.html_case = 'upper'
|
62
|
+
@table.content = 'hello'
|
63
|
+
expect(@table.html.gsub(/\s+/, '')).to eq(html)
|
64
|
+
end
|
65
|
+
|
66
|
+
example 'indent_level' do
|
67
|
+
expect(described_class).to respond_to(:indent_level)
|
68
|
+
expect(described_class).to respond_to(:indent_level=)
|
69
|
+
expect{ described_class.indent_level = 0 }.not_to raise_error
|
70
|
+
expect{ described_class.indent_level = 'foo' }.to raise_error(ArgumentTypeError)
|
71
|
+
end
|
72
|
+
|
73
|
+
example 'index' do
|
74
|
+
expect{ @table[0] = 'foo' }.to raise_error(ArgumentTypeError)
|
75
|
+
end
|
76
|
+
|
77
|
+
example 'caption_index_constraints' do
|
78
|
+
expect{ @table[0] = described_class::Caption.new }.not_to raise_error
|
79
|
+
expect{ @table[1] = described_class::Caption.new }.to raise_error(ArgumentError)
|
80
|
+
end
|
81
|
+
|
82
|
+
example 'head_index_constraints' do
|
83
|
+
expect{ @table[0] = described_class::Head.create }.not_to raise_error
|
84
|
+
expect{ @table[1] = described_class::Head.create }.to raise_error(ArgumentError)
|
85
|
+
expect{ @table[2] = described_class::Head.create }.to raise_error(ArgumentError)
|
86
|
+
end
|
87
|
+
|
88
|
+
example 'foot_index_constraints' do
|
89
|
+
expect do
|
90
|
+
@table[0] = described_class::Caption.new
|
91
|
+
@table[-1] = described_class::Foot.create
|
92
|
+
end.not_to raise_error
|
93
|
+
expect{ @table[0] = described_class::Foot.create }.to raise_error(ArgumentError)
|
94
|
+
end
|
95
|
+
|
96
|
+
example 'unshift_constraints' do
|
97
|
+
expect{ @table.unshift described_class::Row.new }.not_to raise_error
|
98
|
+
expect{ @table.unshift described_class::Row::Data.new }.to raise_error(ArgumentTypeError)
|
99
|
+
expect{ @table.unshift 'foo' }.to raise_error(ArgumentTypeError)
|
100
|
+
end
|
101
|
+
|
102
|
+
example 'push_constraints' do
|
103
|
+
expect{ @table.push described_class::Row.new }.not_to raise_error
|
104
|
+
expect{ @table.push('foo') }.to raise_error(ArgumentTypeError)
|
105
|
+
expect{ @table.push(7) }.to raise_error(ArgumentTypeError)
|
106
|
+
expect{ @table.push(nil) }.to raise_error(ArgumentTypeError)
|
107
|
+
end
|
108
|
+
|
109
|
+
example 'double arrow allows valid values' do
|
110
|
+
expect{ @table << HTML::Table::Row.new }.not_to raise_error
|
111
|
+
expect{ @table << HTML::Table::Row.new << HTML::Table::Row.new }.not_to raise_error
|
112
|
+
end
|
113
|
+
|
114
|
+
example 'double arrow raises an error for invalid types' do
|
115
|
+
expect{ @table << 'foo' }.to raise_error(ArgumentTypeError)
|
116
|
+
expect{ @table << 7 }.to raise_error(ArgumentTypeError)
|
117
|
+
expect{ @table << nil }.to raise_error(ArgumentTypeError)
|
118
|
+
end
|
119
|
+
|
120
|
+
example 'basic' do
|
121
|
+
html = "<table>\n</table>"
|
122
|
+
expect(@table.html).to eq(html)
|
123
|
+
end
|
124
|
+
|
125
|
+
example 'with_attributes' do
|
126
|
+
html = "<table border=1 align='left' nowrap>\n</table>"
|
127
|
+
@table.border = 1
|
128
|
+
@table.align = 'left'
|
129
|
+
@table.nowrap = true
|
130
|
+
expect(@table.html).to eq(html)
|
131
|
+
end
|
132
|
+
|
133
|
+
example 'add_row_push' do
|
134
|
+
html = '<table><tr></tr></table>'
|
135
|
+
@table.push(described_class::Row.new)
|
136
|
+
expect(@table.html.gsub(/\s+/, '')).to eq(html)
|
137
|
+
end
|
138
|
+
|
139
|
+
example 'add_row_by_index' do
|
140
|
+
html = '<table><tr></tr></table>'
|
141
|
+
@table[0] = described_class::Row.new
|
142
|
+
expect(@table.html.gsub(/\s+/, '')).to eq(html)
|
143
|
+
end
|
144
|
+
|
145
|
+
example 'add_multiple_rows' do
|
146
|
+
html = '<table><tr></tr><tr></tr></table>'
|
147
|
+
@table.push HTML::Table::Row.new, HTML::Table::Row.new
|
148
|
+
expect(@table.html.gsub(/\s+/, '')).to eq(html)
|
149
|
+
end
|
150
|
+
|
151
|
+
example 'add_single_data_element' do
|
152
|
+
html = '<table><tr><td>hello</td></tr></table>'
|
153
|
+
@table.content = 'hello'
|
154
|
+
expect(@table.html.gsub(/\s+/, '')).to eq(html)
|
155
|
+
end
|
156
|
+
|
157
|
+
example 'add_multiple_data_elements' do
|
158
|
+
html = '<table><tr><td>hello</td></tr><tr><td>world</td></tr></table>'
|
159
|
+
@table.content = 'hello', 'world'
|
160
|
+
expect(@table.html.gsub(/\s+/, '')).to eq(html)
|
161
|
+
end
|
162
|
+
|
163
|
+
example 'configure_row' do
|
164
|
+
html = "<table><tr align='center'><td bgcolor='red'>hello</td></tr>"
|
165
|
+
html << '</table>'
|
166
|
+
@table.push(HTML::Table::Row::Data.new{ |d| d.content = 'hello' })
|
167
|
+
@table.configure(0){ |t| t.align = 'center' }
|
168
|
+
@table.configure(0, 0){ |d| d.bgcolor = 'red' }
|
169
|
+
expect(@table.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
170
|
+
end
|
171
|
+
|
172
|
+
example 'global_end_tags? basic functionality' do
|
173
|
+
expect(described_class).to respond_to(:global_end_tags?)
|
174
|
+
expect(described_class.global_end_tags?).to be(true)
|
175
|
+
end
|
176
|
+
|
177
|
+
example 'global_end_tags= basic functionality' do
|
178
|
+
expect(described_class).to respond_to(:global_end_tags=)
|
179
|
+
end
|
180
|
+
|
181
|
+
example 'global_end_tags= only accepts valid values' do
|
182
|
+
expect{ described_class.global_end_tags = false }.not_to raise_error
|
183
|
+
expect{ described_class.global_end_tags = true }.not_to raise_error
|
184
|
+
expect{ described_class.global_end_tags = 'foo' }.to raise_error(ArgumentTypeError)
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
######################################################
|
2
|
+
# tablesection_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HTML::Table::TableSection class.
|
5
|
+
######################################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'html/table'
|
8
|
+
|
9
|
+
RSpec.describe HTML::Table::TableSection do
|
10
|
+
before do
|
11
|
+
@table = HTML::Table.new
|
12
|
+
@tsection = described_class.new
|
13
|
+
end
|
14
|
+
|
15
|
+
example 'indent_level' do
|
16
|
+
expect(described_class).to respond_to(:indent_level)
|
17
|
+
expect(described_class).to respond_to(:indent_level=)
|
18
|
+
expect{ described_class.indent_level = 'foo' }.to raise_error(ArgumentTypeError)
|
19
|
+
expect{ described_class.indent_level = 3 }.not_to raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
example 'indices' do
|
23
|
+
expect{ @tsection[0] = 'foo' }.to raise_error(ArgumentTypeError)
|
24
|
+
expect{ @tsection[0] = HTML::Table::Row.new }.not_to raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
example 'push' do
|
28
|
+
expect{ @tsection.push('foo') }.to raise_error(ArgumentTypeError)
|
29
|
+
expect{ @tsection.push(HTML::Table::Row.new) }.not_to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
example 'unshift' do
|
33
|
+
expect{ @tsection.unshift('foo') }.to raise_error(ArgumentTypeError)
|
34
|
+
expect{ @tsection.unshift(HTML::Table::Row.new) }.not_to raise_error
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
############################################################################
|
2
|
+
# tag_handler_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the TagHandler module. For these tests, we'll use an
|
5
|
+
# instance of the Table class where the module has been mixed in.
|
6
|
+
############################################################################
|
7
|
+
require 'rspec'
|
8
|
+
require 'html/table'
|
9
|
+
|
10
|
+
RSpec.describe HTML::Mixin::TagHandler do
|
11
|
+
before(:all) do
|
12
|
+
BlinkWarning.disable
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
@tcontent = HTML::Table::Content.new('test')
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:all) do
|
20
|
+
BlinkWarning.enable
|
21
|
+
end
|
22
|
+
|
23
|
+
example 'bold' do
|
24
|
+
expect(@tcontent).to respond_to(:bold)
|
25
|
+
expect(@tcontent).to respond_to(:bold=)
|
26
|
+
expect{ @tcontent.bold }.not_to raise_error
|
27
|
+
expect{ @tcontent.bold = true }.not_to raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
example 'big' do
|
31
|
+
expect(@tcontent).to respond_to(:big)
|
32
|
+
expect(@tcontent).to respond_to(:big=)
|
33
|
+
expect{ @tcontent.big }.not_to raise_error
|
34
|
+
expect{ @tcontent.big = true }.not_to raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
example 'blink' do
|
38
|
+
expect(@tcontent).to respond_to(:blink)
|
39
|
+
expect(@tcontent).to respond_to(:blink=)
|
40
|
+
expect{ @tcontent.blink }.not_to raise_error
|
41
|
+
expect{ @tcontent.blink = true }.not_to raise_error
|
42
|
+
end
|
43
|
+
|
44
|
+
example 'italic' do
|
45
|
+
expect(@tcontent).to respond_to(:italic)
|
46
|
+
expect(@tcontent).to respond_to(:italic=)
|
47
|
+
expect{ @tcontent.italic }.not_to raise_error
|
48
|
+
expect{ @tcontent.italic = true }.not_to raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
example 'strike' do
|
52
|
+
expect(@tcontent).to respond_to(:strike)
|
53
|
+
expect(@tcontent).to respond_to(:strike=)
|
54
|
+
expect{ @tcontent.strike }.not_to raise_error
|
55
|
+
expect{ @tcontent.strike = true }.not_to raise_error
|
56
|
+
end
|
57
|
+
|
58
|
+
example 'sub' do
|
59
|
+
expect(@tcontent).to respond_to(:sub)
|
60
|
+
expect(@tcontent).to respond_to(:sub)
|
61
|
+
expect{ @tcontent.sub }.not_to raise_error
|
62
|
+
expect{ @tcontent.sub = true }.not_to raise_error
|
63
|
+
end
|
64
|
+
|
65
|
+
example 'sup' do
|
66
|
+
expect(@tcontent).to respond_to(:sup)
|
67
|
+
expect(@tcontent).to respond_to(:sup)
|
68
|
+
expect{ @tcontent.sup }.not_to raise_error
|
69
|
+
expect{ @tcontent.sup = true }.not_to raise_error
|
70
|
+
end
|
71
|
+
|
72
|
+
example 'tt' do
|
73
|
+
expect(@tcontent).to respond_to(:tt)
|
74
|
+
expect(@tcontent).to respond_to(:tt)
|
75
|
+
expect{ @tcontent.tt }.not_to raise_error
|
76
|
+
expect{ @tcontent.tt = true }.not_to raise_error
|
77
|
+
end
|
78
|
+
|
79
|
+
example 'underline' do
|
80
|
+
expect(@tcontent).to respond_to(:underline)
|
81
|
+
expect(@tcontent).to respond_to(:underline)
|
82
|
+
expect{ @tcontent.underline }.not_to raise_error
|
83
|
+
expect{ @tcontent.underline = true }.not_to raise_error
|
84
|
+
end
|
85
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|