ruport 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require "test/unit"
2
- require "ruport"
3
- class TestFormatText < Test::Unit::TestCase
2
+ require "ruport"
3
+
4
+ class TestRenderTextTable < Test::Unit::TestCase
4
5
 
5
6
  def test_basic
6
7
 
@@ -13,75 +14,92 @@ class TestFormatText < Test::Unit::TestCase
13
14
  assert_equal("#{tf}| a | b |\n#{tf}| 1 | 2 |\n| 3 | 4 |\n#{tf}", a)
14
15
 
15
16
  end
16
-
17
- def test_row_basic
18
- actual = Ruport::Renderer::Row.render_text { |r| r.data = [1,2,3] }
19
- assert_equal("| 1 | 2 | 3 |\n", actual)
20
- end
21
-
22
-
17
+
23
18
  def test_centering
24
19
  tf = "+---------+\n"
25
20
 
26
21
  a = [[1,2],[300,4]].to_table
27
22
  assert_equal( "#{tf}| 1 | 2 |\n| 300 | 4 |\n#{tf}",
28
- a.as(:text) { |e| e.options.alignment = :center })
23
+ a.to_text(:alignment => :center) )
29
24
 
30
25
  tf = "+------------+\n"
31
26
  a.column_names = %w[a bark]
32
27
  assert_equal("#{tf}| a | bark |\n#{tf}| 1 | 2 |\n"+
33
- "| 300 | 4 |\n#{tf}",
34
- a.as(:text) { |e| e.options.alignment = :center })
35
-
28
+ "| 300 | 4 |\n#{tf}", a.to_text(:alignment => :center) )
36
29
  end
37
30
 
38
31
  def test_justified
39
32
  tf = "+----------+\n"
40
33
  a = [[1,'Z'],[300,'BB']].to_table
41
- assert_equal "#{tf}| 1 | Z |\n| 300 | BB |\n#{tf}", a.to_s
34
+
35
+ # justified alignment can be set explicitly
36
+ assert_equal "#{tf}| 1 | Z |\n| 300 | BB |\n#{tf}",
37
+ a.to_text(:alignment => :justified)
38
+
39
+ # justified alignment is also default
40
+ assert_equal "#{tf}| 1 | Z |\n| 300 | BB |\n#{tf}", a.to_s
42
41
  end
43
42
 
44
43
  def test_wrapping
45
- a = [[1,2],[300,4]].to_table.as(:text) { |r|
46
- r.options { |l| l.table_width = 10 }
47
- }
48
-
44
+ a = [[1,2],[300,4]].to_table.to_text(:table_width => 10)
49
45
  assert_equal("+------->>\n| 1 | >>\n| 300 | >>\n+------->>\n",a)
50
46
  end
51
47
 
52
48
  def test_ignore_wrapping
53
- a = [[1,2],[300,4]].to_table.as(:text) { |r|
54
- r.options { |l|
55
- l.table_width = 10
56
- l.ignore_table_width = true
57
- }
58
- }
59
-
49
+ a = [[1,2],[300,4]].to_table.to_text(:table_width => 10,
50
+ :ignore_table_width => true )
60
51
  assert_equal("+---------+\n| 1 | 2 |\n| 300 | 4 |\n+---------+\n",a)
52
+ end
53
+
54
+ def test_render_empty_table
55
+ assert_raise(Ruport::FormatterError) { [].to_table.to_text }
56
+ assert_nothing_raised { Table(%w[a b c]).to_text }
57
+
58
+ a = Table(%w[a b c]).to_text
59
+ expected = "+-----------+\n"+
60
+ "| a | b | c |\n"+
61
+ "+-----------+\n"
62
+ assert_equal expected, a
61
63
  end
64
+
65
+ # -- BUG TRAPS ------------------------------
62
66
 
63
- def test_make_sure_this_damn_column_names_bug_dies_a_horrible_death!
67
+ def test_should_render_without_column_names
64
68
  a = [[1,2,3]].to_table.to_text
65
69
  expected = "+-----------+\n"+
66
70
  "| 1 | 2 | 3 |\n"+
67
71
  "+-----------+\n"
68
72
  assert_equal(expected,a)
73
+ end
74
+
75
+ end
76
+
69
77
 
78
+ class TestRenderTextRow < Test::Unit::TestCase
79
+
80
+ def test_row_basic
81
+ actual = Ruport::Renderer::Row.render_text(:data => [1,2,3])
82
+ assert_equal("| 1 | 2 | 3 |\n", actual)
70
83
  end
71
84
 
85
+ end
86
+
87
+
88
+ class TestRenderTextGroup < Test::Unit::TestCase
89
+
72
90
  def test_render_text_group
73
91
  group = Ruport::Data::Group.new(:name => 'test',
74
92
  :data => [ %w[is this more],
75
- %w[interesting chris carter]],
93
+ %w[interesting red snapper]],
76
94
  :column_names => %w[i hope so])
77
95
 
78
- actual = Ruport::Renderer::Group.render(:text, :data => group)
96
+ actual = Ruport::Renderer::Group.render_text(:data => group)
79
97
  expected = "test:\n\n"+
80
98
  "+------------------------------+\n"+
81
- "| i | hope | so |\n"+
99
+ "| i | hope | so |\n"+
82
100
  "+------------------------------+\n"+
83
- "| is | this | more |\n"+
84
- "| interesting | chris | carter |\n"+
101
+ "| is | this | more |\n"+
102
+ "| interesting | red | snapper |\n"+
85
103
  "+------------------------------+\n"
86
104
  assert_equal(expected, actual)
87
105
  end
@@ -89,36 +107,35 @@ class TestFormatText < Test::Unit::TestCase
89
107
  def test_render_text_group_without_headers
90
108
  group = Ruport::Data::Group.new(:name => 'test',
91
109
  :data => [ %w[is this more],
92
- %w[interesting chris carter]],
110
+ %w[interesting red snapper]],
93
111
  :column_names => %w[i hope so])
94
112
 
95
113
  actual = Ruport::Renderer::Group.render(:text, :data => group,
96
114
  :show_table_headers => false )
97
115
  expected = "test:\n\n"+
98
116
  "+------------------------------+\n"+
99
- "| is | this | more |\n"+
100
- "| interesting | chris | carter |\n"+
117
+ "| is | this | more |\n"+
118
+ "| interesting | red | snapper |\n"+
101
119
  "+------------------------------+\n"
102
120
  assert_equal(expected, actual)
103
- end
121
+ end
122
+ end
123
+
104
124
 
105
- def test_raise_error_on_empty_table
106
- assert_raise(RuntimeError) { [].to_table.to_text }
107
- assert_raise(RuntimeError) { [].to_table(%w[a b c]).to_text }
108
- end
125
+ class TestRenderTextGrouping < Test::Unit::TestCase
109
126
 
110
127
  def test_render_text_grouping
111
128
  table = Ruport::Data::Table.new(:data => [ %w[is this more],
112
- %w[interesting chris carter]],
129
+ %w[interesting red snapper]],
113
130
  :column_names => %w[i hope so])
114
131
  grouping = Grouping(table, :by => "i")
115
132
 
116
133
  actual = Ruport::Renderer::Grouping.render(:text, :data => grouping)
117
134
  expected = "interesting:\n\n"+
118
135
  "+----------------+\n"+
119
- "| hope | so |\n"+
136
+ "| hope | so |\n"+
120
137
  "+----------------+\n"+
121
- "| chris | carter |\n"+
138
+ "| red | snapper |\n"+
122
139
  "+----------------+\n\n"+
123
140
  "is:\n\n"+
124
141
  "+-------------+\n"+
@@ -134,7 +151,7 @@ class TestFormatText < Test::Unit::TestCase
134
151
 
135
152
  def test_render_text_grouping_without_headers
136
153
  table = Ruport::Data::Table.new(:data => [ %w[is this more],
137
- %w[interesting chris carter]],
154
+ %w[interesting red snapper]],
138
155
  :column_names => %w[i hope so])
139
156
  grouping = Grouping(table, :by => "i")
140
157
 
@@ -142,7 +159,7 @@ class TestFormatText < Test::Unit::TestCase
142
159
  :show_table_headers => false)
143
160
  expected = "interesting:\n\n"+
144
161
  "+----------------+\n"+
145
- "| chris | carter |\n"+
162
+ "| red | snapper |\n"+
146
163
  "+----------------+\n\n"+
147
164
  "is:\n\n"+
148
165
  "+-------------+\n"+
@@ -151,4 +168,4 @@ class TestFormatText < Test::Unit::TestCase
151
168
  assert_equal(expected, actual)
152
169
  end
153
170
 
154
- end
171
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: ruport
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.11.0
7
- date: 2007-05-01 00:00:00 -04:00
6
+ version: 0.12.0
7
+ date: 2007-05-08 00:00:00 -04:00
8
8
  summary: A generalized Ruby report generation and templating engine.
9
9
  require_paths:
10
10
  - lib