Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions lib/html/colgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ def []=(index, obj)
#
def push(*args)
args.each do |obj|
unless obj.is_a?(Table::ColGroup::Col)
msg = 'Can only assign Col objects to ColGroup class'
msg += ": #{obj.class}"
raise TypeError, msg
end
expect(obj, Table::ColGroup::Col)
super(obj)
end
end
Expand All @@ -76,22 +72,15 @@ def push(*args)
# to be pushed onto a ColGroup instance.
#
def <<(obj)
unless obj.is_a?(Table::ColGroup::Col)
msg = 'Can only assign Col objects to ColGroup class'
msg += ": #{obj.class}"
raise TypeError, msg
end
expect(obj, Table::ColGroup::Col)
super
end

# This method has been redefined to only allow ColGroup::Col objects
# to be unshifted onto a ColGroup instance.
#
def unshift(obj)
unless obj.is_a?(Table::ColGroup::Col)
msg = 'Can only assign Data and Header objects to Row class'
raise TypeError, msg
end
expect(obj, Table::ColGroup::Col)
super
end

Expand Down
35 changes: 21 additions & 14 deletions spec/colgroup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,60 @@
example 'constructor' do
expect{ described_class.new }.not_to raise_error
expect{ described_class.new(@col) }.not_to raise_error
expect{ described_class.new('foo') }.to raise_error(TypeError)
expect{ described_class.new('foo') }.to raise_error(ArgumentTypeError)
end

example 'basic' do
html = '<colgroup></colgroup>'
expect(@cgroup.html.gsub(/\s+/, '')).to eq(html)
end

example 'with_attributes' do
example 'with attributes' do
html = "<colgroup align='center' width='20%'></colgroup>"
@cgroup.align = 'center'
@cgroup.width = '20%'
expect(@cgroup.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
end

example 'push_single_col_element' do
example 'push single col element' do
html = '<colgroup><col></colgroup>'
@cgroup.push(@col)
expect(@cgroup.html.gsub(/\s{2,}|\n+/, '')).to eq(html)
end

example 'index_assignment_constraints' do
example 'index assignment constraints' do
expect{ @cgroup[0] = 'foo' }.to raise_error(ArgumentTypeError)
expect{ @cgroup[0] = 1 }.to raise_error(ArgumentTypeError)
expect{ @cgroup[1] = HTML::Table::Row.new }.to raise_error(ArgumentTypeError)
expect{ @cgroup[0] = HTML::Table::ColGroup::Col.new }.not_to raise_error
end

example 'push_constraints' do
expect{ @cgroup.push(7) }.to raise_error(TypeError)
expect{ @cgroup.push('hello') }.to raise_error(TypeError)
expect{ @cgroup.push(HTML::Table::Row.new) }.to raise_error(TypeError)
example 'push constraints' do
expect{ @cgroup.push(7) }.to raise_error(ArgumentTypeError)
expect{ @cgroup.push('hello') }.to raise_error(ArgumentTypeError)
expect{ @cgroup.push(HTML::Table::Row.new) }.to raise_error(ArgumentTypeError)
expect{ @cgroup.push(HTML::Table::ColGroup::Col.new) }.not_to raise_error
end

example 'double_arrow_constraints' do
expect{ @cgroup << 7 }.to raise_error(TypeError)
expect{ @cgroup << 'hello' }.to raise_error(TypeError)
expect{ @cgroup << HTML::Table::Row.new }.to raise_error(TypeError)
example 'double arrow constraints' do
expect{ @cgroup << 7 }.to raise_error(ArgumentTypeError)
expect{ @cgroup << 'hello' }.to raise_error(ArgumentTypeError)
expect{ @cgroup << HTML::Table::Row.new }.to raise_error(ArgumentTypeError)
expect{ @cgroup << HTML::Table::ColGroup::Col.new }.not_to raise_error
end

example 'configure_error' do
example 'unshift constraints' do
expect{ @cgroup.unshift(7) }.to raise_error(ArgumentTypeError)
expect{ @cgroup.unshift('hello') }.to raise_error(ArgumentTypeError)
expect{ @cgroup.unshift(HTML::Table::Row.new) }.to raise_error(ArgumentTypeError)
expect{ @cgroup.unshift(HTML::Table::ColGroup::Col.new) }.not_to raise_error
end

example 'configure error' do
expect{ @cgroup.configure(0, 0){} }.to raise_error(ArgumentError)
end

example 'content_error' do
example 'content error' do
expect{ @cgroup.content }.to raise_error(NoMethodError)
expect{ @cgroup.content = 'blah' }.to raise_error(NoMethodError)
end
Expand Down