require "spec_helper"
describe OpenXml::Docx::Properties::Columns do
include PropertyTestMacros
it_should_use tag: :cols, name: "columns"
context "when trying to add columns, it" do
before(:each) do
@instance = described_class.new
end
it "should raise an exception if the column to be added isn't a column at all" do
expect { instance << [] }.to raise_error(ArgumentError)
end
end
context "when there are no columns" do
before(:each) do
@instance = described_class.new
end
it "should not output any XML" do
expect(xml(instance)).to eq("")
end
end
context "when there are columns" do
before(:each) do
@instance = described_class.new
instance << OpenXml::Docx::Properties::Column.new(1234, 5678)
instance << OpenXml::Docx::Properties::Column.new(8765, 4321)
end
it "should output the correct XML" do
expect(xml(instance)).to eq("\n \n \n ")
end
end
for_attribute(:equal_width) do
before(:each) do
@instance = described_class.new
@instance << OpenXml::Docx::Properties::Column.new(1, 1)
end
context "when the value is true" do
before(:each) do
@value = true
end
it "should accept the value" do
expect { instance.send("#{attribute}=", value) }.to_not raise_error
end
it "should output the correct value" do
instance.send("#{attribute}=", value)
expect(xml(instance)).to eq("\n \n ")
end
end
for_attribute(:number) do
before(:each) do
@instance = described_class.new
@instance << OpenXml::Docx::Properties::Column.new(1, 1)
end
context "when the value is 1" do
before(:each) do
@value = 1
end
it "should accept the value" do
expect { instance.send("#{attribute}=", value) }.to_not raise_error
end
it "should output the correct value" do
instance.send("#{attribute}=", value)
expect(xml(instance)).to eq("\n \n ")
end
end
context "when the value is -1" do
before(:each) do
@value = -1
end
it "should accept the value" do
expect { instance.send("#{attribute}=", value) }.to_not raise_error
end
it "should output the correct value" do
instance.send("#{attribute}=", value)
expect(xml(instance)).to eq("\n \n ")
end
end
with_value(1.3) do
it_should_raise_an_exception
end
with_value(:a_lot) do
it_should_raise_an_exception
end
end
for_attribute(:separator) do
before(:each) do
@instance = described_class.new
@instance << OpenXml::Docx::Properties::Column.new(1, 1)
end
context "when the value is true" do
before(:each) do
@value = true
end
it "should accept the value" do
expect { instance.send("#{attribute}=", value) }.to_not raise_error
end
it "should output the correct value" do
instance.send("#{attribute}=", value)
expect(xml(instance)).to eq("\n \n ")
end
end
end
for_attribute(:space) do
before(:each) do
@instance = described_class.new
@instance << OpenXml::Docx::Properties::Column.new(1, 1)
end
context "when the value is 1" do
before(:each) do
@value = 1
end
it "should accept the value" do
expect { instance.send("#{attribute}=", value) }.to_not raise_error
end
it "should output the correct value" do
instance.send("#{attribute}=", value)
expect(xml(instance)).to eq("\n \n ")
end
end
context "when the value is -1" do
before(:each) do
@value = -1
end
it "should accept the value" do
expect { instance.send("#{attribute}=", value) }.to_not raise_error
end
it "should output the correct value" do
instance.send("#{attribute}=", value)
expect(xml(instance)).to eq("\n \n ")
end
end
with_value(1.3) do
it_should_raise_an_exception
end
with_value(:a_lot) do
it_should_raise_an_exception
end
end
end
end