ruport 1.6.3 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +11 -0
  3. data/CHANGELOG.md +38 -0
  4. data/HACKING +1 -17
  5. data/README.md +97 -0
  6. data/Rakefile +9 -50
  7. data/examples/add_row_table.rb +46 -0
  8. data/examples/data/wine.csv +255 -0
  9. data/examples/pdf_grouping.rb +39 -0
  10. data/examples/pdf_table.rb +28 -0
  11. data/examples/pdf_table_from_csv.rb +26 -0
  12. data/examples/pdf_table_prawn.rb +30 -0
  13. data/examples/pdf_table_simple.rb +13 -0
  14. data/examples/row_renderer.rb +1 -1
  15. data/examples/simple_pdf_lines.rb +1 -1
  16. data/examples/trac_ticket_status.rb +1 -1
  17. data/lib/ruport/controller.rb +17 -21
  18. data/lib/ruport/data/feeder.rb +2 -2
  19. data/lib/ruport/data/grouping.rb +8 -8
  20. data/lib/ruport/data/record.rb +4 -4
  21. data/lib/ruport/data/table.rb +318 -206
  22. data/lib/ruport/formatter/csv.rb +6 -7
  23. data/lib/ruport/formatter/html.rb +13 -11
  24. data/lib/ruport/formatter/markdown.rb +105 -0
  25. data/lib/ruport/formatter/prawn_pdf.rb +159 -0
  26. data/lib/ruport/formatter/template.rb +1 -1
  27. data/lib/ruport/formatter/text.rb +1 -1
  28. data/lib/ruport/formatter.rb +54 -54
  29. data/lib/ruport/version.rb +1 -1
  30. data/lib/ruport.rb +7 -23
  31. data/test/controller_test.rb +201 -225
  32. data/test/csv_formatter_test.rb +36 -36
  33. data/test/data_feeder_test.rb +64 -64
  34. data/test/expected_outputs/prawn_pdf_formatter/pdf_basic.pdf.test +265 -0
  35. data/test/grouping_test.rb +103 -102
  36. data/test/helpers.rb +29 -10
  37. data/test/html_formatter_test.rb +46 -46
  38. data/test/markdown_formatter_test.rb +142 -0
  39. data/test/prawn_pdf_formatter_test.rb +108 -0
  40. data/test/record_test.rb +91 -91
  41. data/test/samples/sales.csv +21 -0
  42. data/test/table_pivot_test.rb +77 -26
  43. data/test/table_test.rb +376 -354
  44. data/test/template_test.rb +13 -13
  45. data/test/text_formatter_test.rb +52 -52
  46. data/util/bench/data/table/bench_column_manip.rb +0 -1
  47. data/util/bench/data/table/bench_dup.rb +0 -1
  48. data/util/bench/data/table/bench_init.rb +1 -2
  49. data/util/bench/data/table/bench_manip.rb +0 -1
  50. data/util/bench/formatter/bench_csv.rb +0 -1
  51. data/util/bench/formatter/bench_html.rb +0 -1
  52. data/util/bench/formatter/bench_pdf.rb +0 -1
  53. data/util/bench/formatter/bench_text.rb +0 -1
  54. metadata +131 -82
  55. data/README +0 -114
  56. data/lib/ruport/formatter/pdf.rb +0 -591
  57. data/test/pdf_formatter_test.rb +0 -354
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby -w
1
+ #!/usr/bin/env ruby -w
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
3
3
 
4
4
  ###########################################################################
@@ -28,7 +28,7 @@ class OldSchoolController < Ruport::Controller
28
28
  end
29
29
  end
30
30
 
31
- end
31
+ end
32
32
 
33
33
  class VanillaController < Ruport::Controller
34
34
  stage :header,:body,:footer
@@ -39,9 +39,9 @@ end
39
39
  # that the hooks are being set up right. Perhaps these could
40
40
  # be replaced by mock objects in the future.
41
41
  class DummyText < Ruport::Formatter
42
-
42
+
43
43
  renders :text, :for => OldSchoolController
44
-
44
+
45
45
  def prepare_document
46
46
  output << "p"
47
47
  end
@@ -61,7 +61,7 @@ class DummyText < Ruport::Formatter
61
61
  def finalize_document
62
62
  output << "f"
63
63
  end
64
- end
64
+ end
65
65
 
66
66
  # This formatter modifies the (String) data object passed to it
67
67
  class Destructive < Ruport::Formatter
@@ -84,17 +84,17 @@ end
84
84
  class VanillaBinary < Ruport::Formatter
85
85
  renders :bin, :for => VanillaController
86
86
  save_as_binary_file
87
- end
87
+ end
88
88
 
89
89
  class SpecialFinalize < Ruport::Formatter
90
90
  renders :with_finalize, :for => VanillaController
91
-
91
+
92
92
  def finalize
93
93
  output << "I has been finalized"
94
94
  end
95
95
  end
96
96
 
97
- class TestController < Test::Unit::TestCase
97
+ class TestController < Minitest::Test
98
98
 
99
99
  def teardown
100
100
  Ruport::Formatter::Template.instance_variable_set(:@templates, nil)
@@ -103,60 +103,60 @@ class TestController < Test::Unit::TestCase
103
103
  def test_trivial
104
104
  actual = OldSchoolController.render(:text)
105
105
  assert_equal "header\nbody\nfooter\n", actual
106
- end
107
-
106
+ end
107
+
108
108
  context "when running a formatter with custom a finalize method" do
109
- def specify_finalize_method_should_be_called
110
- assert_equal "I has been finalized",
109
+ should "specify_finalize_method_should_be_called" do
110
+ assert_equal "I has been finalized",
111
111
  VanillaController.render_with_finalize
112
- end
112
+ end
113
113
  end
114
-
114
+
115
115
  context "when using templates" do
116
- def specify_apply_template_should_be_called
116
+ should "specify_apply_template_should_be_called" do
117
117
  Ruport::Formatter::Template.create(:stub)
118
- Table(%w[a b c]).to_csv(:template => :stub) do |r|
118
+ Ruport.Table(%w[a b c]).to_csv(:template => :stub) do |r|
119
119
  r.formatter.expects(:apply_template)
120
- end
121
- end
120
+ end
121
+ end
122
122
 
123
- def specify_undefined_template_should_throw_sensible_error
123
+ should "specify_undefined_template_should_throw_sensible_error" do
124
124
  assert_raises(Ruport::Formatter::TemplateNotDefined) do
125
- Table(%w[a b c]).to_csv(:template => :sub)
126
- end
125
+ Ruport.Table(%w[a b c]).to_csv(:template => :sub)
126
+ end
127
127
  end
128
128
  end
129
129
 
130
130
  context "when using default templates" do
131
- def specify_default_template_should_be_called
131
+ should "specify_default_template_should_be_called" do
132
132
  Ruport::Formatter::Template.create(:default)
133
- Table(%w[a b c]).to_csv do |r|
133
+ Ruport.Table(%w[a b c]).to_csv do |r|
134
134
  r.formatter.expects(:apply_template)
135
135
  assert r.formatter.template == Ruport::Formatter::Template[:default]
136
- end
136
+ end
137
137
  end
138
138
 
139
- def specify_specific_should_override_default
139
+ should "specify_specific_should_override_default" do
140
140
  Ruport::Formatter::Template.create(:default)
141
141
  Ruport::Formatter::Template.create(:stub)
142
- Table(%w[a b c]).to_csv(:template => :stub) do |r|
142
+ Ruport.Table(%w[a b c]).to_csv(:template => :stub) do |r|
143
143
  r.formatter.expects(:apply_template)
144
144
  assert r.formatter.template == Ruport::Formatter::Template[:stub]
145
- end
145
+ end
146
146
  end
147
147
 
148
- def specify_should_be_able_to_disable_templates
148
+ should "specify_should_be_able_to_disable_templates" do
149
149
  Ruport::Formatter::Template.create(:default)
150
- Table(%w[a b c]).to_csv(:template => false) do |r|
150
+ Ruport.Table(%w[a b c]).to_csv(:template => false) do |r|
151
151
  r.formatter.expects(:apply_template).never
152
- end
152
+ end
153
153
  end
154
154
  end
155
155
 
156
156
  def test_using_io
157
157
  require "stringio"
158
158
  out = StringIO.new
159
- a = OldSchoolController.render(:text) { |r| r.io = out }
159
+ OldSchoolController.render(:text) { |r| r.io = out }
160
160
  out.rewind
161
161
  assert_equal "header\nbody\nfooter\n", out.read
162
162
  assert_equal "", out.read
@@ -165,21 +165,21 @@ class TestController < Test::Unit::TestCase
165
165
  def test_using_file
166
166
  f = []
167
167
  File.expects(:open).yields(f)
168
- a = OldSchoolController.render(:text, :file => "foo.text")
168
+ OldSchoolController.render(:text, :file => "foo.text")
169
169
  assert_equal "header\nbody\nfooter\n", f[0]
170
-
170
+
171
171
  f = []
172
172
  File.expects(:open).with("blah","wb").yields(f)
173
- VanillaController.render(:bin, :file => "blah")
174
- end
175
-
176
- def test_using_file_via_rendering_tools
173
+ VanillaController.render(:bin, :file => "blah")
174
+ end
175
+
176
+ def test_using_file_via_rendering_tools
177
177
  f = []
178
- File.expects(:open).yields(f)
179
- Table(%w[a b c], :data => [[1,2,3],[4,5,6]]).save_as("foo.csv")
180
- assert_equal "a,b,c\n1,2,3\n4,5,6\n", f[0]
178
+ File.expects(:open).yields(f)
179
+ Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]]).save_as("foo.csv")
180
+ assert_equal "a,b,c\n1,2,3\n4,5,6\n", f[0]
181
181
  end
182
-
182
+
183
183
 
184
184
  def test_formats
185
185
  assert_equal( {}, Ruport::Controller.formats )
@@ -209,33 +209,33 @@ class TestController < Test::Unit::TestCase
209
209
 
210
210
  rend.formatter.clear_output
211
211
  assert_equal "", rend.formatter.output
212
- end
213
-
212
+ end
213
+
214
214
  def test_options_act_like_indifferent_hash
215
215
  opts = Ruport::Controller::Options.new
216
216
  opts.foo = "bar"
217
217
  assert_equal "bar", opts[:foo]
218
- assert_equal "bar", opts["foo"]
219
-
218
+ assert_equal "bar", opts["foo"]
219
+
220
220
  opts["f"] = "bar"
221
221
  assert_equal "bar", opts[:f]
222
222
  assert_equal "bar", opts.f
223
223
  assert_equal "bar", opts["f"]
224
-
224
+
225
225
  opts[:apple] = "banana"
226
226
  assert_equal "banana", opts.apple
227
227
  assert_equal "banana", opts["apple"]
228
228
  assert_equal "banana", opts[:apple]
229
- end
230
-
229
+ end
230
+
231
231
  end
232
232
 
233
233
 
234
- class TestFormatterUsingBuild < Test::Unit::TestCase
234
+ class TestFormatterUsingBuild < Minitest::Test
235
235
  # This formatter uses the build syntax
236
236
  class UsesBuild < Ruport::Formatter
237
- renders :text_using_build, :for => VanillaController
238
-
237
+ renders :text_using_build, :for => VanillaController
238
+
239
239
  build :header do
240
240
  output << "header\n"
241
241
  end
@@ -246,7 +246,7 @@ class TestFormatterUsingBuild < Test::Unit::TestCase
246
246
 
247
247
  build :footer do
248
248
  output << "footer\n"
249
- end
249
+ end
250
250
  end
251
251
 
252
252
  def test_should_render_using_build_syntax
@@ -261,25 +261,25 @@ class TestFormatterUsingBuild < Test::Unit::TestCase
261
261
  end
262
262
 
263
263
 
264
- class TestFormatterWithLayout < Test::Unit::TestCase
264
+ class TestFormatterWithLayout < Minitest::Test
265
265
  # This formatter is meant to check out a special case in Ruport's renderer,
266
266
  # in which a layout method is called and yielded to when defined
267
267
  class WithLayout < DummyText
268
- renders :text_with_layout, :for => VanillaController
269
-
270
- def layout
268
+ renders :text_with_layout, :for => VanillaController
269
+
270
+ def layout
271
271
  output << "---\n"
272
272
  yield
273
273
  output << "---\n"
274
274
  end
275
-
275
+
276
276
  end
277
277
 
278
278
  def test_layout
279
- assert_equal "---\nheader\nbody\nfooter\n---\n",
279
+ assert_equal "---\nheader\nbody\nfooter\n---\n",
280
280
  VanillaController.render_text_with_layout
281
281
  end
282
-
282
+
283
283
  def test_layout_disabled
284
284
  assert_equal "header\nbody\nfooter\n",
285
285
  VanillaController.render_text_with_layout(:layout => false)
@@ -288,7 +288,7 @@ class TestFormatterWithLayout < Test::Unit::TestCase
288
288
  end
289
289
 
290
290
 
291
- class TestControllerWithManyHooks < Test::Unit::TestCase
291
+ class TestControllerWithManyHooks < Minitest::Test
292
292
  # This provides a way to check several hooks that controllers supports
293
293
  class ControllerWithManyHooks < Ruport::Controller
294
294
  add_format DummyText, :text
@@ -305,30 +305,28 @@ class TestControllerWithManyHooks < Test::Unit::TestCase
305
305
  def setup
306
306
  options.apple = true
307
307
  end
308
-
309
308
  end
310
309
 
311
310
  def test_hash_options_setters
312
- a = ControllerWithManyHooks.render(:text, :subtitle => "foo",
313
- :subsubtitle => "bar") { |r|
311
+ ControllerWithManyHooks.render(:text, :subtitle => "foo", :subsubtitle => "bar") do |r|
314
312
  assert_equal "foo", r.options.subtitle
315
313
  assert_equal "bar", r.options.subsubtitle
316
- }
314
+ end
317
315
  end
318
316
 
319
317
  def test_data_accessors
320
- a = ControllerWithManyHooks.render(:text, :data => [1,2,4]) { |r|
321
- assert_equal [1,2,4], r.data
322
- }
323
-
324
- b = ControllerWithManyHooks.render_text(%w[a b c]) { |r|
325
- assert_equal %w[a b c], r.data
326
- }
327
-
328
- c = ControllerWithManyHooks.render_text(%w[a b f],:snapper => :red) { |r|
329
- assert_equal %w[a b f], r.data
330
- assert_equal :red, r.options.snapper
331
- }
318
+ ControllerWithManyHooks.render(:text, :data => [1,2,4]) do |r|
319
+ assert_equal [1,2,4], r.data
320
+ end
321
+
322
+ ControllerWithManyHooks.render_text(%w[a b c]) do |r|
323
+ assert_equal %w[a b c], r.data
324
+ end
325
+
326
+ ControllerWithManyHooks.render_text(%w[a b f],:snapper => :red) do |r|
327
+ assert_equal %w[a b f], r.data
328
+ assert_equal :red, r.options.snapper
329
+ end
332
330
  end
333
331
 
334
332
  def test_formatter_data_dup
@@ -341,7 +339,7 @@ class TestControllerWithManyHooks < Test::Unit::TestCase
341
339
  def test_stage_helper
342
340
  assert ControllerWithManyHooks.stages.include?('body')
343
341
  end
344
-
342
+
345
343
  def test_finalize_helper
346
344
  assert_equal :document, ControllerWithManyHooks.final_stage
347
345
  end
@@ -351,14 +349,14 @@ class TestControllerWithManyHooks < Test::Unit::TestCase
351
349
  end
352
350
 
353
351
  def test_finalize_again
354
- assert_raise(Ruport::Controller::StageAlreadyDefinedError) {
355
- ControllerWithManyHooks.finalize :report
352
+ assert_raises(Ruport::Controller::StageAlreadyDefinedError) {
353
+ ControllerWithManyHooks.finalize :report
356
354
  }
357
355
  end
358
356
 
359
357
  def test_prepare_again
360
- assert_raise(Ruport::Controller::StageAlreadyDefinedError) {
361
- ControllerWithManyHooks.prepare :foo
358
+ assert_raises(Ruport::Controller::StageAlreadyDefinedError) {
359
+ ControllerWithManyHooks.prepare :foo
362
360
  }
363
361
  end
364
362
 
@@ -385,13 +383,13 @@ class TestControllerWithManyHooks < Test::Unit::TestCase
385
383
  a = ControllerWithManyHooks.dup
386
384
  a.required_option :title
387
385
 
388
- assert_raise(Ruport::Controller::RequiredOptionNotSet) { a.render(:text) }
386
+ assert_raises(Ruport::Controller::RequiredOptionNotSet) { a.render(:text) }
389
387
  end
390
-
388
+
391
389
  end
392
390
 
393
391
 
394
- class TestControllerWithRunHook < Test::Unit::TestCase
392
+ class TestControllerWithRunHook < Minitest::Test
395
393
 
396
394
  class ControllerWithRunHook < Ruport::Controller
397
395
  add_format DummyText, :text
@@ -409,14 +407,14 @@ class TestControllerWithRunHook < Test::Unit::TestCase
409
407
  end
410
408
 
411
409
  def test_renderer_with_run_hooks
412
- assert_equal "|header\nbody\nfooter\n",
410
+ assert_equal "|header\nbody\nfooter\n",
413
411
  ControllerWithRunHook.render_text(:foo => "bar",:bar => "baz")
414
412
  end
415
413
 
416
414
  end
417
415
 
418
416
 
419
- class TestControllerWithHelperModule < Test::Unit::TestCase
417
+ class TestControllerWithHelperModule < Minitest::Test
420
418
 
421
419
  class ControllerWithHelperModule < VanillaController
422
420
 
@@ -427,7 +425,7 @@ class TestControllerWithHelperModule < Test::Unit::TestCase
427
425
  "Hello Dolly"
428
426
  end
429
427
  end
430
- end
428
+ end
431
429
 
432
430
  def test_renderer_helper_module
433
431
  ControllerWithHelperModule.render_stub do |r|
@@ -437,9 +435,9 @@ class TestControllerWithHelperModule < Test::Unit::TestCase
437
435
  end
438
436
 
439
437
 
440
- class TestMultiPurposeFormatter < Test::Unit::TestCase
438
+ class TestMultiPurposeFormatter < Minitest::Test
441
439
  # This provides a way to check the multi-format hooks for the Controller
442
- class MultiPurposeFormatter < Ruport::Formatter
440
+ class MultiPurposeFormatter < Ruport::Formatter
443
441
 
444
442
  renders [:html,:text], :for => VanillaController
445
443
 
@@ -447,7 +445,7 @@ class TestMultiPurposeFormatter < Test::Unit::TestCase
447
445
  a = 10
448
446
 
449
447
  text { output << "Foo: #{a}\n" }
450
- html { output << "<b>Foo: #{a}</b>\n" }
448
+ html { output << "<b>Foo: #{a}</b>\n" }
451
449
  end
452
450
 
453
451
  def build_body
@@ -456,7 +454,7 @@ class TestMultiPurposeFormatter < Test::Unit::TestCase
456
454
  html { output << "\n</pre>\n" }
457
455
  end
458
456
 
459
- end
457
+ end
460
458
 
461
459
  def test_multi_purpose
462
460
  text = VanillaController.render_text(:body_text => "foo")
@@ -471,12 +469,12 @@ class TestMultiPurposeFormatter < Test::Unit::TestCase
471
469
 
472
470
  a = MultiPurposeFormatter.new
473
471
  a.format = :html
474
-
472
+
475
473
  visited = false
476
474
  a.html { visited = true }
477
475
 
478
476
  assert visited
479
-
477
+
480
478
  visited = false
481
479
  a.text { visited = true }
482
480
  assert !visited
@@ -489,100 +487,100 @@ class TestMultiPurposeFormatter < Test::Unit::TestCase
489
487
  end
490
488
 
491
489
 
492
- class TestFormatterErbHelper < Test::Unit::TestCase
490
+ class TestFormatterErbHelper < Minitest::Test
493
491
  class ErbFormatter < Ruport::Formatter
494
-
492
+
495
493
  renders :terb, :for => VanillaController
496
-
497
- def build_body
494
+
495
+ def build_body
498
496
  # demonstrate local binding
499
- @foo = "bar"
497
+ @foo = "bar"
500
498
  if options.binding
501
- output << erb("Binding Override: <%= reverse %>",
502
- :binding => options.binding)
503
- else
504
- output << erb("Default Binding: <%= @foo %>")
505
- end
499
+ output << erb("Binding Override: <%= reverse.inspect %>",
500
+ :binding => options.binding)
501
+ else
502
+ output << erb("Default Binding: <%= @foo %>")
503
+ end
506
504
  end
507
-
505
+
508
506
  end
509
507
 
510
- #FIXME: need to test file
508
+ #FIXME: need to test file
511
509
 
512
510
  def test_self_bound
513
511
  assert_equal "Default Binding: bar", VanillaController.render_terb
514
512
  end
515
-
513
+
516
514
  def test_custom_bound
517
515
  a = [1,2,3]
518
516
  arr_binding = a.instance_eval { binding }
519
- assert_equal "Binding Override: 321",
517
+ assert_equal "Binding Override: [3, 2, 1]",
520
518
  VanillaController.render_terb(:binding => arr_binding)
521
519
  end
522
- end
520
+ end
521
+
523
522
 
523
+ class TestOptionReaders < Minitest::Test
524
524
 
525
- class TestOptionReaders < Test::Unit::TestCase
526
-
527
525
  class ControllerForCheckingOptionReaders < Ruport::Controller
528
- required_option :foo
529
- end
530
-
526
+ required_option :foo
527
+ end
528
+
531
529
  class ControllerForCheckingPassivity < Ruport::Controller
532
530
  def foo
533
531
  "apples"
534
532
  end
535
- required_option :foo
533
+ required_option :foo
536
534
  end
537
535
 
538
- def setup
539
- @renderer = ControllerForCheckingOptionReaders.new
540
- @renderer.formatter = Ruport::Formatter.new
541
-
536
+ def setup
537
+ @renderer = ControllerForCheckingOptionReaders.new
538
+ @renderer.formatter = Ruport::Formatter.new
539
+
542
540
  @passive = ControllerForCheckingPassivity.new
543
541
  @passive.formatter = Ruport::Formatter.new
544
542
  end
545
-
543
+
546
544
  def test_options_are_readable
547
545
  @renderer.foo = 5
548
546
  assert_equal 5, @renderer.foo
549
- end
550
-
547
+ end
548
+
551
549
  def test_methods_are_not_overridden
552
550
  @passive.foo = 5
553
551
  assert_equal "apples", @passive.foo
554
552
  assert_equal 5, @passive.options.foo
555
553
  assert_equal 5, @passive.formatter.options.foo
556
554
  end
557
-
555
+
558
556
  end
559
-
560
- class TestSetupOrdering < Test::Unit::TestCase
561
-
557
+
558
+ class TestSetupOrdering < Minitest::Test
559
+
562
560
  class ControllerWithSetup < Ruport::Controller
563
561
  stage :bar
564
562
  def setup
565
563
  options.foo.capitalize!
566
- end
567
- end
568
-
569
- class BasicFormatter < Ruport::Formatter
564
+ end
565
+ end
566
+
567
+ class BasicFormatter < Ruport::Formatter
570
568
  renders :text, :for => ControllerWithSetup
571
-
569
+
572
570
  def build_bar
573
571
  output << options.foo
574
572
  end
575
573
  end
576
-
574
+
577
575
  def test_render_hash_options_should_be_called_before_setup
578
576
  assert_equal "Hello", ControllerWithSetup.render_text(:foo => "hello")
579
- end
580
-
577
+ end
578
+
581
579
  def test_render_block_should_be_called_before_setup
582
- assert_equal "Hello",
580
+ assert_equal "Hello",
583
581
  ControllerWithSetup.render_text { |r| r.options.foo = "hello" }
584
582
  end
585
-
583
+
586
584
  end
587
585
 
588
586
  class CustomFormatter < Ruport::Formatter
@@ -608,7 +606,7 @@ class ControllerWithAnonymousFormatters < Ruport::Controller
608
606
  end
609
607
 
610
608
  formatter :pdf do
611
- build :report do
609
+ build :report do
612
610
  add_text "hello world"
613
611
  end
614
612
  end
@@ -630,24 +628,20 @@ class ControllerWithAnonymousFormatters < Ruport::Controller
630
628
 
631
629
  end
632
630
 
633
- class TestAnonymousFormatter < Test::Unit::TestCase
634
- context "When using built in Ruport formatters" do
631
+ class TestAnonymousFormatter < Minitest::Test
635
632
 
636
- def specify_text_formatter_shortcut_is_accessible
637
- assert_equal "Hello world", ControllerWithAnonymousFormatters.render_text
638
- assert_equal "1,2,3\n", ControllerWithAnonymousFormatters.render_csv
639
- assert_equal "<h1>Hi there</h1>", ControllerWithAnonymousFormatters.render_html
633
+ def test_text_formatter_shortcut_is_accessible
634
+ assert_equal "Hello world", ControllerWithAnonymousFormatters.render_text
635
+ assert_equal "1,2,3\n", ControllerWithAnonymousFormatters.render_csv
636
+ assert_equal "<h1>Hi there</h1>", ControllerWithAnonymousFormatters.render_html
637
+ if RUBY_VERSION < "1.9"
640
638
  assert_not_nil ControllerWithAnonymousFormatters.render_pdf
641
639
  end
642
-
643
640
  end
644
641
 
645
- context "When using custom formatters" do
646
- def specify_custom_formatter_shortcut_is_accessible
647
- assert_equal "This is Custom!", ControllerWithAnonymousFormatters.render_custom
648
- end
642
+ def test_custom_formatter_shortcut_is_accessible
643
+ assert_equal "This is Custom!", ControllerWithAnonymousFormatters.render_custom
649
644
  end
650
-
651
645
  end
652
646
 
653
647
  # Used to ensure that problems in controller code aren't mistakenly intercepted
@@ -663,106 +657,88 @@ class MisbehavingFormatter < Ruport::Formatter
663
657
  end
664
658
  end
665
659
 
666
- class TestMisbehavingController < Test::Unit::TestCase
660
+ class TestMisbehavingController < Minitest::Test
667
661
 
668
- context "using a controller that throws NoMethodError" do
669
- def specify_controller_errors_should_bubble_up
670
- assert_raises(NoMethodError) do
671
- MisbehavingController.render :text
672
- end
662
+ def test_controller_errors_should_bubble_up
663
+ assert_raises(NoMethodError) do
664
+ MisbehavingController.render :text
673
665
  end
674
666
  end
675
667
 
676
668
  end
677
669
 
678
- class TestControllerHooks < Test::Unit::TestCase
679
-
680
- context "when renderable_data omitted" do
681
-
682
- require "mocha"
670
+ class TestControllerHooks < Minitest::Test
683
671
 
684
- class DummyObject
685
- include Ruport::Controller::Hooks
686
- renders_as_table
687
- end
688
-
689
- def specify_should_return_self
690
- a = DummyObject.new
691
- rend = mock("renderer")
692
- rend.expects(:data=).with(a)
693
- Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend)
694
- a.as(:csv)
695
- end
672
+ require "mocha"
696
673
 
674
+ class DummyObject
675
+ include Ruport::Controller::Hooks
676
+ renders_as_table
697
677
  end
698
678
 
699
- context "when using renderable_data" do
700
-
701
- class DummyObject2
702
- include Ruport::Controller::Hooks
703
- renders_as_table
704
-
705
- def renderable_data(format)
706
- 1
707
- end
708
- end
709
-
710
- def specify_should_return_results_of_renderable_data
711
- a = DummyObject2.new
712
- rend = mock("renderer")
713
- rend.expects(:data=).with(1)
714
- Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend)
715
- a.as(:csv)
716
- end
679
+ def test_should_return_self
680
+ a = DummyObject.new
681
+ rend = mock("renderer")
682
+ rend.expects(:data=).with(a)
683
+ Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend)
684
+ a.as(:csv)
685
+ end
717
686
 
718
- class DummyObject3
719
- include Ruport::Controller::Hooks
720
- renders_as_table
721
-
722
- def renderable_data
723
- raise ArgumentError
724
- end
725
- end
687
+ class DummyObject2
688
+ include Ruport::Controller::Hooks
689
+ renders_as_table
726
690
 
727
- def specify_should_not_mask_errors
728
- assert_raises(ArgumentError) { DummyObject3.new.as(:csv) }
691
+ def renderable_data(_format)
692
+ 1
729
693
  end
694
+ end
730
695
 
731
- class DummyObject4
732
- include Ruport::Controller::Hooks
733
- renders_as_table
696
+ def test_should_return_results_of_renderable_data
697
+ a = DummyObject2.new
698
+ rend = mock("renderer")
699
+ rend.expects(:data=).with(1)
700
+ Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend)
701
+ a.as(:csv)
702
+ end
734
703
 
735
- def renderable_data(format)
736
- case format
737
- when :html
738
- 1
739
- when :csv
740
- 2
741
- end
742
- end
743
- end
704
+ class DummyObject3
705
+ include Ruport::Controller::Hooks
706
+ renders_as_table
744
707
 
745
- def specify_should_return_results_of_renderable_data_using_format
746
- a = DummyObject4.new
747
- rend = mock("renderer")
748
- rend.expects(:data=).with(2)
749
- Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend)
750
- a.as(:csv)
708
+ def renderable_data
709
+ raise ArgumentError
751
710
  end
711
+ end
752
712
 
753
- end
754
-
755
- context "when attempting to render a format that doesn't exist" do
713
+ def test_should_not_mask_errors
714
+ assert_raises(ArgumentError) { DummyObject3.new.as(:csv) }
715
+ end
756
716
 
757
- def specify_an_unknown_format_error_should_be_raised
717
+ class DummyObject4
718
+ include Ruport::Controller::Hooks
719
+ renders_as_table
758
720
 
759
- assert_raises(Ruport::Controller::UnknownFormatError) do
760
- Ruport::Controller.render_foo
721
+ def renderable_data(format)
722
+ case format
723
+ when :html
724
+ 1
725
+ when :csv
726
+ 2
761
727
  end
762
-
763
728
  end
764
729
  end
765
730
 
731
+ def test_should_return_results_of_renderable_data_using_format
732
+ a = DummyObject4.new
733
+ rend = mock("renderer")
734
+ rend.expects(:data=).with(2)
735
+ Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend)
736
+ a.as(:csv)
737
+ end
766
738
 
767
-
739
+ def test_an_unknown_format_error_should_be_raised
740
+ assert_raises(Ruport::Controller::UnknownFormatError) do
741
+ Ruport::Controller.render_foo
742
+ end
743
+ end
768
744
  end