html-table 1.7.0 → 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} +73 -69
- data/Gemfile +2 -7
- data/{MANIFEST.rdoc → MANIFEST.md} +15 -15
- data/{README.rdoc → README.md} +80 -71
- data/Rakefile +7 -2
- 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 +13 -8
- 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 +57 -53
- 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 +94 -80
- data/spec/body_spec.rb +54 -37
- data/spec/caption_spec.rb +41 -32
- data/spec/colgroup_col_spec.rb +7 -7
- data/spec/colgroup_spec.rb +50 -36
- data/spec/data_spec.rb +39 -23
- data/spec/foot_spec.rb +58 -46
- data/spec/head_spec.rb +62 -47
- data/spec/header_spec.rb +35 -22
- data/spec/html_handler_spec.rb +15 -12
- data/spec/row_spec.rb +95 -68
- data/spec/table_spec.rb +65 -31
- data/spec/tablesection_spec.rb +13 -13
- data/spec/tag_handler_spec.rb +13 -13
- data.tar.gz.sig +0 -0
- metadata +103 -78
- metadata.gz.sig +0 -0
- 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/spec/head_spec.rb
CHANGED
@@ -8,94 +8,109 @@
|
|
8
8
|
require 'rspec'
|
9
9
|
require 'html/table'
|
10
10
|
|
11
|
-
#####################################################################
|
12
|
-
# Ensure that a fresh instance of described_class is used between tests
|
13
|
-
# by calling 'refresh' in the 'teardown' method.
|
14
|
-
#####################################################################
|
15
|
-
class HTML::Table::Head
|
16
|
-
private
|
17
|
-
def refresh
|
18
|
-
@@head = nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
11
|
RSpec.describe HTML::Table::Head do
|
23
12
|
before do
|
24
|
-
@table = HTML::Table.new
|
25
13
|
@thead = described_class.create
|
26
14
|
end
|
27
15
|
|
28
|
-
|
16
|
+
after do
|
17
|
+
described_class.instance_variable_set(:@instance, nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
example 'constructor' do
|
29
21
|
expect{ described_class.create }.not_to raise_error
|
30
|
-
|
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
|
31
29
|
expect{ described_class.create(1) }.not_to raise_error
|
32
|
-
expect{ described_class.create(%w/foo bar baz/) }.not_to raise_error
|
33
|
-
expect{ described_class.create([1,2,3]) }.not_to raise_error
|
34
|
-
expect{ described_class.create([[1,2,3],["foo","bar"]]) }.not_to raise_error
|
35
30
|
end
|
36
31
|
|
37
|
-
example
|
38
|
-
|
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>'
|
39
40
|
expect(@thead.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
40
41
|
end
|
41
42
|
|
42
|
-
example
|
43
|
+
example 'end_tags? basic functionality' do
|
43
44
|
expect(described_class).to respond_to(:end_tags?)
|
44
|
-
expect(described_class).to
|
45
|
+
expect(described_class.end_tags?).to be(true)
|
45
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=)
|
46
51
|
expect{ described_class.end_tags = true }.not_to raise_error
|
47
|
-
expect{ described_class.end_tags = "foo" }.to raise_error(HTML::Mixin::StrongTyping::ArgumentTypeError)
|
48
52
|
end
|
49
53
|
|
50
|
-
example
|
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
|
51
59
|
html = "<thead align='left' char='x'></thead>"
|
52
|
-
@thead.align =
|
60
|
+
@thead.align = 'left'
|
53
61
|
@thead.char = 'x'
|
54
62
|
expect(@thead.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
55
63
|
end
|
56
64
|
|
57
|
-
example
|
58
|
-
html =
|
59
|
-
@thead.push
|
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' })
|
60
68
|
expect(@thead.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
61
69
|
end
|
62
70
|
|
63
|
-
example
|
64
|
-
html =
|
65
|
-
r1 = HTML::Table::Row.new(
|
66
|
-
r2 = HTML::Table::Row.new(
|
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')
|
67
75
|
@thead.push(r1, r2)
|
68
76
|
expect(@thead.html.gsub(/\s{2,}|\n/, '')).to eq(html)
|
69
77
|
end
|
70
78
|
|
71
|
-
example
|
72
|
-
html =
|
73
|
-
@thead.content =
|
79
|
+
example 'add content directly' do
|
80
|
+
html = '<thead><tr><td>hello</td><td>world</td></tr></thead>'
|
81
|
+
@thead.content = 'hello', 'world'
|
74
82
|
expect(@thead.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
75
83
|
end
|
76
84
|
|
77
|
-
example
|
78
|
-
html =
|
79
|
-
|
80
|
-
@thead = described_class.create([
|
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])
|
81
89
|
expect(@thead.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
82
90
|
end
|
83
91
|
|
84
|
-
example
|
92
|
+
example 'configure column' do
|
85
93
|
html = "<thead><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
|
86
|
-
html +=
|
87
|
-
@thead.content =
|
88
|
-
@thead.configure(0,1)
|
94
|
+
html += '</td></tr></thead>'
|
95
|
+
@thead.content = 'hello', 'world'
|
96
|
+
@thead.configure(0, 1) do |d|
|
89
97
|
d.abbr = 'test'
|
90
98
|
d.width = 3
|
91
99
|
d.nowrap = true
|
92
|
-
|
100
|
+
end
|
93
101
|
expect(@thead.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
94
102
|
end
|
95
103
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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)
|
100
114
|
end
|
115
|
+
# rubocop:enable RSpec/IdenticalEqualityAssertion
|
101
116
|
end
|
data/spec/header_spec.rb
CHANGED
@@ -11,21 +11,30 @@ RSpec.describe HTML::Table::Row::Header do
|
|
11
11
|
@theader = described_class.new
|
12
12
|
end
|
13
13
|
|
14
|
-
example
|
15
|
-
html =
|
14
|
+
example 'basic' do
|
15
|
+
html = '<th></th>'
|
16
16
|
expect(@theader.html.gsub(/\s+/, '')).to eq(html)
|
17
17
|
end
|
18
18
|
|
19
|
-
example
|
19
|
+
example 'constructor' do
|
20
20
|
expect{ described_class.new }.not_to raise_error
|
21
|
-
|
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
|
22
28
|
expect{ described_class.new(1) }.not_to raise_error
|
23
|
-
expect{ described_class.new(%w/foo bar baz/) }.not_to raise_error
|
24
|
-
expect{ described_class.new([1,2,3]) }.not_to raise_error
|
25
|
-
expect{ described_class.new([[1,2,3],["foo","bar"]]) }.not_to raise_error
|
26
29
|
end
|
27
30
|
|
28
|
-
example
|
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
|
29
38
|
html = "<th align='left' colspan=3 nowrap></th>"
|
30
39
|
@theader.align = 'left'
|
31
40
|
@theader.colspan = 3
|
@@ -33,39 +42,43 @@ RSpec.describe HTML::Table::Row::Header do
|
|
33
42
|
expect(@theader.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
34
43
|
end
|
35
44
|
|
36
|
-
example
|
45
|
+
example 'configure_not_allowed' do
|
37
46
|
expect{ @theader.configure }.to raise_error(NoMethodError)
|
38
47
|
end
|
39
48
|
|
40
|
-
example
|
41
|
-
html =
|
42
|
-
@theader.content =
|
49
|
+
example 'add_content' do
|
50
|
+
html = '<th>hello world</th>'
|
51
|
+
@theader.content = 'hello world'
|
43
52
|
expect(@theader.html.gsub(/\s{2,}/, '')).to eq(html)
|
44
53
|
end
|
45
54
|
|
46
|
-
example
|
47
|
-
html =
|
48
|
-
@theader.content =
|
55
|
+
example 'add_multiple_content_items' do
|
56
|
+
html = '<th>hello world</th>'
|
57
|
+
@theader.content = 'hello', ' world'
|
49
58
|
expect(@theader.html.gsub(/\s{2,}/, '')).to eq(html)
|
50
59
|
end
|
51
60
|
|
52
|
-
example
|
53
|
-
html =
|
54
|
-
@theader = described_class.new(
|
61
|
+
example 'add_content_in_constructor' do
|
62
|
+
html = '<th>hello world</th>'
|
63
|
+
@theader = described_class.new('hello world')
|
55
64
|
expect(@theader.html.gsub(/\s{2,}/, '')).to eq(html)
|
56
65
|
end
|
57
66
|
|
58
|
-
example
|
67
|
+
example 'indent_level' do
|
59
68
|
expect(described_class).to respond_to(:indent_level)
|
60
69
|
expect(described_class).to respond_to(:indent_level=)
|
61
|
-
expect{ described_class.indent_level =
|
70
|
+
expect{ described_class.indent_level = 'foo' }.to raise_error(ArgumentTypeError)
|
62
71
|
expect{ described_class.indent_level = 6 }.not_to raise_error
|
63
72
|
end
|
64
73
|
|
65
|
-
example
|
74
|
+
example 'end_tags? basic functionality' do
|
66
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
|
67
80
|
expect(described_class).to respond_to(:end_tags=)
|
68
|
-
expect{ described_class.end_tags =
|
81
|
+
expect{ described_class.end_tags = 'foo' }.to raise_error(ArgumentTypeError)
|
69
82
|
expect{ described_class.end_tags = 1 }.to raise_error(ArgumentTypeError)
|
70
83
|
expect{ described_class.end_tags = true }.not_to raise_error
|
71
84
|
end
|
data/spec/html_handler_spec.rb
CHANGED
@@ -9,24 +9,27 @@ require 'html/table'
|
|
9
9
|
|
10
10
|
RSpec.describe HTML::Mixin::HtmlHandler do
|
11
11
|
before do
|
12
|
-
@table = HTML::Table.new([
|
12
|
+
@table = HTML::Table.new(['foo', 1, 'bar'])
|
13
13
|
end
|
14
14
|
|
15
|
-
example
|
15
|
+
example 'html basic functionality' do
|
16
16
|
expect(@table).to respond_to(:html)
|
17
17
|
expect{ @table.html }.not_to raise_error
|
18
|
-
expect
|
19
|
-
expect(
|
20
|
-
expect( @table.html.length > 0).to eq(true)
|
18
|
+
expect(@table.html).to be_a(String)
|
19
|
+
expect(!@table.html.empty?).to be(true)
|
21
20
|
end
|
22
21
|
|
23
|
-
example
|
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
|
24
27
|
expect{ @table.send(:modify_html) }.to raise_error(ArgumentError)
|
25
|
-
expect{ @table.send(:modify_html,
|
26
|
-
expect{ @table.send(:modify_html,
|
27
|
-
expect
|
28
|
-
@table.send(:modify_html,
|
29
|
-
@table.send(:modify_html,
|
30
|
-
|
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
|
31
34
|
end
|
32
35
|
end
|
data/spec/row_spec.rb
CHANGED
@@ -1,136 +1,163 @@
|
|
1
1
|
############################################
|
2
2
|
# row_spec.rb
|
3
3
|
#
|
4
|
-
# Specs for the Table::Row class.
|
4
|
+
# Specs for the HTML::Table::Row class.
|
5
5
|
############################################
|
6
6
|
require 'rspec'
|
7
7
|
require 'html/table'
|
8
|
-
include HTML
|
9
8
|
|
10
9
|
RSpec.describe HTML::Table::Row do
|
11
10
|
before do
|
12
11
|
@trow = described_class.new
|
13
12
|
end
|
14
13
|
|
15
|
-
example
|
16
|
-
expect{
|
17
|
-
expect{ Table::Row.new("foo") }.not_to raise_error
|
18
|
-
expect{ Table::Row.new(1) }.not_to raise_error
|
19
|
-
expect{ Table::Row.new([1,2,3]) }.not_to raise_error
|
20
|
-
expect{ Table::Row.new([[1,2,3],["foo","bar"]]) }.not_to raise_error
|
14
|
+
example 'constructor' do
|
15
|
+
expect{ described_class.new }.not_to raise_error
|
21
16
|
end
|
22
17
|
|
23
|
-
example
|
24
|
-
|
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>'
|
25
33
|
expect(@trow.html.gsub(/\s+/, '')).to eq(html)
|
26
34
|
end
|
27
35
|
|
28
|
-
example
|
36
|
+
example 'header' do
|
29
37
|
expect(@trow).to respond_to(:header?)
|
30
38
|
expect(@trow).to respond_to(:header=)
|
31
39
|
expect{ @trow.header? }.not_to raise_error
|
32
40
|
expect{ @trow.header = true }.not_to raise_error
|
33
41
|
end
|
34
42
|
|
35
|
-
example
|
43
|
+
example 'with attributes' do
|
36
44
|
html = "<tr align='center'></tr>"
|
37
|
-
@trow.align =
|
45
|
+
@trow.align = 'center'
|
38
46
|
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
39
47
|
end
|
40
48
|
|
41
|
-
example
|
42
|
-
expect{ @trow[0] =
|
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)
|
43
56
|
expect{ @trow[0] = 1 }.to raise_error(ArgumentTypeError)
|
44
|
-
expect{ @trow[0] = Table::Caption.new }.to raise_error(ArgumentTypeError)
|
45
|
-
expect{ @trow[0] = Table::Row::Data.new }.not_to raise_error
|
46
|
-
expect{ @trow[0] = Table::Row::Header.new }.not_to raise_error
|
57
|
+
expect{ @trow[0] = HTML::Table::Caption.new }.to raise_error(ArgumentTypeError)
|
47
58
|
end
|
48
59
|
|
49
|
-
example
|
50
|
-
expect{ @trow.push(
|
51
|
-
expect{ @trow.push(nil) }.to raise_error(ArgumentTypeError)
|
52
|
-
expect{ @trow.push("test") }.not_to raise_error
|
60
|
+
example 'push allows valid types' do
|
61
|
+
expect{ @trow.push('test') }.not_to raise_error
|
53
62
|
expect{ @trow.push(7) }.not_to raise_error
|
54
|
-
expect{ @trow.push(Table::Row::Data.new) }.not_to raise_error
|
55
|
-
expect{ @trow.push(Table::Row::Header.new) }.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)
|
56
70
|
end
|
57
71
|
|
58
|
-
example
|
59
|
-
expect{ @trow <<
|
60
|
-
expect{ @trow <<
|
61
|
-
expect{ @trow <<
|
62
|
-
expect{ @trow << Table::Row::
|
63
|
-
expect{ @trow << Table::Row::Header.new }.not_to raise_error
|
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
|
64
77
|
end
|
65
78
|
|
66
|
-
example
|
67
|
-
expect{ @trow
|
68
|
-
|
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>'
|
69
86
|
expect(@trow.html.gsub(/\s+/, '')).to eq(html)
|
70
87
|
end
|
71
88
|
|
72
|
-
example
|
73
|
-
html =
|
74
|
-
@trow.push
|
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' })
|
75
92
|
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
76
93
|
end
|
77
94
|
|
78
|
-
example
|
79
|
-
html =
|
80
|
-
d1 = Table::Row::Data.new{ |d| d.content =
|
81
|
-
d2 = Table::Row::Data.new{ |d| d.content =
|
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' }
|
82
99
|
@trow.push d1, d2
|
83
100
|
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
84
101
|
end
|
85
102
|
|
86
|
-
example
|
87
|
-
html =
|
88
|
-
@trow.content =
|
103
|
+
example 'add content directly' do
|
104
|
+
html = '<tr><td>hello</td><td>world</td></tr>'
|
105
|
+
@trow.content = 'hello', 'world'
|
89
106
|
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
90
107
|
end
|
91
108
|
|
92
|
-
example
|
93
|
-
html =
|
94
|
-
@trow =
|
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])
|
95
112
|
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
96
113
|
end
|
97
114
|
|
98
|
-
example
|
115
|
+
example 'configure column' do
|
99
116
|
html = "<tr><td>hello</td><td abbr='test' width=3 nowrap>world</td></tr>"
|
100
|
-
@trow.content =
|
101
|
-
@trow.configure(1)
|
117
|
+
@trow.content = 'hello', 'world'
|
118
|
+
@trow.configure(1) do |d|
|
102
119
|
d.abbr = 'test'
|
103
120
|
d.width = 3
|
104
121
|
d.nowrap = true
|
105
|
-
|
122
|
+
end
|
106
123
|
expect(@trow.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
|
107
124
|
end
|
108
125
|
|
109
|
-
example
|
110
|
-
expect{ @trow.unshift(Table::Caption.new) }.to raise_error(ArgumentTypeError)
|
126
|
+
example 'unshift does not allow invalid types' do
|
127
|
+
expect{ @trow.unshift(HTML::Table::Caption.new) }.to raise_error(ArgumentTypeError)
|
111
128
|
expect{ @trow.unshift(nil) }.to raise_error(ArgumentTypeError)
|
112
|
-
|
129
|
+
end
|
130
|
+
|
131
|
+
example 'unshift allows proper types' do
|
132
|
+
expect{ @trow.unshift('test') }.not_to raise_error
|
113
133
|
expect{ @trow.unshift(7) }.not_to raise_error
|
114
|
-
expect{ @trow.unshift(Table::Row::Data.new) }.not_to raise_error
|
115
|
-
expect{ @trow.unshift(Table::Row::Header.new) }.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
|
116
147
|
end
|
117
148
|
|
118
|
-
example
|
119
|
-
expect
|
149
|
+
example 'end_tags?' do
|
150
|
+
expect(described_class).to respond_to(:end_tags?)
|
151
|
+
expect(described_class.end_tags?).to be(true)
|
120
152
|
end
|
121
153
|
|
122
|
-
example
|
123
|
-
expect(
|
124
|
-
expect
|
125
|
-
expect{ Table::Row.indent_level = "foo" }.to raise_error(ArgumentTypeError)
|
126
|
-
expect{ Table::Row.indent_level = 3 }.not_to raise_error
|
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
|
127
157
|
end
|
128
158
|
|
129
|
-
example
|
130
|
-
expect
|
131
|
-
expect
|
132
|
-
expect{ Table::Row.end_tags = "foo" }.to raise_error(ArgumentTypeError)
|
133
|
-
expect{ Table::Row.end_tags = 1 }.to raise_error(ArgumentTypeError)
|
134
|
-
expect{ Table::Row.end_tags = true }.not_to raise_error
|
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)
|
135
162
|
end
|
136
163
|
end
|