osheet 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.bundle/config +2 -0
  2. data/.gitignore +6 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +33 -0
  5. data/README.rdoc +103 -61
  6. data/Rakefile +5 -56
  7. data/examples/basic.rb +73 -0
  8. data/examples/formats.rb +366 -0
  9. data/examples/trivial.rb +21 -0
  10. data/lib/osheet/associations.rb +62 -0
  11. data/lib/osheet/cell.rb +44 -10
  12. data/lib/osheet/column.rb +34 -7
  13. data/lib/osheet/format/accounting.rb +21 -0
  14. data/lib/osheet/format/currency.rb +23 -0
  15. data/lib/osheet/format/custom.rb +13 -0
  16. data/lib/osheet/format/datetime.rb +13 -0
  17. data/lib/osheet/format/fraction.rb +33 -0
  18. data/lib/osheet/format/general.rb +9 -0
  19. data/lib/osheet/format/number.rb +13 -0
  20. data/lib/osheet/format/numeric.rb +113 -0
  21. data/lib/osheet/format/percentage.rb +25 -0
  22. data/lib/osheet/format/scientific.rb +25 -0
  23. data/lib/osheet/format/special.rb +28 -0
  24. data/lib/osheet/format/text.rb +11 -0
  25. data/lib/osheet/format.rb +30 -0
  26. data/lib/osheet/row.rb +32 -7
  27. data/lib/osheet/style.rb +65 -0
  28. data/lib/osheet/style_set.rb +39 -0
  29. data/lib/osheet/styled_element.rb +18 -0
  30. data/lib/osheet/template.rb +32 -0
  31. data/lib/osheet/template_set.rb +57 -0
  32. data/lib/osheet/version.rb +1 -11
  33. data/lib/osheet/workbook.rb +32 -16
  34. data/lib/osheet/workbook_element.rb +21 -0
  35. data/lib/osheet/worksheet.rb +18 -20
  36. data/lib/osheet/worksheet_element.rb +15 -0
  37. data/lib/osheet/xmlss_writer/base.rb +42 -0
  38. data/lib/osheet/xmlss_writer/elements.rb +68 -0
  39. data/lib/osheet/xmlss_writer/styles.rb +176 -0
  40. data/lib/osheet/xmlss_writer.rb +1 -0
  41. data/lib/osheet.rb +7 -27
  42. data/osheet.gemspec +26 -0
  43. data/test/cell_test.rb +83 -0
  44. data/test/column_test.rb +81 -0
  45. data/test/env.rb +9 -0
  46. data/test/format/accounting_test.rb +158 -0
  47. data/test/format/currency_test.rb +158 -0
  48. data/test/format/custom_test.rb +22 -0
  49. data/test/format/datetime_test.rb +22 -0
  50. data/test/format/fraction_test.rb +84 -0
  51. data/test/format/general_test.rb +21 -0
  52. data/test/format/number_test.rb +93 -0
  53. data/test/format/percentage_test.rb +116 -0
  54. data/test/format/scientific_test.rb +116 -0
  55. data/test/format/special_test.rb +51 -0
  56. data/test/format/text_test.rb +18 -0
  57. data/test/format_test.rb +35 -0
  58. data/test/helper.rb +101 -0
  59. data/test/osheet_test.rb +14 -0
  60. data/test/row_test.rb +78 -0
  61. data/test/style_set_test.rb +50 -0
  62. data/test/style_test.rb +92 -0
  63. data/test/template_set_test.rb +76 -0
  64. data/test/template_test.rb +63 -0
  65. data/test/workbook_test.rb +142 -0
  66. data/test/worksheet_test.rb +77 -0
  67. data/test/xmlss_writer/base_test.rb +92 -0
  68. data/test/xmlss_writer/elements_test.rb +168 -0
  69. data/test/xmlss_writer/styles_test.rb +253 -0
  70. metadata +141 -30
  71. data/lib/osheet/base.rb +0 -95
@@ -0,0 +1,18 @@
1
+ require "test/helper"
2
+ require 'osheet/format/text'
3
+
4
+ module Osheet::Format
5
+
6
+ class TextTest < Test::Unit::TestCase
7
+ context "Text format" do
8
+ subject { Text.new }
9
+
10
+ should "generate a style strings and key" do
11
+ assert_equal "@", subject.style
12
+ assert_equal "text", subject.key
13
+ end
14
+
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,35 @@
1
+ require "test/helper"
2
+ require 'osheet/format'
3
+
4
+ module Osheet
5
+
6
+ class FormatTest < Test::Unit::TestCase
7
+ context "Osheet::Format" do
8
+ subject do
9
+ Format.new(:number, {
10
+ :decimal_places => 4,
11
+ :comma_separator => true,
12
+ :negative_numbers => :black_parenth
13
+ })
14
+ end
15
+
16
+ should "build format class instances" do
17
+ assert_kind_of Format::Number, subject
18
+ assert_equal 4, subject.decimal_places
19
+ assert_equal true, subject.comma_separator
20
+ assert_equal :black_parenth, subject.negative_numbers
21
+ end
22
+
23
+ should "error for invalid format types" do
24
+ assert_raises ArgumentError do
25
+ Format.new(:awesome, {})
26
+ end
27
+ assert_nothing_raised do
28
+ Format.new(:general)
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'rubygems'
2
+ require 'test_belt'
3
+ require 'test/env'
4
+
5
+ class Test::Unit::TestCase
6
+ class << self
7
+
8
+ def should_be_a_workbook_element(klass)
9
+ should_have_instance_methods :workbook, :styles, :templates
10
+ context "given a workbook with templates and styles" do
11
+ before do
12
+ @wkbk = Osheet::Workbook.new {
13
+ template(:column, :thing) {}
14
+ template(:row, :empty) {}
15
+ style('.title') {
16
+ font 14
17
+ }
18
+ style('.title', '.header') {
19
+ font :bold
20
+ }
21
+ }
22
+ @klass = klass.new(@wkbk)
23
+ end
24
+
25
+ should "be able to read the workbook and it's styles/templates" do
26
+ assert_equal @wkbk, @klass.workbook
27
+ assert_equal @wkbk.styles, @klass.styles
28
+ assert_equal @wkbk.templates, @klass.templates
29
+ end
30
+ end
31
+ end
32
+
33
+ def should_be_a_worksheet_element(klass)
34
+ should_have_instance_methods :worksheet, :columns
35
+ context "given a worksheet with columns" do
36
+ before do
37
+ @wksht = Osheet::Worksheet.new {
38
+ column {}
39
+ column {}
40
+ column {}
41
+ }
42
+ @klass = klass.new(nil, @wksht)
43
+ end
44
+
45
+ should "be able to read the worksheet and it's columns" do
46
+ assert_equal @wksht, @klass.worksheet
47
+ assert_equal @wksht.columns, @klass.columns
48
+ end
49
+ end
50
+ end
51
+
52
+ def should_be_a_styled_element(klass)
53
+ should_have_instance_methods :style_class
54
+
55
+ context "by default" do
56
+ before { @default = klass.new }
57
+ should "default an empty style class" do
58
+ assert_equal nil, @default.send(:instance_variable_get, "@style_class")
59
+ end
60
+ end
61
+
62
+ should "default an empty style class" do
63
+ styled = klass.new{ style_class "awesome thing" }
64
+ assert_equal "awesome thing", styled.send(:instance_variable_get, "@style_class")
65
+ end
66
+
67
+ should "verify the style class string" do
68
+ ['.thing', 'thing.thing', 'thing .thing > thing', 'thin>g'].each do |s|
69
+ assert_raises ArgumentError do
70
+ klass.new { style_class s }
71
+ end
72
+ end
73
+ ['thing', '#thing 123', 'thing-one thing_one'].each do |s|
74
+ assert_nothing_raised do
75
+ klass.new { style_class s }
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ def should_hm(klass, collection, item_klass)
82
+ should_have_reader collection
83
+ should_have_instance_method collection.to_s.sub(/s$/, '')
84
+
85
+ should "should initialize #{collection} and add them to it's collection" do
86
+ singular = collection.to_s.sub(/s$/, '')
87
+ thing = klass.new do
88
+ self.send(singular) {}
89
+ end
90
+
91
+ items = thing.send(:instance_variable_get, "@#{collection}")
92
+ assert_equal items, thing.send(collection)
93
+ assert !items.empty?
94
+ assert_equal 1, items.size
95
+ assert_kind_of item_klass, items.first
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+ end
@@ -0,0 +1,14 @@
1
+ require "test/helper"
2
+
3
+ class OsheetTest < Test::Unit::TestCase
4
+
5
+ context "Osheet" do
6
+
7
+ should "use Excel" do
8
+ assert_equal "application/vnd.ms-excel", Osheet::MIME_TYPE
9
+ assert_equal "Excel", Osheet::SPREADSHEET_TYPE
10
+ end
11
+
12
+ end
13
+
14
+ end
data/test/row_test.rb ADDED
@@ -0,0 +1,78 @@
1
+ require "test/helper"
2
+ require 'osheet/row'
3
+
4
+ module Osheet
5
+ class RowTest < Test::Unit::TestCase
6
+
7
+ context "Osheet::Row" do
8
+ subject { Row.new }
9
+
10
+ should_be_a_styled_element(Row)
11
+ should_be_a_worksheet_element(Row)
12
+ should_be_a_workbook_element(Row)
13
+
14
+ should_have_instance_method :height
15
+ should_have_instance_methods :autofit, :autofit?
16
+ should_have_instance_methods :hidden, :hidden?
17
+
18
+ should "set it's defaults" do
19
+ assert_equal nil, subject.send(:instance_variable_get, "@height")
20
+ assert_equal false, subject.send(:instance_variable_get, "@autofit")
21
+ assert !subject.autofit?
22
+ assert_equal false, subject.send(:instance_variable_get, "@hidden")
23
+ assert !subject.hidden?
24
+
25
+ assert_equal [], subject.cells
26
+ end
27
+
28
+ context "that has attributes" do
29
+ subject do
30
+ Row.new do
31
+ style_class "poo"
32
+ height 100
33
+ autofit true
34
+ hidden true
35
+ end
36
+ end
37
+
38
+ should "should set them correctly" do
39
+ assert_equal 100, subject.send(:instance_variable_get, "@height")
40
+ assert_equal true, subject.send(:instance_variable_get, "@autofit")
41
+ assert subject.autofit?
42
+ assert_equal true, subject.send(:instance_variable_get, "@hidden")
43
+ assert subject.hidden?
44
+ end
45
+
46
+ should "know it's height" do
47
+ subject.height(false)
48
+ assert_equal false, subject.height
49
+ subject.height(180)
50
+ assert_equal 180, subject.height
51
+ subject.height(nil)
52
+ assert_equal 180, subject.height
53
+ end
54
+
55
+ should "know it's attribute(s)" do
56
+ [:style_class, :height, :autofit, :hidden].each do |a|
57
+ assert subject.attributes.has_key?(a)
58
+ end
59
+ assert_equal 'poo', subject.attributes[:style_class]
60
+ assert_equal 100, subject.attributes[:height]
61
+ assert_equal true, subject.attributes[:autofit]
62
+ assert_equal true, subject.attributes[:hidden]
63
+ end
64
+
65
+ end
66
+
67
+ should "cast autofit and hidden to bool" do
68
+ rw = Row.new { autofit :true; hidden 'false'}
69
+ assert_kind_of ::TrueClass, rw.send(:instance_variable_get, "@autofit")
70
+ assert_kind_of ::TrueClass, rw.send(:instance_variable_get, "@hidden")
71
+ end
72
+
73
+ should_hm(Row, :cells, Cell)
74
+
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,50 @@
1
+ require "test/helper"
2
+ require "osheet/style_set"
3
+
4
+ module Osheet
5
+ class StyleSetTest < Test::Unit::TestCase
6
+
7
+ context "Osheet::StyleSet" do
8
+ subject { StyleSet.new }
9
+
10
+ should "be an Array" do
11
+ assert_kind_of ::Array, subject
12
+ end
13
+
14
+ should_have_reader :for
15
+
16
+ should "verify Template objs" do
17
+ assert_raises ArgumentError do
18
+ subject.send(:verify, {})
19
+ end
20
+ assert_nothing_raised do
21
+ subject.send(:verify, Style.new('.awesome') {})
22
+ end
23
+ end
24
+
25
+ should "be able to lookup styles by class" do
26
+ subject << (a = Style.new('.awesome') {})
27
+ subject << (at = Style.new('.awesome.thing') {})
28
+ subject << (b = Style.new('.boring') {})
29
+ subject << (bt = Style.new('.boring.thing') {})
30
+ subject << (a_b = Style.new('.awesome', '.boring') {})
31
+ subject << (t = Style.new('.thing') {})
32
+ subject << (s = Style.new('.stupid') {})
33
+
34
+ { 'awesome' => [a, a_b],
35
+ 'boring' => [b, a_b],
36
+ 'thing' => [t],
37
+ 'awesome thing' => [a, at, a_b, t],
38
+ 'thing awesome' => [a, at, a_b, t],
39
+ 'other' => []
40
+ }.each do |style_class, styles_set|
41
+ if style_class == 'awesome'
42
+ assert_equal styles_set, subject.for(style_class)
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,92 @@
1
+ require "test/helper"
2
+ require "osheet/style"
3
+
4
+ module Osheet
5
+ class StyleTest < Test::Unit::TestCase
6
+
7
+ context "Osheet::Style" do
8
+ subject { Style.new('.test') }
9
+
10
+ should_have_reader :selectors
11
+ should_have_instance_methods :align, :font, :bg
12
+ should_have_instance_methods :border, :border_left, :border_top, :border_right, :border_bottom
13
+ should_have_instance_method :match?
14
+
15
+ should "verify the selector" do
16
+ ['poo', '#poo', 'poo poo', 'poo > poo', :poo, 123].each do |s|
17
+ assert_raises ArgumentError do
18
+ Style.new(s)
19
+ end
20
+ end
21
+ ['.poo', '.poo.poo', '.poo-poo', '.poo_poo'].each do |s|
22
+ assert_nothing_raised do
23
+ Style.new(s)
24
+ end
25
+ end
26
+ end
27
+
28
+ should "set it's defaults" do
29
+ assert_equal 1, subject.selectors.size
30
+ assert_equal '.test', subject.selectors.first
31
+ [ :align, :font, :bg,
32
+ :border_left, :border_top, :border_right, :border_bottom
33
+ ].each do |a|
34
+ assert_equal [], subject.send(:instance_variable_get, "@#{a}")
35
+ end
36
+ end
37
+
38
+ should "know it's attribute(s)" do
39
+ [ :align, :font, :bg,
40
+ :border_left, :border_top, :border_right, :border_bottom
41
+ ].each do |a|
42
+ assert subject.attributes.has_key?(a)
43
+ end
44
+ end
45
+
46
+
47
+
48
+ [ :align, :font, :bg,
49
+ :border_left, :border_top, :border_right, :border_bottom
50
+ ].each do |a|
51
+ should "collect styles for #{a}" do
52
+ args = [1, "#FF0000", "Verdana", :love, 1.2]
53
+ subject.send(a, *args)
54
+ assert_equal args, subject.send(:instance_variable_get, "@#{a}")
55
+ end
56
+ end
57
+
58
+ should "set all border positions to the same styles using 'border' macro" do
59
+ args = [:thick, '#FF00FF', :dot]
60
+ subject.border *args
61
+ [ :border_left, :border_top, :border_right, :border_bottom].each do |a|
62
+ assert_equal args, subject.send(:instance_variable_get, "@#{a}")
63
+ end
64
+ end
65
+
66
+ should "match on style class strings" do
67
+ a = Style.new('.awesome') {}
68
+ at = Style.new('.awesome.thing') {}
69
+ b = Style.new('.boring') {}
70
+ bt = Style.new('.boring.thing') {}
71
+ a_b = Style.new('.awesome', '.boring') {}
72
+ t = Style.new('.thing') {}
73
+ s = Style.new('.stupid') {}
74
+
75
+ { 'awesome' => [a, a_b],
76
+ 'boring' => [b, a_b],
77
+ 'thing' => [t],
78
+ 'awesome thing' => [a, at, a_b, t],
79
+ 'thing awesome' => [a, at, a_b, t],
80
+ 'other' => []
81
+ }.each do |style_class, styles|
82
+ styles.each do |style|
83
+ assert_equal true, style.match?(style_class)
84
+ end
85
+ end
86
+ assert_equal false, a.match?('stupid')
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,76 @@
1
+ require "test/helper"
2
+ require "osheet/template_set"
3
+
4
+ module Osheet
5
+ class TemplateSetTest < Test::Unit::TestCase
6
+
7
+ context "Osheet::TemplateSet" do
8
+ subject { TemplateSet.new }
9
+
10
+ should "be a Hash" do
11
+ assert_kind_of ::Hash, subject
12
+ end
13
+
14
+ should_have_instance_method :<<
15
+ should_have_reader :get
16
+
17
+ should "key templates using their element and name" do
18
+ assert_equal [:row, :poo], subject.send(:key, :row, :poo)
19
+ assert_equal [:row, :row], subject.send(:key, :row, :row)
20
+ assert_equal ['row', 'poo'], subject.send(:template_key, Template.new(:row, :poo) {})
21
+ end
22
+
23
+ should "verify Template objs" do
24
+ assert_raises ArgumentError do
25
+ subject.send(:verify, {})
26
+ end
27
+ assert_nothing_raised do
28
+ subject.send(:verify, Template.new(:row, :poo) {})
29
+ end
30
+ end
31
+
32
+ should "init the key when verify templates" do
33
+ key = subject.send(:verify, Template.new(:row, :poo) {})
34
+ assert_equal ['row', 'poo'], key
35
+ assert_equal({
36
+ key.first => { key.last => nil }
37
+ }, subject)
38
+ end
39
+
40
+ should "push templates onto the set" do
41
+ assert_nothing_raised do
42
+ subject << Template.new(:row, :poo) {}
43
+ subject << Template.new(:row, :not_poo) {}
44
+ subject << Template.new(:column, :awesome) {}
45
+ subject << Template.new(:column, :not_awesome) {}
46
+ end
47
+
48
+ assert_equal 2, subject.keys.size
49
+ assert subject["row"]
50
+ assert_equal 2, subject["row"].keys.size
51
+ assert subject["row"]["poo"]
52
+ assert_kind_of Template, subject["row"]["poo"]
53
+ assert subject["row"]["not_poo"]
54
+ assert_kind_of Template, subject["row"]["not_poo"]
55
+ assert subject["column"]
56
+ assert_equal 2, subject["column"].keys.size
57
+ assert subject["column"]["awesome"]
58
+ assert_kind_of Template, subject["column"]["awesome"]
59
+ assert subject["column"]["not_awesome"]
60
+ assert_kind_of Template, subject["column"]["not_awesome"]
61
+ end
62
+
63
+ should "be able to lookup a template by element, name" do
64
+ t = Template.new(:row, :poo) {}
65
+ subject << t
66
+ assert_equal t, subject.get(:row, :poo)
67
+ assert_equal t, subject.get('row', 'poo')
68
+
69
+ assert_equal nil, subject.get(:row, :ugh)
70
+ assert_equal nil, subject.get(:col, :ugh)
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,63 @@
1
+ require "test/helper"
2
+ require "osheet/template"
3
+
4
+ module Osheet
5
+ class TemplateTest < Test::Unit::TestCase
6
+
7
+ context "Osheet::Template" do
8
+ subject do
9
+ Template.new('column', :thing) { |a_thing|
10
+ width 100
11
+ meta(
12
+ :thing => a_thing
13
+ )
14
+ }
15
+ end
16
+
17
+ should "define what elements it is valid for" do
18
+ assert_equal ['worksheet', 'column', 'row', 'cell'], Template::ELEMENTS
19
+ end
20
+
21
+ should_have_accessors :element, :name
22
+
23
+ should "be a Proc" do
24
+ assert_kind_of ::Proc, subject
25
+ end
26
+
27
+ should "convert the element and name args to string and store off" do
28
+ assert_equal 'column', subject.element
29
+ assert_equal 'thing', subject.name
30
+ end
31
+
32
+ should "verify the element argument" do
33
+ assert_raises ArgumentError do
34
+ Template.new({}, :poo) {}
35
+ end
36
+ assert_raises ArgumentError do
37
+ Template.new('workbook', :poo) {}
38
+ end
39
+ Template::ELEMENTS.each do |elem|
40
+ assert_nothing_raised do
41
+ Template.new(elem, :poo) {}
42
+ end
43
+ end
44
+ end
45
+
46
+ should "verify the name argument" do
47
+ assert_raises ArgumentError do
48
+ Template.new('worksheet', []) {}
49
+ end
50
+ assert_raises ArgumentError do
51
+ Template.new('worksheet', 1) {}
52
+ end
53
+ assert_nothing_raised do
54
+ Template.new('worksheet', :poo) {}
55
+ end
56
+ assert_nothing_raised do
57
+ Template.new('worksheet', 'poo') {}
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,142 @@
1
+ require "test/helper"
2
+ require 'osheet/workbook'
3
+
4
+ module Osheet
5
+ class WorkbookTest < Test::Unit::TestCase
6
+
7
+ context "Osheet::Workbook" do
8
+ subject { Workbook.new }
9
+
10
+ should_have_readers :styles, :templates
11
+ should_have_instance_methods :title, :style, :template, :attributes
12
+
13
+ should_hm(Workbook, :worksheets, Worksheet)
14
+
15
+ should "set it's defaults" do
16
+ assert_equal nil, subject.send(:instance_variable_get, "@title")
17
+ assert_equal [], subject.worksheets
18
+ assert_equal StyleSet.new, subject.styles
19
+ assert_equal TemplateSet.new, subject.templates
20
+ end
21
+
22
+ context "that has some columns and rows" do
23
+ subject do
24
+ Workbook.new {
25
+ title "The Poo"
26
+
27
+ worksheet {
28
+ name "Poo!"
29
+
30
+ column
31
+
32
+ row {
33
+ cell {
34
+ format :number
35
+ data 1
36
+ }
37
+ }
38
+ }
39
+ }
40
+ end
41
+
42
+ should "set it's title" do
43
+ assert_equal "The Poo", subject.send(:instance_variable_get, "@title")
44
+ end
45
+
46
+ should "know it's title" do
47
+ subject.title(false)
48
+ assert_equal false, subject.title
49
+ subject.title('la')
50
+ assert_equal 'la', subject.title
51
+ subject.title(nil)
52
+ assert_equal 'la', subject.title
53
+ end
54
+
55
+ should "set it's worksheets" do
56
+ worksheets = subject.send(:instance_variable_get, "@worksheets")
57
+ assert_equal 1, worksheets.size
58
+ assert_kind_of Worksheet, worksheets.first
59
+ end
60
+
61
+ should "know it's attribute(s)" do
62
+ [:title].each do |a|
63
+ assert subject.attributes.has_key?(a)
64
+ end
65
+ assert_equal "The Poo", subject.attributes[:title]
66
+ end
67
+ end
68
+
69
+ context "that defines styles" do
70
+ subject do
71
+ Workbook.new {
72
+ style('.test')
73
+ style('.test.awesome')
74
+ }
75
+ end
76
+
77
+ should "add them to it's styles" do
78
+ assert_equal 2, subject.styles.size
79
+ assert_equal 1, subject.styles.first.selectors.size
80
+ assert_equal '.test', subject.styles.first.selectors.first
81
+ assert_equal 1, subject.styles.last.selectors.size
82
+ assert_equal '.test.awesome', subject.styles.last.selectors.first
83
+ end
84
+ end
85
+
86
+ context "that defines templates" do
87
+ subject do
88
+ Workbook.new {
89
+ template(:column, :yo) { |color|
90
+ width 200
91
+ meta(:color => color)
92
+ }
93
+ template(:row, :yo_yo) {
94
+ height 500
95
+ }
96
+ template(:worksheet, :go) {
97
+ column(:yo, 'blue')
98
+ row(:yo_yo)
99
+ }
100
+ }
101
+ end
102
+
103
+ should "add them to it's templates" do
104
+ assert subject.templates
105
+ assert_kind_of TemplateSet, subject.templates
106
+ assert_equal 3, subject.templates.keys.size
107
+ assert_kind_of Template, subject.templates.get('column', 'yo')
108
+ assert_kind_of Template, subject.templates.get('row', 'yo_yo')
109
+ assert_kind_of Template, subject.templates.get('worksheet', 'go')
110
+
111
+ subject.worksheet(:go)
112
+ assert_equal 1, subject.worksheets.size
113
+ assert_equal 'blue', subject.worksheets.first.columns.first.meta[:color]
114
+ assert_equal 500, subject.worksheets.first.rows.first.attributes[:height]
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+
122
+ class WorkbookWriter < Test::Unit::TestCase
123
+ context "a workbook" do
124
+ subject do
125
+ Workbook.new {
126
+ style('.test')
127
+ style('.test.awesome')
128
+ }
129
+ end
130
+
131
+ should_have_instance_method :writer, :to_data, :to_file
132
+
133
+ should "provide a writer for itself" do
134
+ writer = subject.writer
135
+ assert writer
136
+ assert_kind_of XmlssWriter::Base, writer
137
+ end
138
+
139
+ end
140
+ end
141
+
142
+ end