xmlss 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/helper.rb CHANGED
@@ -1,13 +1,17 @@
1
- require 'rubygems'
2
- require 'test_belt'
3
- require 'test/env'
1
+ # this file is automatically required in when you require 'assert' in your tests
2
+ # put test helpers here
4
3
 
5
- class Test::Unit::TestCase
4
+ # add root dir to the load path
5
+ $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
6
+
7
+ require 'xmlss'
8
+
9
+ class Assert::Context
6
10
 
7
11
  class << self
8
12
 
9
13
  def should_build_node
10
- should_have_instance_methods :build_node
14
+ should have_instance_methods :build_node
11
15
  should "build it's node" do
12
16
  assert_nothing_raised do
13
17
  ::Nokogiri::XML::Builder.new do |builder|
@@ -18,18 +22,15 @@ class Test::Unit::TestCase
18
22
  end
19
23
 
20
24
  def should_build_no_attributes_by_default(klass)
21
- context "by default" do
22
- subject{ klass.new }
23
-
24
- should "have no element attributes" do
25
- assert_equal({}, subject.send(:build_attributes))
26
- end
25
+ should "have no element attributes" do
26
+ xmlthing = klass.new
27
+ assert_equal({}, xmlthing.send(:build_attributes))
27
28
  end
28
29
  end
29
30
 
30
31
  def should_have_style(klass)
31
- should_have_accessor :style_id
32
- should_have_reader :style_i_d
32
+ should have_accessor :style_id
33
+ should have_reader :style_i_d
33
34
 
34
35
  should "set the style default" do
35
36
  assert_equal nil, subject.style_id
@@ -40,10 +41,8 @@ class Test::Unit::TestCase
40
41
  assert_equal :poo, c.style_id
41
42
  assert_equal :poo, c.style_i_d
42
43
  end
43
-
44
-
45
44
  end
46
45
 
47
46
  end
48
47
 
49
- end
48
+ end
data/test/irb.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'assert/setup'
2
+
3
+ # this file is required in when the 'irb' rake test is run.
4
+ # b/c 'assert' is required above, the test helper will be
5
+ # required in.
6
+
7
+ # put any IRB setup code here
8
+
9
+ require 'xmlss'
10
+
@@ -1,26 +1,27 @@
1
- require "test/helper"
1
+ require "assert"
2
2
  require 'xmlss/item_set'
3
3
 
4
4
  module Xmlss
5
- class ItemSetTest < Test::Unit::TestCase
5
+ class ItemSetTest < Assert::Context
6
+ desc "Xmlss::ItemSet"
7
+ subject { ItemSet.new(:test) }
6
8
 
7
- context "Xmlss::ItemSet" do
8
- subject { ItemSet.new(:test) }
9
+ should have_reader :name
9
10
 
10
- should_have_reader :name
11
+ should "be an Array" do
12
+ assert_kind_of ::Array, subject
13
+ assert_respond_to :each, subject
14
+ assert_empty subject
15
+ end
11
16
 
12
- should "be an Array" do
13
- assert_kind_of ::Array, subject
14
- assert_respond_to subject, :each
15
- assert subject.empty?
16
- end
17
+ end
17
18
 
18
- context "for generating XML" do
19
- should_have_reader :xml
20
- should_build_node
21
- should_build_no_attributes_by_default(ItemSet)
22
- end
23
- end
19
+ class ItemSetXmlTest < ItemSetTest
20
+ desc "for generating XML"
24
21
 
22
+ should have_reader :xml
23
+ should_build_node
24
+ should_build_no_attributes_by_default(ItemSet)
25
25
  end
26
- end
26
+
27
+ end
data/test/row_test.rb CHANGED
@@ -1,67 +1,70 @@
1
- require "test/helper"
1
+ require "assert"
2
+ require 'xmlss/cell'
2
3
  require 'xmlss/row'
3
4
 
4
5
  module Xmlss
5
- class RowTest < Test::Unit::TestCase
6
+ class RowTest < Assert::Context
7
+ desc "Xmlss::Row"
8
+ before { @row = Row.new }
9
+ subject { @row }
6
10
 
7
- context "Xmlss::Row" do
8
- subject { Row.new }
11
+ should_have_style(Row)
12
+ should have_accessors :height, :auto_fit_height, :hidden
13
+ should have_accessor :cells
9
14
 
10
- should_have_style(Row)
11
- should_have_accessor :height, :auto_fit_height, :hidden
12
- should_have_accessor :cells
15
+ should "set it's defaults" do
16
+ assert_equal nil, subject.height
17
+ assert_equal false, subject.auto_fit_height
18
+ assert_equal false, subject.hidden
19
+ assert_equal [], subject.cells
20
+ end
13
21
 
14
- should "set it's defaults" do
15
- assert_equal nil, subject.height
16
- assert_equal false, subject.auto_fit_height
17
- assert_equal false, subject.hidden
18
- assert_equal [], subject.cells
19
- end
22
+ should "allow defining a cells at init" do
23
+ row = Row.new({
24
+ :cells => [Cell.new]
25
+ })
20
26
 
21
- should "allow defining a cells at init" do
22
- row = Row.new({
23
- :cells => [Cell.new]
24
- })
27
+ assert_equal 1, row.cells.size
28
+ assert_kind_of Cell, row.cells.first
29
+ end
25
30
 
26
- assert_equal 1, row.cells.size
27
- assert_kind_of Cell, row.cells.first
31
+ should "bark when setting non Numeric height" do
32
+ assert_raises ArgumentError do
33
+ Row.new({:height => "do it"})
28
34
  end
29
-
30
- should "bark when setting non Numeric height" do
31
- assert_raises ArgumentError do
32
- Row.new({:height => "do it"})
33
- end
34
- assert_nothing_raised do
35
- Row.new({:height => 2})
36
- end
37
- assert_nothing_raised do
38
- Row.new({:height => 3.5})
39
- end
35
+ assert_nothing_raised do
36
+ Row.new({:height => 2})
40
37
  end
41
-
42
- should "nil out height values that are < 0" do
43
- assert_equal nil, Row.new({:height => -1.2}).height
44
- assert_equal nil, Row.new({:height => -1}).height
45
- assert_equal 0, Row.new({:height => 0}).height
46
- assert_equal 1.2, Row.new({:height => 1.2}).height
38
+ assert_nothing_raised do
39
+ Row.new({:height => 3.5})
47
40
  end
41
+ end
48
42
 
43
+ should "nil out height values that are < 0" do
44
+ assert_equal nil, Row.new({:height => -1.2}).height
45
+ assert_equal nil, Row.new({:height => -1}).height
46
+ assert_equal 0, Row.new({:height => 0}).height
47
+ assert_equal 1.2, Row.new({:height => 1.2}).height
48
+ end
49
+ end
49
50
 
50
- context "when using cells" do
51
- before { subject.cells << Cell.new }
52
-
53
- should "should build a data object" do
54
- assert_equal 1, subject.cells.size
55
- assert_kind_of Cell, subject.cells.first
56
- end
57
- end
58
-
59
- context "for generating XML" do
60
- should_have_reader :xml
61
- should_build_node
62
- end
51
+ class RowCellsTest < RowTest
52
+ desc "when using cells"
53
+ before do
54
+ r = subject.cells << Cell.new
55
+ end
63
56
 
57
+ should "should build a data object" do
58
+ assert_equal 1, subject.cells.size
59
+ assert_kind_of Cell, subject.cells.first
64
60
  end
61
+ end
65
62
 
63
+ class RowXmlTest < RowTest
64
+ desc "for generating XML"
65
+
66
+ should have_reader :xml
67
+ should_build_node
66
68
  end
69
+
67
70
  end
@@ -1,12 +1,14 @@
1
- require "test/helper"
1
+ require "assert"
2
2
  require 'xmlss/style/alignment'
3
3
 
4
- class Xmlss::Style::AlignmentTest < Test::Unit::TestCase
4
+ module Xmlss::Style
5
+ class AlignmentTest < Assert::Context
6
+ desc "Xmlss::Style::Alignment"
7
+ before { @a = Alignment.new }
8
+ subject { @a }
5
9
 
6
- context "Xmlss::Style::Alignment" do
7
- subject { Xmlss::Style::Alignment.new }
10
+ should have_class_method :horizontal
8
11
 
9
- should_have_class_method :horizontal
10
12
  {
11
13
  :automatic => "Automatic",
12
14
  :left => "Left",
@@ -14,11 +16,12 @@ class Xmlss::Style::AlignmentTest < Test::Unit::TestCase
14
16
  :right => "Right"
15
17
  }.each do |horizontal, value|
16
18
  should "provide the value for the '#{horizontal}' horizontal" do
17
- assert_equal value, Xmlss::Style::Alignment.horizontal(horizontal)
19
+ assert_equal value, Alignment.horizontal(horizontal)
18
20
  end
19
21
  end
20
22
 
21
- should_have_class_method :vertical
23
+ should have_class_method :vertical
24
+
22
25
  {
23
26
  :automatic => "Automatic",
24
27
  :top => "Top",
@@ -26,12 +29,12 @@ class Xmlss::Style::AlignmentTest < Test::Unit::TestCase
26
29
  :bottom => "Bottom"
27
30
  }.each do |vertical, value|
28
31
  should "provide the value for the '#{vertical}' vertical" do
29
- assert_equal value, Xmlss::Style::Alignment.vertical(vertical)
32
+ assert_equal value, Alignment.vertical(vertical)
30
33
  end
31
34
  end
32
35
 
33
- should_have_accessors :horizontal, :vertical, :wrap_text, :rotate
34
- should_have_instance_methods :wrap_text?
36
+ should have_accessors :horizontal, :vertical, :wrap_text, :rotate
37
+ should have_instance_methods :wrap_text?
35
38
 
36
39
  should "set it's defaults" do
37
40
  assert_equal false, subject.wrap_text
@@ -40,68 +43,58 @@ class Xmlss::Style::AlignmentTest < Test::Unit::TestCase
40
43
  assert_equal nil, subject.rotate
41
44
  end
42
45
 
43
- context "that sets attributes at init" do
44
- before do
45
- @attrs = {
46
- :wrap_text => true,
47
- :horizontal => :center,
48
- :vertical => :bottom,
49
- :rotate => 90
50
- }
51
- @alignment = Xmlss::Style::Alignment.new(@attrs)
52
- end
53
- subject{ @alignment }
54
-
55
- should "should set them correctly" do
56
- @attrs.reject{|a, v| [:horizontal, :vertical].include?(a)}.each do |a,v|
57
- assert_equal v, subject.send(a)
58
- end
59
- assert_equal Xmlss::Style::Alignment.horizontal(:center), subject.horizontal
60
- assert_equal Xmlss::Style::Alignment.vertical(:bottom), subject.vertical
61
- end
62
- end
63
-
64
46
  should "reject invalid rotate alignments" do
65
- assert_equal nil, Xmlss::Style::Alignment.new({:rotate => 100}).rotate
66
- assert_equal 90, Xmlss::Style::Alignment.new({:rotate => 90}).rotate
67
- assert_equal 0, Xmlss::Style::Alignment.new({:rotate => 0}).rotate
68
- assert_equal -90, Xmlss::Style::Alignment.new({:rotate => -90}).rotate
69
- assert_equal nil, Xmlss::Style::Alignment.new({:rotate => -100}).rotate
70
- assert_equal 0, Xmlss::Style::Alignment.new({:rotate => 0.2}).rotate
71
- assert_equal 1, Xmlss::Style::Alignment.new({:rotate => 0.5}).rotate
72
- assert_equal nil, Xmlss::Style::Alignment.new({:rotate => "poo"}).rotate
73
- assert_equal nil, Xmlss::Style::Alignment.new({:rotate => :poo}).rotate
47
+ assert_equal nil, Alignment.new({:rotate => 100}).rotate
48
+ assert_equal 90, Alignment.new({:rotate => 90}).rotate
49
+ assert_equal 0, Alignment.new({:rotate => 0}).rotate
50
+ assert_equal -90, Alignment.new({:rotate => -90}).rotate
51
+ assert_equal nil, Alignment.new({:rotate => -100}).rotate
52
+ assert_equal 0, Alignment.new({:rotate => 0.2}).rotate
53
+ assert_equal 1, Alignment.new({:rotate => 0.5}).rotate
54
+ assert_equal nil, Alignment.new({:rotate => "poo"}).rotate
55
+ assert_equal nil, Alignment.new({:rotate => :poo}).rotate
74
56
  end
75
57
 
76
- context "that sets underline and alignment by key" do
77
- before do
78
- subject.horizontal = :left
79
- subject.vertical = :top
80
- end
58
+ should "should set them correctly" do
59
+ attrs = {
60
+ :wrap_text => true,
61
+ :horizontal => :center,
62
+ :vertical => :bottom,
63
+ :rotate => 90
64
+ }
65
+ alignment = Alignment.new(attrs)
81
66
 
82
- should "should returm it by value" do
83
- assert_equal Xmlss::Style::Alignment.horizontal(:left), subject.horizontal
84
- assert_equal Xmlss::Style::Alignment.vertical(:top), subject.vertical
67
+ attrs.reject{|a, v| [:horizontal, :vertical].include?(a)}.each do |a,v|
68
+ assert_equal v, alignment.send(a)
85
69
  end
70
+ assert_equal Alignment.horizontal(:center), alignment.horizontal
71
+ assert_equal Alignment.vertical(:bottom), alignment.vertical
86
72
  end
87
73
 
88
- context "that sets underline and alignment by value" do
89
- before do
90
- subject.horizontal = Xmlss::Style::Alignment.horizontal(:right)
91
- subject.vertical = Xmlss::Style::Alignment.vertical(:center)
92
- end
74
+ should "set attrs by key" do
75
+ subject.horizontal = :left
76
+ subject.vertical = :top
93
77
 
94
- should "should returm it by value" do
95
- assert_equal Xmlss::Style::Alignment.horizontal(:right), subject.horizontal
96
- assert_equal Xmlss::Style::Alignment.vertical(:center), subject.vertical
97
- end
78
+ assert_equal Alignment.horizontal(:left), subject.horizontal
79
+ assert_equal Alignment.vertical(:top), subject.vertical
98
80
  end
99
81
 
100
- context "for generating XML" do
101
- should_have_reader :xml
102
- should_build_node
103
- should_build_no_attributes_by_default(Xmlss::Style::Alignment)
82
+ should "set attrs by value" do
83
+ subject.horizontal = Alignment.horizontal(:right)
84
+ subject.vertical = Alignment.vertical(:center)
85
+
86
+ assert_equal Alignment.horizontal(:right), subject.horizontal
87
+ assert_equal Alignment.vertical(:center), subject.vertical
104
88
  end
105
89
 
106
90
  end
91
+
92
+ class AlignmentXmlTest < AlignmentTest
93
+ desc "for generating XML"
94
+
95
+ should have_reader :xml
96
+ should_build_node
97
+ should_build_no_attributes_by_default(Alignment)
98
+ end
99
+
107
100
  end
@@ -1,24 +1,27 @@
1
- require "test/helper"
1
+ require "assert"
2
2
  require 'xmlss/style/base'
3
3
 
4
- class Xmlss::Style::BaseTest < Test::Unit::TestCase
5
- context "Xmlss::Style::Base" do
6
- subject { Xmlss::Style::Base.new(:test) }
4
+ module Xmlss::Style
7
5
 
8
- should_have_reader :id, :i_d, :border
9
- should_have_accessors :borders, :alignment, :font
10
- should_have_accessors :interior, :number_format, :protection
6
+ class BaseTest < Assert::Context
7
+ desc "Xmlss::Style::Base"
8
+ before { @bs = Base.new(:test) }
9
+ subject { @bs }
10
+
11
+ should have_reader :id, :i_d, :border
12
+ should have_accessors :borders, :alignment, :font
13
+ should have_accessors :interior, :number_format, :protection
11
14
 
12
15
  should "bark if you don't init with an id" do
13
16
  assert_raises ArgumentError do
14
- Xmlss::Style::Base.new(nil)
17
+ Base.new(nil)
15
18
  end
16
19
  end
17
20
 
18
21
  should "force string ids" do
19
- assert_equal 'string', Xmlss::Style::Base.new('string').id
20
- assert_equal 'symbol', Xmlss::Style::Base.new(:symbol).id
21
- assert_equal '123', Xmlss::Style::Base.new(123).id
22
+ assert_equal 'string', Base.new('string').id
23
+ assert_equal 'symbol', Base.new(:symbol).id
24
+ assert_equal '123', Base.new(123).id
22
25
  end
23
26
 
24
27
  should "set it's defaults" do
@@ -31,96 +34,103 @@ class Xmlss::Style::BaseTest < Test::Unit::TestCase
31
34
  end
32
35
  end
33
36
 
34
- context "that sets alignment" do
35
- subject do
36
- Xmlss::Style::Base.new(:alignment) do
37
- alignment(
38
- :horizontal => :left,
39
- :vertical => :center,
40
- :wrap_text => true
41
- )
42
- end
43
- end
37
+ end
44
38
 
45
- should "should create an Alignment object" do
46
- assert_kind_of Xmlss::Style::Alignment, subject.alignment
47
- assert_equal true, subject.alignment.wrap_text
48
- assert_equal Xmlss::Style::Alignment.horizontal(:left), subject.alignment.horizontal
49
- assert_equal Xmlss::Style::Alignment.vertical(:center), subject.alignment.vertical
39
+ class SetAlignmentTest < Assert::Context
40
+ desc "that sets alignment"
41
+ before do
42
+ @s = Base.new(:alignment) do
43
+ alignment(
44
+ :horizontal => :left,
45
+ :vertical => :center,
46
+ :wrap_text => true
47
+ )
50
48
  end
51
49
  end
50
+ subject { @s }
52
51
 
53
- context "that sets borders" do
54
- subject do
55
- Xmlss::Style::Base.new(:borders) do
56
- border(:position => :left)
57
- border(:position => :right)
58
- end
59
- end
60
-
61
- should "should create Border objects and add them to its borders" do
62
- assert_equal 2, subject.borders.size
63
- assert_kind_of Xmlss::Style::Border, subject.borders.first
64
- assert_equal Xmlss::Style::Border.position(:left), subject.borders.first.position
65
- assert_equal Xmlss::Style::Border.position(:right), subject.borders.last.position
66
- end
52
+ should "create an Alignment object" do
53
+ assert_kind_of Alignment, subject.alignment
54
+ assert_equal true, subject.alignment.wrap_text
55
+ assert_equal Alignment.horizontal(:left), subject.alignment.horizontal
56
+ assert_equal Alignment.vertical(:center), subject.alignment.vertical
57
+ end
58
+ end
67
59
 
68
- should "error if manually setting borders to non ItemSet collection" do
69
- assert_raises ArgumentError do
70
- subject.borders = []
71
- end
60
+ class SetBorderTest < Assert::Context
61
+ desc "that sets borders"
62
+ before do
63
+ @s = Base.new(:borders) do
64
+ border(:position => :left)
65
+ border(:position => :right)
72
66
  end
73
67
  end
68
+ subject { @s }
74
69
 
75
- context "that sets font" do
76
- subject do
77
- Xmlss::Style::Base.new(:font) { font(:bold => true) }
78
- end
70
+ should "create Border objects and add them to its borders" do
71
+ assert_equal 2, subject.borders.size
72
+ assert_kind_of Border, subject.borders.first
73
+ assert_equal Border.position(:left), subject.borders.first.position
74
+ assert_equal Border.position(:right), subject.borders.last.position
75
+ end
79
76
 
80
- should "should create a Font object" do
81
- assert_kind_of Xmlss::Style::Font, subject.font
82
- assert subject.font.bold?
77
+ should "error if manually setting borders to non ItemSet collection" do
78
+ assert_raises ::ArgumentError do
79
+ subject.borders = []
83
80
  end
84
81
  end
82
+ end
85
83
 
86
- context "that sets interior" do
87
- subject do
88
- Xmlss::Style::Base.new(:interior) { interior(:color => "#000000") }
89
- end
84
+ class SetFontTest < Assert::Context
85
+ desc "that sets font"
86
+ before { @s = Base.new(:font) { font(:bold => true) } }
87
+ subject { @s }
90
88
 
91
- should "should create an Interior object" do
92
- assert_kind_of Xmlss::Style::Interior, subject.interior
93
- assert_equal "#000000", subject.interior.color
94
- end
89
+ should "should create a Font object" do
90
+ assert_kind_of Font, subject.font
91
+ assert subject.font.bold?
95
92
  end
93
+ end
96
94
 
97
- context "that sets number format" do
98
- subject do
99
- Xmlss::Style::Base.new(:number_format) { number_format(:format => "General") }
100
- end
95
+ class SetInteriorTest < Assert::Context
96
+ desc "that sets interior"
97
+ before { @s = Base.new(:interior) { interior(:color => "#000000") } }
98
+ subject { @s }
101
99
 
102
- should "should create a NumberFormat object" do
103
- assert_kind_of Xmlss::Style::NumberFormat, subject.number_format
104
- assert_equal "General", subject.number_format.format
105
- end
100
+ should "should create an Interior object" do
101
+ assert_kind_of Interior, subject.interior
102
+ assert_equal "#000000", subject.interior.color
106
103
  end
104
+ end
107
105
 
108
- context "that sets protection" do
109
- subject do
110
- Xmlss::Style::Base.new(:protection) { protection(:protect => true) }
111
- end
106
+ class SetNumberFormatTest < Assert::Context
107
+ desc "that sets number format"
108
+ before { @s = Base.new(:number_format) { number_format(:format => "General") } }
109
+ subject { @s }
112
110
 
113
- should "should create a Protection object" do
114
- assert_kind_of Xmlss::Style::Protection, subject.protection
115
- assert subject.protection.protected?
116
- end
111
+ should "should create a NumberFormat object" do
112
+ assert_kind_of NumberFormat, subject.number_format
113
+ assert_equal "General", subject.number_format.format
117
114
  end
115
+ end
116
+
117
+ class SetProtectionTest < Assert::Context
118
+ desc "that sets protection"
119
+ before { @s = Base.new(:protection) { protection(:protect => true) } }
120
+ subject { @s }
118
121
 
119
- context "for generating XML" do
120
- should_have_reader :xml
121
- should_build_node
122
- should_build_no_attributes_by_default(Xmlss::Style::Alignment)
122
+ should "should create a Protection object" do
123
+ assert_kind_of Protection, subject.protection
124
+ assert subject.protection.protected?
123
125
  end
126
+ end
127
+
128
+ class BaseXmlTest < BaseTest
129
+ desc "for generating XML"
124
130
 
131
+ should have_reader :xml
132
+ should_build_node
133
+ should_build_no_attributes_by_default(Xmlss::Style::Alignment)
125
134
  end
126
- end
135
+
136
+ end