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/body_spec.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
############################################
|
2
|
+
# body_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HTML::Table::Body class.
|
5
|
+
############################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'html/table'
|
8
|
+
|
9
|
+
RSpec.describe HTML::Table::Body do
|
10
|
+
before do
|
11
|
+
@table = HTML::Table.new
|
12
|
+
@tbody = described_class.new
|
13
|
+
end
|
14
|
+
|
15
|
+
example 'constructor with no arguments' do
|
16
|
+
expect{ described_class.new }.not_to raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
example 'constructor with string argument' do
|
20
|
+
expect{ described_class.new('foo') }.not_to raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
example 'constructor with numeric argument' do
|
24
|
+
expect{ described_class.new(1) }.not_to raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
example 'constructor with array argument' do
|
28
|
+
expect{ described_class.new(%w[foo bar baz]) }.not_to raise_error
|
29
|
+
expect{ described_class.new([1, 2, 3]) }.not_to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
example 'constructor with multiple array arguments' do
|
33
|
+
expect{ described_class.new([[1, 2, 3], %w[foo bar]]) }.not_to raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
example 'basic' do
|
37
|
+
html = '<tbody></tbody>'
|
38
|
+
expect(@tbody.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
39
|
+
end
|
40
|
+
|
41
|
+
example 'with_attributes' do
|
42
|
+
html = "<tbody align='left' char='x'></tbody>"
|
43
|
+
@tbody.align = 'left'
|
44
|
+
@tbody.char = 'x'
|
45
|
+
expect(@tbody.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
46
|
+
end
|
47
|
+
|
48
|
+
example 'push_single_row' do
|
49
|
+
html = '<tbody><tr><td>test</td></tr></tbody>'
|
50
|
+
@tbody.push(HTML::Table::Row.new{ |r| r.content = 'test' })
|
51
|
+
expect(@tbody.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
52
|
+
end
|
53
|
+
|
54
|
+
example 'push_multiple_rows' do
|
55
|
+
html = '<tbody><tr><td>test</td></tr><tr><td>foo</td></tr></tbody>'
|
56
|
+
r1 = HTML::Table::Row.new{ |r| r.content = 'test' }
|
57
|
+
r2 = HTML::Table::Row.new{ |r| r.content = 'foo' }
|
58
|
+
@tbody.push r1, r2
|
59
|
+
expect(@tbody.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
60
|
+
end
|
61
|
+
|
62
|
+
example 'add_content_directly' do
|
63
|
+
html = '<tbody><tr><td>hello</td><td>world</td></tr></tbody>'
|
64
|
+
@tbody.content = 'hello', 'world'
|
65
|
+
expect(@tbody.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
66
|
+
end
|
67
|
+
|
68
|
+
example 'add_content_in_constructor' do
|
69
|
+
html = '<tbody><tr><td>hello</td><td>world</td></tr></tbody>'
|
70
|
+
tb = described_class.new(%w[hello world])
|
71
|
+
expect(tb.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
72
|
+
end
|
73
|
+
|
74
|
+
example 'configure_column' do
|
75
|
+
html = "<tbody><tr><td>hello</td><td abbr='test' width=3 nowrap>world</td></tr></tbody>"
|
76
|
+
|
77
|
+
@tbody.content = 'hello', 'world'
|
78
|
+
@tbody.configure(0, 1) do |data|
|
79
|
+
data.abbr = 'test'
|
80
|
+
data.width = 3
|
81
|
+
data.nowrap = true
|
82
|
+
end
|
83
|
+
|
84
|
+
expect(@tbody.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
85
|
+
end
|
86
|
+
|
87
|
+
example 'end_tags?' do
|
88
|
+
expect(described_class).to respond_to(:end_tags?)
|
89
|
+
expect(described_class.end_tags?).to be(true)
|
90
|
+
end
|
91
|
+
|
92
|
+
example 'end_tags=' do
|
93
|
+
expect(described_class).to respond_to(:end_tags=)
|
94
|
+
expect{ described_class.end_tags = 'foo' }.to raise_error(ArgumentTypeError)
|
95
|
+
expect{ described_class.end_tags = 1 }.to raise_error(ArgumentTypeError)
|
96
|
+
expect{ described_class.end_tags = true }.not_to raise_error
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
###################################################
|
2
|
+
# caption_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HTML::Table::Caption class.
|
5
|
+
###################################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'html/table'
|
8
|
+
|
9
|
+
RSpec.describe HTML::Table::Caption do
|
10
|
+
before do
|
11
|
+
@table = HTML::Table.new
|
12
|
+
@tcaption = described_class.new
|
13
|
+
end
|
14
|
+
|
15
|
+
example 'constructor' do
|
16
|
+
expect{ described_class.new }.not_to raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
example 'constructor with string' do
|
20
|
+
expect{ described_class.new('foo') }.not_to raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
example 'constructor with number' do
|
24
|
+
expect{ described_class.new(1) }.not_to raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
example 'constructor with arrays' do
|
28
|
+
expect{ described_class.new(%w[foo bar baz]) }.not_to raise_error
|
29
|
+
expect{ described_class.new([1, 2, 3]) }.not_to raise_error
|
30
|
+
expect{ described_class.new([[1, 2, 3], %w[foo bar]]) }.not_to raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
example 'basic' do
|
34
|
+
html = '<caption></caption>'
|
35
|
+
expect(@tcaption.html.gsub(/\s+/, '')).to eq(html)
|
36
|
+
end
|
37
|
+
|
38
|
+
example 'with_attributes' do
|
39
|
+
html = "<caption align='left' valign='top'></caption>"
|
40
|
+
@tcaption.align = 'left'
|
41
|
+
@tcaption.valign = 'top'
|
42
|
+
expect(@tcaption.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
43
|
+
end
|
44
|
+
|
45
|
+
example 'configure_not_allowed' do
|
46
|
+
expect{ @tcaption.configure }.to raise_error(NoMethodError)
|
47
|
+
end
|
48
|
+
|
49
|
+
example 'add_content' do
|
50
|
+
html = '<caption>hello world</caption>'
|
51
|
+
@tcaption.content = 'hello world'
|
52
|
+
expect(@tcaption.html.gsub(/\s{2,}/, '')).to eq(html)
|
53
|
+
end
|
54
|
+
|
55
|
+
example 'add_multiple_content_items' do
|
56
|
+
html = '<caption>hello world</caption>'
|
57
|
+
@tcaption.content = 'hello', ' world'
|
58
|
+
expect(@tcaption.html.gsub(/\s{2,}/, '')).to eq(html)
|
59
|
+
end
|
60
|
+
|
61
|
+
example 'add_content_in_constructor' do
|
62
|
+
html = '<caption>hello world</caption>'
|
63
|
+
@tcaption = described_class.new('hello world')
|
64
|
+
expect(@tcaption.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 = 3 }.not_to raise_error
|
72
|
+
end
|
73
|
+
|
74
|
+
example 'only_row_zero_allowed' do
|
75
|
+
expect{ @table[1] = @tcaption }.to raise_error(ArgumentError)
|
76
|
+
end
|
77
|
+
|
78
|
+
example 'automatically_set_to_row_zero' do
|
79
|
+
@table.content = 'hello', 'world'
|
80
|
+
@table.push(@tcaption)
|
81
|
+
expect(@table[0]).to be_a(described_class)
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
##################################################
|
2
|
+
# colgroup_col_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Table::ColGroup::Col class
|
5
|
+
##################################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'html/table'
|
8
|
+
|
9
|
+
RSpec.describe HTML::Table::ColGroup::Col do
|
10
|
+
before do
|
11
|
+
@col = described_class.new
|
12
|
+
end
|
13
|
+
|
14
|
+
example 'basic' do
|
15
|
+
html = '<col>'
|
16
|
+
expect(@col.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
17
|
+
end
|
18
|
+
|
19
|
+
example 'no_configure' do
|
20
|
+
expect{ @col.configure }.to raise_error(NoMethodError)
|
21
|
+
end
|
22
|
+
|
23
|
+
example 'no_content_allowed' do
|
24
|
+
expect{ @col.content }.to raise_error(NoMethodError)
|
25
|
+
expect{ @col.content = 'foo' }.to raise_error(NoMethodError)
|
26
|
+
end
|
27
|
+
|
28
|
+
example 'indent_level' do
|
29
|
+
expect(described_class).to respond_to(:indent_level)
|
30
|
+
expect(described_class).to respond_to(:indent_level=)
|
31
|
+
expect{ described_class.indent_level = 'foo' }.to raise_error(ArgumentTypeError)
|
32
|
+
expect{ described_class.indent_level = 6 }.not_to raise_error
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
##################################################
|
2
|
+
# colgroup_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HTML::Table::ColGroup class.
|
5
|
+
##################################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'html/table'
|
8
|
+
|
9
|
+
RSpec.describe HTML::Table::ColGroup do
|
10
|
+
before do
|
11
|
+
@cgroup = described_class.new
|
12
|
+
@col = HTML::Table::ColGroup::Col.new
|
13
|
+
end
|
14
|
+
|
15
|
+
example 'constructor' do
|
16
|
+
expect{ described_class.new }.not_to raise_error
|
17
|
+
expect{ described_class.new(@col) }.not_to raise_error
|
18
|
+
expect{ described_class.new('foo') }.to raise_error(ArgumentTypeError)
|
19
|
+
end
|
20
|
+
|
21
|
+
example 'basic' do
|
22
|
+
html = '<colgroup></colgroup>'
|
23
|
+
expect(@cgroup.html.gsub(/\s+/, '')).to eq(html)
|
24
|
+
end
|
25
|
+
|
26
|
+
example 'with attributes' do
|
27
|
+
html = "<colgroup align='center' width='20%'></colgroup>"
|
28
|
+
@cgroup.align = 'center'
|
29
|
+
@cgroup.width = '20%'
|
30
|
+
expect(@cgroup.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
31
|
+
end
|
32
|
+
|
33
|
+
example 'push single col element' do
|
34
|
+
html = '<colgroup><col></colgroup>'
|
35
|
+
@cgroup.push(@col)
|
36
|
+
expect(@cgroup.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
37
|
+
end
|
38
|
+
|
39
|
+
example 'index assignment constraints' do
|
40
|
+
expect{ @cgroup[0] = 'foo' }.to raise_error(ArgumentTypeError)
|
41
|
+
expect{ @cgroup[0] = 1 }.to raise_error(ArgumentTypeError)
|
42
|
+
expect{ @cgroup[1] = HTML::Table::Row.new }.to raise_error(ArgumentTypeError)
|
43
|
+
expect{ @cgroup[0] = HTML::Table::ColGroup::Col.new }.not_to raise_error
|
44
|
+
end
|
45
|
+
|
46
|
+
example 'push constraints' do
|
47
|
+
expect{ @cgroup.push(7) }.to raise_error(ArgumentTypeError)
|
48
|
+
expect{ @cgroup.push('hello') }.to raise_error(ArgumentTypeError)
|
49
|
+
expect{ @cgroup.push(HTML::Table::Row.new) }.to raise_error(ArgumentTypeError)
|
50
|
+
expect{ @cgroup.push(HTML::Table::ColGroup::Col.new) }.not_to raise_error
|
51
|
+
end
|
52
|
+
|
53
|
+
example 'double arrow constraints' do
|
54
|
+
expect{ @cgroup << 7 }.to raise_error(ArgumentTypeError)
|
55
|
+
expect{ @cgroup << 'hello' }.to raise_error(ArgumentTypeError)
|
56
|
+
expect{ @cgroup << HTML::Table::Row.new }.to raise_error(ArgumentTypeError)
|
57
|
+
expect{ @cgroup << HTML::Table::ColGroup::Col.new }.not_to raise_error
|
58
|
+
end
|
59
|
+
|
60
|
+
example 'unshift constraints' do
|
61
|
+
expect{ @cgroup.unshift(7) }.to raise_error(ArgumentTypeError)
|
62
|
+
expect{ @cgroup.unshift('hello') }.to raise_error(ArgumentTypeError)
|
63
|
+
expect{ @cgroup.unshift(HTML::Table::Row.new) }.to raise_error(ArgumentTypeError)
|
64
|
+
expect{ @cgroup.unshift(HTML::Table::ColGroup::Col.new) }.not_to raise_error
|
65
|
+
end
|
66
|
+
|
67
|
+
example 'configure error' do
|
68
|
+
expect{ @cgroup.configure(0, 0){} }.to raise_error(ArgumentError)
|
69
|
+
end
|
70
|
+
|
71
|
+
example 'content error' do
|
72
|
+
expect{ @cgroup.content }.to raise_error(NoMethodError)
|
73
|
+
expect{ @cgroup.content = 'blah' }.to raise_error(NoMethodError)
|
74
|
+
end
|
75
|
+
|
76
|
+
example 'indent_level' do
|
77
|
+
expect(described_class).to respond_to(:indent_level)
|
78
|
+
expect(described_class).to respond_to(:indent_level=)
|
79
|
+
expect{ described_class.indent_level = 'foo' }.to raise_error(ArgumentTypeError)
|
80
|
+
expect{ described_class.indent_level = 6 }.not_to raise_error
|
81
|
+
end
|
82
|
+
|
83
|
+
example 'end_tags? basic functionality' do
|
84
|
+
expect(described_class).to respond_to(:end_tags?)
|
85
|
+
expect(described_class.end_tags?).to be(true)
|
86
|
+
end
|
87
|
+
|
88
|
+
example 'end_tags= basic functionality' do
|
89
|
+
expect(described_class).to respond_to(:end_tags=)
|
90
|
+
expect{ described_class.end_tags = true }.not_to raise_error
|
91
|
+
end
|
92
|
+
|
93
|
+
example 'end_tags= raises an error if an invalid type is assigned' do
|
94
|
+
expect{ described_class.end_tags = 'foo' }.to raise_error(ArgumentTypeError)
|
95
|
+
expect{ described_class.end_tags = 1 }.to raise_error(ArgumentTypeError)
|
96
|
+
end
|
97
|
+
end
|
data/spec/data_spec.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
###################################################
|
2
|
+
# data_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HTML::Table::Row::Data class.
|
5
|
+
###################################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'html/table'
|
8
|
+
|
9
|
+
RSpec.describe HTML::Table::Row::Data do
|
10
|
+
before do
|
11
|
+
@tdata = 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' do
|
19
|
+
expect{ described_class.new('foo') }.not_to raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
example 'constructor with numeric' do
|
23
|
+
expect{ described_class.new(1) }.not_to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
example 'constructor with arrays' do
|
27
|
+
expect{ described_class.new(%w[foo bar baz]) }.not_to raise_error
|
28
|
+
expect{ described_class.new([1, 2, 3]) }.not_to raise_error
|
29
|
+
expect{ described_class.new([[1, 2, 3], %w[foo bar]]) }.not_to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
example 'basic' do
|
33
|
+
html = '<td></td>'
|
34
|
+
expect(@tdata.html.gsub(/\s+/, '')).to eq(html)
|
35
|
+
end
|
36
|
+
|
37
|
+
example 'with_attributes' do
|
38
|
+
html = "<td align='left' width=3 nowrap></td>"
|
39
|
+
@tdata.align = 'left'
|
40
|
+
@tdata.width = 3
|
41
|
+
@tdata.nowrap = true
|
42
|
+
expect(@tdata.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
43
|
+
end
|
44
|
+
|
45
|
+
example 'configure_not_allowed' do
|
46
|
+
expect{ @tdata.configure }.to raise_error(NoMethodError)
|
47
|
+
end
|
48
|
+
|
49
|
+
example 'add_content' do
|
50
|
+
html = '<td>hello world</td>'
|
51
|
+
@tdata.content = 'hello world'
|
52
|
+
expect(@tdata.html.gsub(/\s{2,}/, '')).to eq(html)
|
53
|
+
end
|
54
|
+
|
55
|
+
example 'add_content_in_constructor' do
|
56
|
+
html = '<td>hello world</td>'
|
57
|
+
td = described_class.new('hello world')
|
58
|
+
expect(td.html.gsub(/\s{2,}/, '')).to eq(html)
|
59
|
+
end
|
60
|
+
|
61
|
+
example 'add_multiple_content_items' do
|
62
|
+
html = '<td>hello world</td>'
|
63
|
+
@tdata.content = 'hello', ' world'
|
64
|
+
expect(@tdata.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= basic functionality' do
|
80
|
+
expect(described_class).to respond_to(:end_tags=)
|
81
|
+
expect{ described_class.end_tags = true }.not_to raise_error
|
82
|
+
end
|
83
|
+
|
84
|
+
example 'end_tags= raises an error on an invalid value' do
|
85
|
+
expect{ described_class.end_tags = 'foo' }.to raise_error(ArgumentTypeError)
|
86
|
+
expect{ described_class.end_tags = 1 }.to raise_error(ArgumentTypeError)
|
87
|
+
end
|
88
|
+
end
|
data/spec/foot_spec.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
###############################################################################
|
2
|
+
# foot_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HTML::Table::Foot class. The class is a singleton
|
5
|
+
# class, so we have to take extra measures to ensure that a fresh instance
|
6
|
+
# is created between tests.
|
7
|
+
###############################################################################
|
8
|
+
require 'rspec'
|
9
|
+
require 'html/table'
|
10
|
+
|
11
|
+
RSpec.describe HTML::Table::Foot do
|
12
|
+
before do
|
13
|
+
@tfoot = described_class.create
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
described_class.instance_variable_set(:@instance, nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
example 'constructor' do
|
21
|
+
expect{ described_class.create }.not_to raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
example 'constructor with string' do
|
25
|
+
expect{ described_class.create('foo') }.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
example 'constructor with numeric' do
|
29
|
+
expect{ described_class.create(1) }.not_to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
example 'constructor with arrays' do
|
33
|
+
expect{ described_class.create(%w[foo bar baz]) }.not_to raise_error
|
34
|
+
expect{ described_class.create([1, 2, 3]) }.not_to raise_error
|
35
|
+
expect{ described_class.create([[1, 2, 3], %w[foo bar]]) }.not_to raise_error
|
36
|
+
end
|
37
|
+
|
38
|
+
example 'basic' do
|
39
|
+
html = '<tfoot></tfoot>'
|
40
|
+
expect(@tfoot.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
41
|
+
end
|
42
|
+
|
43
|
+
example 'end_tags? basic functionality' do
|
44
|
+
expect(described_class).to respond_to(:end_tags?)
|
45
|
+
expect(described_class.end_tags?).to be(true)
|
46
|
+
expect{ described_class.end_tags? }.not_to raise_error
|
47
|
+
end
|
48
|
+
|
49
|
+
example 'end_tags= basic functionality' do
|
50
|
+
expect(described_class).to respond_to(:end_tags=)
|
51
|
+
expect{ described_class.end_tags = true }.not_to raise_error
|
52
|
+
end
|
53
|
+
|
54
|
+
example 'end_tags raises an error on an invalid type' do
|
55
|
+
expect{ described_class.end_tags = 'foo' }.to raise_error(ArgumentTypeError)
|
56
|
+
end
|
57
|
+
|
58
|
+
example 'with attributes' do
|
59
|
+
html = "<tfoot align='left' char='x'></tfoot>"
|
60
|
+
@tfoot.align = 'left'
|
61
|
+
@tfoot.char = 'x'
|
62
|
+
expect(@tfoot.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
63
|
+
end
|
64
|
+
|
65
|
+
example 'push single row' do
|
66
|
+
html = '<tfoot><tr><td>test</td></tr></tfoot>'
|
67
|
+
@tfoot.push(HTML::Table::Row.new{ |r| r.content = 'test' })
|
68
|
+
expect(@tfoot.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
69
|
+
end
|
70
|
+
|
71
|
+
example 'push multiple rows' do
|
72
|
+
html = '<tfoot><tr><td>test</td></tr><tr><td>foo</td></tr></tfoot>'
|
73
|
+
r1 = HTML::Table::Row.new{ |r| r.content = 'test' }
|
74
|
+
r2 = HTML::Table::Row.new{ |r| r.content = 'foo' }
|
75
|
+
@tfoot.push r1, r2
|
76
|
+
expect(@tfoot.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
77
|
+
end
|
78
|
+
|
79
|
+
example 'add content directly' do
|
80
|
+
html = '<tfoot><tr><td>hello</td><td>world</td></tr></tfoot>'
|
81
|
+
@tfoot.content = 'hello', 'world'
|
82
|
+
expect(@tfoot.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
83
|
+
end
|
84
|
+
|
85
|
+
example 'add content in constructor' do
|
86
|
+
html = '<tfoot><tr><td>hello</td><td>world</td></tr></tfoot>'
|
87
|
+
described_class.instance_variable_set(:@instance, nil)
|
88
|
+
@tfoot = described_class.create(%w[hello world])
|
89
|
+
expect(@tfoot.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
90
|
+
end
|
91
|
+
|
92
|
+
example 'configure column' do
|
93
|
+
html = "<tfoot><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
|
94
|
+
html += '</td></tr></tfoot>'
|
95
|
+
@tfoot.content = 'hello', 'world'
|
96
|
+
@tfoot.configure(0, 1) do |data|
|
97
|
+
data.abbr = 'test'
|
98
|
+
data.width = 3
|
99
|
+
data.nowrap = true
|
100
|
+
end
|
101
|
+
expect(@tfoot.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
102
|
+
end
|
103
|
+
|
104
|
+
# rubocop:disable RSpec/IdenticalEqualityAssertion
|
105
|
+
example 'new not allowed' do
|
106
|
+
expect{ described_class.new }.to raise_error(NoMethodError)
|
107
|
+
end
|
108
|
+
|
109
|
+
example 'additional calls to constructor do nothing since class is a singleton' do
|
110
|
+
expect(described_class.create).to eq(described_class.create)
|
111
|
+
expect(described_class.instance).to eq(described_class.instance)
|
112
|
+
expect(described_class.instance.object_id).to eq(described_class.instance.object_id)
|
113
|
+
expect(described_class.create.object_id).to eq(described_class.create.object_id)
|
114
|
+
end
|
115
|
+
# rubocop:enable RSpec/IdenticalEqualityAssertion
|
116
|
+
end
|
data/spec/head_spec.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
###############################################################################
|
2
|
+
# head_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the described_class class. The Table::Head class is a singleton
|
5
|
+
# class, so we have to take extra measures to ensure that a fresh instance
|
6
|
+
# is created between tests.
|
7
|
+
###############################################################################
|
8
|
+
require 'rspec'
|
9
|
+
require 'html/table'
|
10
|
+
|
11
|
+
RSpec.describe HTML::Table::Head do
|
12
|
+
before do
|
13
|
+
@thead = described_class.create
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
described_class.instance_variable_set(:@instance, nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
example 'constructor' do
|
21
|
+
expect{ described_class.create }.not_to raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
example 'constructor with string' do
|
25
|
+
expect{ described_class.create('foo') }.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
example 'constructor with numeric' do
|
29
|
+
expect{ described_class.create(1) }.not_to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
example 'constructor with arrays' do
|
33
|
+
expect{ described_class.create(%w[foo bar baz]) }.not_to raise_error
|
34
|
+
expect{ described_class.create([1, 2, 3]) }.not_to raise_error
|
35
|
+
expect{ described_class.create([[1, 2, 3], %w[foo bar]]) }.not_to raise_error
|
36
|
+
end
|
37
|
+
|
38
|
+
example 'basic' do
|
39
|
+
html = '<thead></thead>'
|
40
|
+
expect(@thead.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
41
|
+
end
|
42
|
+
|
43
|
+
example 'end_tags? basic functionality' do
|
44
|
+
expect(described_class).to respond_to(:end_tags?)
|
45
|
+
expect(described_class.end_tags?).to be(true)
|
46
|
+
expect{ described_class.end_tags? }.not_to raise_error
|
47
|
+
end
|
48
|
+
|
49
|
+
example 'end_tags= basic functionality' do
|
50
|
+
expect(described_class).to respond_to(:end_tags=)
|
51
|
+
expect{ described_class.end_tags = true }.not_to raise_error
|
52
|
+
end
|
53
|
+
|
54
|
+
example 'end_tags= does not allow invalid types' do
|
55
|
+
expect{ described_class.end_tags = 'foo' }.to raise_error(ArgumentTypeError)
|
56
|
+
end
|
57
|
+
|
58
|
+
example 'with attributes' do
|
59
|
+
html = "<thead align='left' char='x'></thead>"
|
60
|
+
@thead.align = 'left'
|
61
|
+
@thead.char = 'x'
|
62
|
+
expect(@thead.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
63
|
+
end
|
64
|
+
|
65
|
+
example 'push single row' do
|
66
|
+
html = '<thead><tr><td>test</td></tr></thead>'
|
67
|
+
@thead.push(HTML::Table::Row.new{ |r| r.content = 'test' })
|
68
|
+
expect(@thead.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
69
|
+
end
|
70
|
+
|
71
|
+
example 'push multiple rows' do
|
72
|
+
html = '<thead><tr><td>test</td></tr><tr><td>foo</td></tr></thead>'
|
73
|
+
r1 = HTML::Table::Row.new('test')
|
74
|
+
r2 = HTML::Table::Row.new('foo')
|
75
|
+
@thead.push(r1, r2)
|
76
|
+
expect(@thead.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
77
|
+
end
|
78
|
+
|
79
|
+
example 'add content directly' do
|
80
|
+
html = '<thead><tr><td>hello</td><td>world</td></tr></thead>'
|
81
|
+
@thead.content = 'hello', 'world'
|
82
|
+
expect(@thead.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
83
|
+
end
|
84
|
+
|
85
|
+
example 'add content in constructor' do
|
86
|
+
html = '<thead><tr><td>hello</td><td>world</td></tr></thead>'
|
87
|
+
described_class.instance_variable_set(:@instance, nil)
|
88
|
+
@thead = described_class.create(%w[hello world])
|
89
|
+
expect(@thead.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
90
|
+
end
|
91
|
+
|
92
|
+
example 'configure column' do
|
93
|
+
html = "<thead><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
|
94
|
+
html += '</td></tr></thead>'
|
95
|
+
@thead.content = 'hello', 'world'
|
96
|
+
@thead.configure(0, 1) do |d|
|
97
|
+
d.abbr = 'test'
|
98
|
+
d.width = 3
|
99
|
+
d.nowrap = true
|
100
|
+
end
|
101
|
+
expect(@thead.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
102
|
+
end
|
103
|
+
|
104
|
+
# rubocop:disable RSpec/IdenticalEqualityAssertion
|
105
|
+
example 'new not allowed' do
|
106
|
+
expect{ described_class.new }.to raise_error(NoMethodError)
|
107
|
+
end
|
108
|
+
|
109
|
+
example 'additional calls to constructor do nothing since class is a singleton' do
|
110
|
+
expect(described_class.create).to eq(described_class.create)
|
111
|
+
expect(described_class.instance).to eq(described_class.instance)
|
112
|
+
expect(described_class.instance.object_id).to eq(described_class.instance.object_id)
|
113
|
+
expect(described_class.create.object_id).to eq(described_class.create.object_id)
|
114
|
+
end
|
115
|
+
# rubocop:enable RSpec/IdenticalEqualityAssertion
|
116
|
+
end
|