osheet 0.5.0 → 0.6.0

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.
@@ -0,0 +1,84 @@
1
+ require "test/helper"
2
+ require "osheet/partial_set"
3
+
4
+ module Osheet
5
+
6
+ class PartialSetTest < Test::Unit::TestCase
7
+ context "Osheet::PartialSet" do
8
+ subject { PartialSet.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 "verify set objs are partials" do
18
+ assert_raises ArgumentError do
19
+ subject.send(:verify, {})
20
+ end
21
+ assert_nothing_raised do
22
+ subject.send(:verify, Partial.new(:poo) {})
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ class PartialSetKeyTest < Test::Unit::TestCase
30
+ context "A partial set" do
31
+ subject { PartialSet.new }
32
+
33
+ should "key using name values" do
34
+ assert_equal 'poo', subject.send(:key, :poo)
35
+ end
36
+
37
+ should "key on partial objs" do
38
+ assert_equal 'poo', subject.send(:partial_key, Partial.new(:poo) {})
39
+ end
40
+
41
+ should "init the key in the set when verifying" do
42
+ key = subject.send(:verify, Partial.new(:thing) {})
43
+ assert_equal 'thing', key
44
+ assert_equal({'thing' => nil}, subject)
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ class PartialSetPushTest < Test::Unit::TestCase
51
+ context "A partial set" do
52
+ subject { PartialSet.new }
53
+ should "push partials onto the set" do
54
+ assert_nothing_raised do
55
+ subject << Partial.new(:poo) {}
56
+ subject << Partial.new(:not_poo) {}
57
+ subject << Partial.new(:awesome) {}
58
+ subject << Partial.new(:poo) {}
59
+ end
60
+
61
+ assert_equal 3, subject.keys.size
62
+ assert subject["poo"]
63
+ assert_kind_of Partial, subject["poo"]
64
+ end
65
+
66
+ end
67
+ end
68
+
69
+ class PartialSetLookupTest < Test::Unit::TestCase
70
+ context "A partial set" do
71
+ subject { PartialSet.new }
72
+
73
+ should "lookup a partial by name" do
74
+ p = Partial.new(:poo) {}
75
+ subject << p
76
+ assert_equal p, subject.get(:poo)
77
+ assert_equal p, subject.get('poo')
78
+ assert_equal nil, subject.get(:ugh)
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,66 @@
1
+ require "test/helper"
2
+ require "osheet/partial"
3
+
4
+ module Osheet
5
+ class PartialTest < Test::Unit::TestCase
6
+
7
+ context "Osheet::Partial" do
8
+ subject do
9
+ Partial.new(:thing) {}
10
+ end
11
+
12
+ should_have_accessor :name
13
+
14
+ should "be a Proc" do
15
+ assert_kind_of ::Proc, subject
16
+ end
17
+
18
+ should "convert the name arg to a string and store off" do
19
+ assert_equal 'thing', subject.name
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ class PartialNameTest < Test::Unit::TestCase
26
+ context "A named partial" do
27
+ should "verify the name argument" do
28
+ assert_raises ArgumentError do
29
+ Partial.new([]) {}
30
+ end
31
+ assert_raises ArgumentError do
32
+ Partial.new(1) {}
33
+ end
34
+ assert_nothing_raised do
35
+ Partial.new(:poo) {}
36
+ end
37
+ assert_nothing_raised do
38
+ Partial.new('poo') {}
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+ class PartialBindingTest < Test::Unit::TestCase
46
+ context "a partial defined w/ a block" do
47
+ should "access instance vars from that block's binding" do
48
+ @test = 'test thing'
49
+ @workbook = Workbook.new {
50
+ partial(:stuff) {
51
+ worksheet(:thing) { name @test }
52
+ }
53
+
54
+ add(:stuff)
55
+ }
56
+
57
+ assert !@workbook.worksheets.first.send(:instance_variable_get, "@test").nil?
58
+ assert_equal @test, @workbook.worksheets.first.send(:instance_variable_get, "@test")
59
+ assert_equal @test.object_id, @workbook.worksheets.first.send(:instance_variable_get, "@test").object_id
60
+ assert_equal @test, @workbook.worksheets.first.attributes[:name]
61
+ assert_equal @test.object_id, @workbook.worksheets.first.attributes[:name].object_id
62
+ end
63
+ end
64
+ end
65
+
66
+ end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- osheet (0.4.0)
4
+ osheet (0.5.0)
5
5
  enumeration (~> 1.1.0)
6
6
  xmlss (~> 0.2.0)
7
7
 
@@ -1,5 +1,3 @@
1
- # TODO: make instance vars available
2
-
3
1
  title "rails three test"
4
2
 
5
3
  worksheet {
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- osheet (0.4.0)
4
+ osheet (0.5.0)
5
5
  enumeration (~> 1.1.0)
6
6
  xmlss (~> 0.2.0)
7
7
 
data/test/row_test.rb CHANGED
@@ -2,8 +2,8 @@ require "test/helper"
2
2
  require 'osheet/row'
3
3
 
4
4
  module Osheet
5
- class RowTest < Test::Unit::TestCase
6
5
 
6
+ class RowTest < Test::Unit::TestCase
7
7
  context "Osheet::Row" do
8
8
  subject { Row.new }
9
9
 
@@ -16,6 +16,8 @@ module Osheet
16
16
  should_have_instance_methods :hidden, :hidden?
17
17
  should_have_instance_method :meta
18
18
 
19
+ should_hm(Row, :cells, Cell)
20
+
19
21
  should "set it's defaults" do
20
22
  assert_equal nil, subject.send(:get_ivar, "height")
21
23
  assert_equal false, subject.send(:get_ivar, "autofit")
@@ -27,47 +29,56 @@ module Osheet
27
29
  assert_equal nil, subject.meta
28
30
  end
29
31
 
30
- context "that has attributes" do
31
- subject do
32
- Row.new do
33
- style_class "poo"
34
- height 100
35
- autofit true
36
- hidden true
37
- meta(
38
- {}
39
- )
40
- end
41
- end
32
+ end
33
+ end
42
34
 
43
- should "should set them correctly" do
44
- assert_equal 100, subject.send(:get_ivar, "height")
45
- assert_equal true, subject.send(:get_ivar, "autofit")
46
- assert subject.autofit?
47
- assert_equal true, subject.send(:get_ivar, "hidden")
48
- assert subject.hidden?
49
- assert_equal({}, subject.meta)
35
+ class RowAttributeTest < Test::Unit::TestCase
36
+ context "a row that has attributes" do
37
+ subject do
38
+ Row.new do
39
+ style_class "poo"
40
+ height 100
41
+ autofit true
42
+ hidden true
43
+ meta(
44
+ {}
45
+ )
50
46
  end
47
+ end
51
48
 
52
- should "know it's height" do
53
- subject.height(false)
54
- assert_equal false, subject.height
55
- subject.height(180)
56
- assert_equal 180, subject.height
57
- subject.height(nil)
58
- assert_equal 180, subject.height
59
- end
49
+ should "should set them correctly" do
50
+ assert_equal 100, subject.send(:get_ivar, "height")
51
+ assert_equal true, subject.send(:get_ivar, "autofit")
52
+ assert subject.autofit?
53
+ assert_equal true, subject.send(:get_ivar, "hidden")
54
+ assert subject.hidden?
55
+ assert_equal({}, subject.meta)
56
+ end
60
57
 
61
- should "know it's attribute(s)" do
62
- [:style_class, :height, :autofit, :hidden].each do |a|
63
- assert subject.attributes.has_key?(a)
64
- end
65
- assert_equal 'poo', subject.attributes[:style_class]
66
- assert_equal 100, subject.attributes[:height]
67
- assert_equal true, subject.attributes[:autofit]
68
- assert_equal true, subject.attributes[:hidden]
58
+ should "know it's attribute(s)" do
59
+ [:style_class, :height, :autofit, :hidden].each do |a|
60
+ assert subject.attributes.has_key?(a)
69
61
  end
62
+ assert_equal 'poo', subject.attributes[:style_class]
63
+ assert_equal 100, subject.attributes[:height]
64
+ assert_equal true, subject.attributes[:autofit]
65
+ assert_equal true, subject.attributes[:hidden]
66
+ end
67
+
68
+ end
69
+ end
70
+
71
+ class RowDataTest < Test::Unit::TestCase
72
+ context "A row" do
73
+ subject { Row.new }
70
74
 
75
+ should "set it's height" do
76
+ subject.height(false)
77
+ assert_equal false, subject.height
78
+ subject.height(180)
79
+ assert_equal 180, subject.height
80
+ subject.height(nil)
81
+ assert_equal 180, subject.height
71
82
  end
72
83
 
73
84
  should "cast autofit and hidden to bool" do
@@ -76,10 +87,30 @@ module Osheet
76
87
  assert_kind_of ::TrueClass, rw.send(:get_ivar, "hidden")
77
88
  end
78
89
 
79
- should_hm(Row, :cells, Cell)
80
-
81
90
  end
91
+ end
92
+
93
+ class RowPartialTest < Test::Unit::TestCase
94
+ context "A workbook that defines column partials" do
95
+ subject do
96
+ Workbook.new {
97
+ partial(:row_stuff) {
98
+ height 200
99
+ meta 'awesome'
100
+ }
101
+
102
+ worksheet { row {
103
+ add :row_stuff
104
+ } }
105
+ }
106
+ end
82
107
 
108
+ should "add it's partials to it's markup" do
109
+ assert_equal 200, subject.worksheets.first.rows.first.height
110
+ assert_equal 'awesome', subject.worksheets.first.rows.first.meta
111
+ end
112
+
113
+ end
83
114
  end
84
115
 
85
116
  class RowBindingTest < Test::Unit::TestCase
data/test/style_test.rb CHANGED
@@ -2,8 +2,8 @@ require "test/helper"
2
2
  require "osheet/style"
3
3
 
4
4
  module Osheet
5
- class StyleTest < Test::Unit::TestCase
6
5
 
6
+ class StyleTest < Test::Unit::TestCase
7
7
  context "Osheet::Style" do
8
8
  subject { Style.new('.test') }
9
9
 
@@ -12,19 +12,6 @@ module Osheet
12
12
  should_have_instance_methods :border, :border_left, :border_top, :border_right, :border_bottom
13
13
  should_have_instance_method :match?
14
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
15
  should "set it's defaults" do
29
16
  assert_equal 1, subject.selectors.size
30
17
  assert_equal '.test', subject.selectors.first
@@ -43,7 +30,35 @@ module Osheet
43
30
  end
44
31
  end
45
32
 
33
+ end
34
+ end
35
+
36
+ class StyleSelectorTest < Test::Unit::TestCase
37
+ context "A Style" do
38
+ subject { Style.new('.test') }
39
+
40
+ should "complain about bad selectors" do
41
+ ['poo', '#poo', 'poo poo', 'poo > poo', :poo, 123].each do |s|
42
+ assert_raises ArgumentError do
43
+ Style.new(s)
44
+ end
45
+ end
46
+ end
47
+
48
+ should "not complain about good selectors" do
49
+ ['.poo', '.poo.poo', '.poo-poo', '.poo_poo'].each do |s|
50
+ assert_nothing_raised do
51
+ Style.new(s)
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+ end
46
58
 
59
+ class StyleCollectorTest < Test::Unit::TestCase
60
+ context "A Style" do
61
+ subject { Style.new }
47
62
 
48
63
  [ :align, :font, :bg,
49
64
  :border_left, :border_top, :border_right, :border_bottom
@@ -55,7 +70,7 @@ module Osheet
55
70
  end
56
71
  end
57
72
 
58
- should "set all border positions to the same styles using 'border' macro" do
73
+ should "set all border positions to the same styles using 'border' macro collector" do
59
74
  args = [:thick, '#FF00FF', :dot]
60
75
  subject.border *args
61
76
  [ :border_left, :border_top, :border_right, :border_bottom].each do |a|
@@ -63,6 +78,13 @@ module Osheet
63
78
  end
64
79
  end
65
80
 
81
+ end
82
+ end
83
+
84
+ class StyleMatcherTest < Test::Unit::TestCase
85
+ context "A Style" do
86
+ subject { Style.new }
87
+
66
88
  should "match on style class strings" do
67
89
  a = Style.new('.awesome') {}
68
90
  at = Style.new('.awesome.thing') {}
@@ -87,7 +109,6 @@ module Osheet
87
109
  end
88
110
 
89
111
  end
90
-
91
112
  end
92
113
 
93
114
  class StyleBindingTest < Test::Unit::TestCase
@@ -7,20 +7,11 @@ module Osheet
7
7
  context "Osheet::TemplateSet" do
8
8
  subject { TemplateSet.new }
9
9
 
10
- should "be a Hash" do
11
- assert_kind_of ::Hash, subject
10
+ should "be a PartialSet" do
11
+ assert_kind_of PartialSet, subject
12
12
  end
13
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
14
+ should "verify set objs are templates" do
24
15
  assert_raises ArgumentError do
25
16
  subject.send(:verify, {})
26
17
  end
@@ -29,7 +20,22 @@ module Osheet
29
20
  end
30
21
  end
31
22
 
32
- should "init the key when verify templates" do
23
+ end
24
+ end
25
+
26
+ class TemplateSetKeyTest < Test::Unit::TestCase
27
+ context "A template set" do
28
+ subject { TemplateSet.new }
29
+
30
+ should "key templates using an array of their element and name" do
31
+ assert_equal ['row','poo'], subject.send(:key, :row, :poo)
32
+ end
33
+
34
+ should "key on templates objs" do
35
+ assert_equal ['row', 'poo'], subject.send(:template_key, Template.new(:row, :poo) {})
36
+ end
37
+
38
+ should "init the key in the set when verifying" do
33
39
  key = subject.send(:verify, Template.new(:row, :poo) {})
34
40
  assert_equal ['row', 'poo'], key
35
41
  assert_equal({
@@ -37,6 +43,12 @@ module Osheet
37
43
  }, subject)
38
44
  end
39
45
 
46
+ end
47
+ end
48
+
49
+ class TemplateSetPushTest < Test::Unit::TestCase
50
+ context "A template set" do
51
+ subject { TemplateSet.new }
40
52
  should "push templates onto the set" do
41
53
  assert_nothing_raised do
42
54
  subject << Template.new(:row, :poo) {}
@@ -60,7 +72,14 @@ module Osheet
60
72
  assert_kind_of Template, subject["column"]["not_awesome"]
61
73
  end
62
74
 
63
- should "be able to lookup a template by element, name" do
75
+ end
76
+ end
77
+
78
+ class TemplateSetLookupTest < Test::Unit::TestCase
79
+ context "A template set" do
80
+ subject { TemplateSet.new }
81
+
82
+ should "lookup a template by element, name" do
64
83
  t = Template.new(:row, :poo) {}
65
84
  subject << t
66
85
  assert_equal t, subject.get(:row, :poo)
@@ -71,6 +90,6 @@ module Osheet
71
90
  end
72
91
 
73
92
  end
74
-
75
93
  end
94
+
76
95
  end
@@ -2,33 +2,32 @@ require "test/helper"
2
2
  require "osheet/template"
3
3
 
4
4
  module Osheet
5
- class TemplateTest < Test::Unit::TestCase
6
5
 
6
+ class TemplateTest < Test::Unit::TestCase
7
7
  context "Osheet::Template" do
8
8
  subject do
9
- Template.new('column', :thing) { |a_thing|
10
- width 100
11
- meta(
12
- :thing => a_thing
13
- )
14
- }
9
+ Template.new('column', :thing) {}
15
10
  end
16
11
 
17
12
  should "define what elements it is valid for" do
18
13
  assert_equal ['worksheet', 'column', 'row', 'cell'], Template::ELEMENTS
19
14
  end
20
15
 
21
- should_have_accessors :element, :name
16
+ should_have_accessor :element
22
17
 
23
- should "be a Proc" do
24
- assert_kind_of ::Proc, subject
18
+ should "be a Partial" do
19
+ assert_kind_of Partial, subject
25
20
  end
26
21
 
27
- should "convert the element and name args to string and store off" do
22
+ should "convert the element ars to string and store off" do
28
23
  assert_equal 'column', subject.element
29
- assert_equal 'thing', subject.name
30
24
  end
31
25
 
26
+ end
27
+ end
28
+
29
+ class TemplateElementTest < Test::Unit::TestCase
30
+ context "a template" do
32
31
  should "verify the element argument" do
33
32
  assert_raises ArgumentError do
34
33
  Template.new({}, :poo) {}
@@ -43,40 +42,25 @@ module Osheet
43
42
  end
44
43
  end
45
44
 
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
45
  end
61
-
62
46
  end
63
47
 
64
- class StyleBindingTest < Test::Unit::TestCase
65
- context "a template defined w/ a block" do
66
- should "access instance vars from that block's binding" do
67
- @test = 'test thing'
68
- @workbook = Workbook.new {
69
- template('worksheet', :thing) { name @test }
70
- worksheet(:thing)
71
- }
72
-
73
- assert !@workbook.worksheets.first.send(:instance_variable_get, "@test").nil?
74
- assert_equal @test, @workbook.worksheets.first.send(:instance_variable_get, "@test")
75
- assert_equal @test.object_id, @workbook.worksheets.first.send(:instance_variable_get, "@test").object_id
76
- assert_equal @test, @workbook.worksheets.first.attributes[:name]
77
- assert_equal @test.object_id, @workbook.worksheets.first.attributes[:name].object_id
78
- end
79
- end
80
- end
48
+ # class TemplateBindingTest < Test::Unit::TestCase
49
+ # context "a template defined w/ a block" do
50
+ # should "access instance vars from that block's binding" do
51
+ # @test = 'test thing'
52
+ # @workbook = Workbook.new {
53
+ # template('worksheet', :thing) { name @test }
54
+ # worksheet(:thing)
55
+ # }
56
+ #
57
+ # assert !@workbook.worksheets.first.send(:instance_variable_get, "@test").nil?
58
+ # assert_equal @test, @workbook.worksheets.first.send(:instance_variable_get, "@test")
59
+ # assert_equal @test.object_id, @workbook.worksheets.first.send(:instance_variable_get, "@test").object_id
60
+ # assert_equal @test, @workbook.worksheets.first.attributes[:name]
61
+ # assert_equal @test.object_id, @workbook.worksheets.first.attributes[:name].object_id
62
+ # end
63
+ # end
64
+ # end
81
65
 
82
66
  end