thinreports 0.6.0.pre3 → 0.7.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.
Files changed (158) hide show
  1. data/README.rdoc +37 -32
  2. data/doc/yardoc_templates/default/layout/html/footer.erb +1 -1
  3. data/lib/thinreports.rb +2 -1
  4. data/lib/thinreports/config.rb +21 -0
  5. data/lib/thinreports/core/errors.rb +14 -1
  6. data/lib/thinreports/core/format/builder.rb +6 -1
  7. data/lib/thinreports/core/page.rb +6 -6
  8. data/lib/thinreports/core/shape.rb +8 -9
  9. data/lib/thinreports/core/shape/base/internal.rb +6 -12
  10. data/lib/thinreports/core/shape/basic.rb +3 -0
  11. data/lib/thinreports/core/shape/basic/block_format.rb +12 -0
  12. data/lib/thinreports/core/shape/basic/block_interface.rb +25 -0
  13. data/lib/thinreports/core/shape/basic/block_internal.rb +33 -0
  14. data/lib/thinreports/core/shape/basic/interface.rb +37 -11
  15. data/lib/thinreports/core/shape/basic/internal.rb +3 -12
  16. data/lib/thinreports/core/shape/image_block.rb +15 -0
  17. data/lib/thinreports/core/shape/image_block/format.rb +13 -0
  18. data/lib/thinreports/core/shape/image_block/interface.rb +19 -0
  19. data/lib/thinreports/core/shape/image_block/internal.rb +16 -0
  20. data/lib/thinreports/core/shape/list/events.rb +19 -2
  21. data/lib/thinreports/core/shape/list/manager.rb +17 -4
  22. data/lib/thinreports/core/shape/list/page.rb +2 -2
  23. data/lib/thinreports/core/shape/list/page_state.rb +4 -0
  24. data/lib/thinreports/core/shape/list/section_internal.rb +4 -0
  25. data/lib/thinreports/core/shape/manager/format.rb +1 -1
  26. data/lib/thinreports/core/shape/manager/internal.rb +24 -11
  27. data/lib/thinreports/core/shape/manager/target.rb +2 -2
  28. data/lib/thinreports/core/shape/style.rb +15 -0
  29. data/lib/thinreports/core/shape/style/base.rb +149 -0
  30. data/lib/thinreports/core/shape/style/basic.rb +17 -0
  31. data/lib/thinreports/core/shape/style/graphic.rb +60 -0
  32. data/lib/thinreports/core/shape/style/text.rb +138 -0
  33. data/lib/thinreports/core/shape/text/internal.rb +4 -0
  34. data/lib/thinreports/core/shape/text_block.rb +16 -0
  35. data/lib/thinreports/core/shape/{tblock → text_block}/format.rb +3 -3
  36. data/lib/thinreports/core/shape/{tblock → text_block}/formatter.rb +7 -7
  37. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/basic.rb +1 -1
  38. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/datetime.rb +1 -1
  39. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/number.rb +1 -1
  40. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/padding.rb +10 -8
  41. data/lib/thinreports/core/shape/{tblock → text_block}/interface.rb +2 -21
  42. data/lib/thinreports/core/shape/{tblock → text_block}/internal.rb +16 -10
  43. data/lib/thinreports/core/utils.rb +0 -8
  44. data/lib/thinreports/generator.rb +2 -2
  45. data/lib/thinreports/generator/configuration.rb +30 -0
  46. data/lib/thinreports/generator/pdf.rb +13 -10
  47. data/lib/thinreports/generator/pdf/configuration.rb +28 -0
  48. data/lib/thinreports/generator/pdf/document.rb +16 -56
  49. data/lib/thinreports/generator/pdf/document/draw_shape.rb +35 -17
  50. data/lib/thinreports/generator/pdf/document/font.rb +25 -9
  51. data/lib/thinreports/generator/pdf/document/graphics.rb +1 -1
  52. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +18 -4
  53. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +1 -1
  54. data/lib/thinreports/generator/pdf/document/graphics/image.rb +18 -1
  55. data/lib/thinreports/generator/pdf/document/graphics/text.rb +29 -6
  56. data/lib/thinreports/generator/pdf/document/page.rb +70 -0
  57. data/lib/thinreports/generator/pdf/document/parse_color.rb +1 -1
  58. data/lib/thinreports/generator/pdf/document/parse_svg.rb +1 -1
  59. data/lib/thinreports/generator/pdf/drawer.rb +1 -1
  60. data/lib/thinreports/generator/pdf/drawer/base.rb +5 -7
  61. data/lib/thinreports/generator/pdf/drawer/list.rb +4 -4
  62. data/lib/thinreports/generator/pdf/drawer/list_section.rb +8 -3
  63. data/lib/thinreports/generator/pdf/drawer/page.rb +10 -3
  64. data/lib/thinreports/generator/pdf/prawn_ext.rb +16 -21
  65. data/lib/thinreports/layout/format.rb +2 -2
  66. data/lib/thinreports/layout/version.rb +2 -2
  67. data/lib/thinreports/report/base.rb +68 -31
  68. data/tasks/test.rake +48 -4
  69. data/test/benchmark/basic_estimate.tlf +1 -0
  70. data/test/benchmark/bench_basic_estimate.rb +95 -0
  71. data/test/case/character_spacing/character_spacing.rb +7 -0
  72. data/test/case/character_spacing/character_spacing.tlf +1 -0
  73. data/test/case/dynamic_image/dynamic_image.rb +41 -0
  74. data/test/case/dynamic_image/dynamic_image.tlf +1 -0
  75. data/test/case/dynamic_image/img200x100.png +0 -0
  76. data/test/case/dynamic_image/img50x50.png +0 -0
  77. data/test/case/dynamic_style/dynamic_style.rb +154 -0
  78. data/test/case/dynamic_style/dynamic_style.tlf +1 -0
  79. data/test/case/dynamic_style/dynamic_style_in_list.tlf +1 -0
  80. data/test/case/dynamic_style/image.png +0 -0
  81. data/test/case/eudc/eudc.rb +20 -0
  82. data/test/case/eudc/eudc.tlf +1 -0
  83. data/test/case/eudc/eudc.ttf +0 -0
  84. data/test/case/helper.rb +27 -0
  85. data/test/case/hidden_shapes/hidden_shapes.rb +13 -0
  86. data/test/case/hidden_shapes/hidden_shapes.tlf +1 -0
  87. data/test/case/list_events/list_events.rb +32 -0
  88. data/test/case/list_events/list_events.tlf +1 -0
  89. data/test/case/list_header_inheriting/list_header_inheriting.rb +19 -0
  90. data/test/case/list_header_inheriting/list_header_inheriting.tlf +1 -0
  91. data/test/case/list_manual_generation/list_manual_generation.rb +24 -0
  92. data/test/case/list_manual_generation/list_manual_generation.tlf +1 -0
  93. data/test/case/single_line_tblock/single_line_tblock.rb +15 -0
  94. data/test/case/single_line_tblock/single_line_tblock.tlf +1 -0
  95. data/test/case/tblock_styles/tblock_styles.rb +27 -0
  96. data/test/case/tblock_styles/tblock_styles.tlf +1 -0
  97. data/test/case/text_align/text_align.rb +9 -0
  98. data/test/case/text_align/text_align.tlf +1 -0
  99. data/test/unit/core/shape/base/test_internal.rb +65 -85
  100. data/test/unit/core/shape/basic/test_basic_format.rb +30 -0
  101. data/test/unit/core/shape/basic/test_basic_interface.rb +27 -0
  102. data/test/unit/core/shape/basic/test_basic_internal.rb +55 -0
  103. data/test/unit/core/shape/basic/test_interface.rb +84 -36
  104. data/test/unit/core/shape/basic/test_internal.rb +32 -24
  105. data/test/unit/core/shape/image_block/test_format.rb +58 -0
  106. data/test/unit/core/shape/image_block/test_interface.rb +23 -0
  107. data/test/unit/core/shape/image_block/test_internal.rb +28 -0
  108. data/test/unit/core/shape/list/test_events.rb +19 -11
  109. data/test/unit/core/shape/list/test_manager.rb +112 -0
  110. data/test/unit/core/shape/list/test_page.rb +57 -0
  111. data/test/unit/core/shape/list/test_section_format.rb +1 -1
  112. data/test/unit/core/shape/list/test_section_interface.rb +37 -30
  113. data/test/unit/core/shape/list/test_section_internal.rb +39 -14
  114. data/test/unit/core/shape/manager/test_format.rb +12 -18
  115. data/test/unit/core/shape/manager/test_internal.rb +127 -93
  116. data/test/unit/core/shape/manager/test_target.rb +63 -56
  117. data/test/unit/core/shape/styles/test_base.rb +219 -0
  118. data/test/unit/core/shape/styles/test_basic.rb +24 -0
  119. data/test/unit/core/shape/styles/test_graphic.rb +69 -0
  120. data/test/unit/core/shape/styles/test_text.rb +318 -0
  121. data/test/unit/core/shape/{tblock → text_block}/formatter/test_basic.rb +2 -2
  122. data/test/unit/core/shape/{tblock → text_block}/formatter/test_datetime.rb +2 -2
  123. data/test/unit/core/shape/{tblock → text_block}/formatter/test_number.rb +2 -2
  124. data/test/unit/core/shape/{tblock → text_block}/formatter/test_padding.rb +11 -6
  125. data/test/unit/core/shape/text_block/test_format.rb +160 -0
  126. data/test/unit/core/shape/{tblock → text_block}/test_formatter.rb +2 -2
  127. data/test/unit/core/shape/text_block/test_interface.rb +46 -0
  128. data/test/unit/core/shape/text_block/test_internal.rb +128 -0
  129. data/test/unit/core/test_shape.rb +31 -6
  130. data/test/unit/data/basic_layout1.tlf +1 -0
  131. data/test/unit/data/basic_layout2.tlf +1 -0
  132. data/test/unit/data/basic_list_layout.tlf +1 -0
  133. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +81 -52
  134. data/test/unit/generator/pdf/document/graphics/test_text.rb +159 -0
  135. data/test/unit/generator/pdf/document/test_font.rb +21 -6
  136. data/test/unit/generator/pdf/document/test_graphics.rb +2 -2
  137. data/test/unit/generator/pdf/document/test_page.rb +95 -0
  138. data/test/unit/generator/pdf/document/test_parse_color.rb +2 -2
  139. data/test/unit/generator/pdf/test_configuration.rb +24 -0
  140. data/test/unit/generator/pdf/test_document.rb +28 -0
  141. data/test/unit/generator/test_configuration.rb +25 -0
  142. data/test/unit/generator/test_pdf.rb +19 -0
  143. data/test/unit/helper.rb +18 -0
  144. data/test/unit/layout/test_format.rb +24 -7
  145. data/test/unit/layout/test_version.rb +61 -27
  146. data/test/unit/report/test_base.rb +185 -89
  147. data/test/unit/test_config.rb +22 -0
  148. data/test/unit/test_report.rb +4 -4
  149. metadata +94 -43
  150. data/lib/thinreports/core/shape/tblock.rb +0 -16
  151. data/lib/thinreports/generator/pxd.rb +0 -75
  152. data/lib/thinreports/generator/pxd/helper.rb +0 -33
  153. data/lib/thinreports/generator/pxd/list_renderer.rb +0 -58
  154. data/lib/thinreports/generator/pxd/page_renderer.rb +0 -75
  155. data/tasks/clean.rake +0 -6
  156. data/test/unit/core/shape/tblock/test_format.rb +0 -125
  157. data/test/unit/core/shape/tblock/test_interface.rb +0 -40
  158. data/test/unit/core/shape/tblock/test_internal.rb +0 -139
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'test/unit/helper'
4
4
 
5
- class ThinReports::Generator::Pdf::TestParseColor < MiniTest::Unit::TestCase
5
+ class ThinReports::Generator::PDF::TestParseColor < MiniTest::Unit::TestCase
6
6
  include ThinReports::TestHelpers
7
7
 
8
8
  class TestColorParser
9
- include ThinReports::Generator::Pdf::ParseColor
9
+ include ThinReports::Generator::PDF::ParseColor
10
10
  end
11
11
 
12
12
  def setup
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Generator::PDF::TestConfiguration < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ def setup
9
+ @config = ThinReports::Generator::PDF::Configuration.new
10
+ end
11
+
12
+ def test_eudc_fonts_can_only_set_font_of_TTF
13
+ assert_raises ArgumentError do
14
+ @config.eudc_fonts = '/path/to/eudc'
15
+ end
16
+ assert_raises ArgumentError do
17
+ @config.eudc_fonts = %w( /path/to/eudc1.ttf /path/to/eudc2 )
18
+ end
19
+ end
20
+
21
+ def test_eudc_fonts_should_return_empty_array_by_default
22
+ assert_equal @config.eudc_fonts, []
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Generator::PDF::TestDocument < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ Document = ThinReports::Generator::PDF::Document
10
+
11
+ def test_new_without_page_creation
12
+ pdf = Document.new
13
+ assert_equal pdf.internal.page_count, 0
14
+ end
15
+
16
+ def test_new_with_zero_margin_canvas
17
+ pdf = Document.new
18
+ assert_equal pdf.internal.page.margins.values, [0, 0, 0, 0]
19
+ end
20
+
21
+ def test_new_with_security_settings
22
+ flexmock(Prawn::Document).new_instances.
23
+ should_receive(:encrypt_document).once.
24
+ with(:user_password => 'foo')
25
+
26
+ Document.new(:security => {:user_password => 'foo'})
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Generator::TestConfiguration < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ def setup
9
+ @config = ThinReports::Generator::Configuration.new
10
+ end
11
+
12
+ def test_pdf_should_return_configuration_of_pdf
13
+ assert_instance_of ThinReports::Generator::PDF::Configuration, @config.pdf
14
+ end
15
+
16
+ def test_default_should_return_pdf_by_default
17
+ assert_equal @config.default, :pdf
18
+ end
19
+
20
+ def test_default_should_raise_when_value_is_unknown_generator_type
21
+ assert_raises ThinReports::Errors::UnknownGeneratorType do
22
+ @config.default = :unknown
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Generator::TestPDF < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ PDF = ThinReports::Generator::PDF
10
+
11
+ def test_new_should_set_title_as_metadata
12
+ report = create_basic_report('basic_layout1.tlf') {|r| r.start_new_page }
13
+
14
+ flexmock(PDF::Document).should_receive(:new).
15
+ with(Hash, :Title => 'Basic Layout').once
16
+
17
+ PDF.new(report, {})
18
+ end
19
+ end
@@ -34,4 +34,22 @@ module ThinReports::TestHelpers
34
34
  skip('This test is not required Ruby 1.8 below.')
35
35
  end
36
36
  end
37
+
38
+ def create_basic_report(file, &block)
39
+ report = ThinReports::Report.new :layout => data_file(file)
40
+ block.call(report) if block_given?
41
+ report
42
+ end
43
+
44
+ def create_basic_layout(file)
45
+ ThinReports::Layout.new(data_file(file))
46
+ end
47
+
48
+ def create_basic_layout_format(file)
49
+ ThinReports::Layout::Format.build(data_file(file))
50
+ end
51
+
52
+ def data_file(filename)
53
+ File.join(File.dirname(__FILE__), 'data', filename)
54
+ end
37
55
  end
@@ -7,10 +7,7 @@ class ThinReports::Layout::TestFormat < MiniTest::Unit::TestCase
7
7
 
8
8
  TEST_SIMPLE_FORMAT = <<-'EOF'
9
9
  {
10
- "built-at":"",
11
10
  "version":"%s",
12
- "encoding":"utf-8",
13
- "updated-at":"20110528120710",
14
11
  "finger-print":-860627816,
15
12
  "config":{
16
13
  "title":"Sample Layout",
@@ -37,6 +34,26 @@ class ThinReports::Layout::TestFormat < MiniTest::Unit::TestCase
37
34
  Shape = ThinReports::Core::Shape
38
35
  Layout = ThinReports::Layout
39
36
 
37
+ def test_report_title
38
+ format = Layout::Format.new('config' => {'title' => 'Title'})
39
+ assert_equal format.report_title, 'Title'
40
+ end
41
+
42
+ def test_user_paper_type_return_true_when_type_is_user
43
+ format = Layout::Format.new('config' => {'page' => {'paper-type' => 'user'}})
44
+ assert_equal format.user_paper_type?, true
45
+ end
46
+
47
+ def test_user_paper_type_return_false_when_type_is_not_user
48
+ format = Layout::Format.new('config' => {'page' => {'paper-type' => 'A4'}})
49
+ assert_equal format.user_paper_type?, false
50
+ end
51
+
52
+ def test_last_version
53
+ format = Layout::Format.new('version' => '1.0')
54
+ assert_equal format.last_version, '1.0'
55
+ end
56
+
40
57
  def test_build_simple_format
41
58
  flexmock(Layout::Format).
42
59
  should_receive(:read_format_file).and_return(create_raw_format).once
@@ -77,12 +94,12 @@ class ThinReports::Layout::TestFormat < MiniTest::Unit::TestCase
77
94
  assert_same result1, result2
78
95
  end
79
96
 
80
- def test_build_raise_when_layout_file_is_incompatible
97
+ def test_build_should_raise_when_layout_file_is_incompatible
81
98
  original_rules = Layout::Version::REQUIRED_RULES.dup
82
- Layout::Version::REQUIRED_RULES.replace(['== 2.0.0'])
99
+ Layout::Version::REQUIRED_RULES.replace(['>= 0.6.0.pre3', '< 0.8.0'])
83
100
 
84
101
  flexmock(Layout::Format).
85
- should_receive(:read_format_file).and_return(create_raw_format('1.0.0'))
102
+ should_receive(:read_format_file).and_return(create_raw_format('0.6.0.pre2'))
86
103
 
87
104
  assert_raises ThinReports::Errors::IncompatibleLayoutFormat do
88
105
  Layout::Format.build('dummy.tlf')
@@ -92,7 +109,7 @@ class ThinReports::Layout::TestFormat < MiniTest::Unit::TestCase
92
109
  end
93
110
 
94
111
  def setup
95
- flexmock(Shape::Tblock::Format).
112
+ flexmock(Shape::TextBlock::Format).
96
113
  should_receive(:build).and_return {|f| flexmock(:id => f['id']) }
97
114
  flexmock(Shape::Basic::Format).
98
115
  should_receive(:build).and_return {|f| flexmock(:id => f['id']) }
@@ -8,45 +8,79 @@ class ThinReports::Layout::TestVersion < MiniTest::Unit::TestCase
8
8
  # Alias
9
9
  Version = ThinReports::Layout::Version
10
10
 
11
- def test_comparable_version
12
- assert_equal Version.comparable_version('0.6.0'), '0.6.0.99'
11
+ def test_comparable_version_should_add_99_when_the_given_version_is_not_PRE
12
+ assert_equal Version.comparable_version('0.7.0'), '0.7.0.99'
13
+ end
14
+
15
+ def test_comparable_version_should_map_pre_to_1_when_the_given_version_is_PRE
13
16
  assert_equal Version.comparable_version('0.6.0.pre'), '0.6.0.1'
17
+ end
18
+
19
+ def test_comparable_version_should_map_pre2_to_2_when_the_given_version_is_PRE2
14
20
  assert_equal Version.comparable_version('0.6.0.pre2'), '0.6.0.2'
15
21
  end
16
22
 
17
- def test_compare_with_simple_rule
18
- assert Version.compare('0.6.0', '== 0.6.0')
19
- refute Version.compare('0.6.0', '== 0.6.1')
20
-
21
- refute Version.compare('0.6.0', '> 0.6.0')
22
- assert Version.compare('0.6.1', '> 0.6.0')
23
- assert Version.compare('0.6.0', '> 0.5.9')
24
- assert Version.compare('0.6.0', '> 0.6.0.pre3')
25
- assert Version.compare('0.6.0.pre2', '> 0.6.0.pre')
26
-
27
- assert Version.compare('0.6.0.pre', '< 0.6.0.pre3')
28
-
29
- assert Version.compare('0.6.0', '>= 0.6.0')
30
- assert Version.compare('0.6.0', '<= 0.6.0')
23
+ def test_compare_with_equal_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
24
+ assert Version.compare('0.7.0', '== 0.7.0')
25
+ end
26
+
27
+ def test_compare_with_equal_rule_should_return_false_when_the_given_version_is_not_equal_to_the_version_of_rule
28
+ refute Version.compare('0.6.0.pre3', '== 0.6.0.pre2')
29
+ end
30
+
31
+ def test_compare_with_larger_rule_should_return_true_when_the_given_version_is_larger_than_the_version_of_rule
32
+ assert Version.compare('0.7.0', '> 0.6.0.pre3')
33
+ end
34
+
35
+ def test_compare_with_larger_rule_should_return_false_when_the_given_version_is_not_larger_than_the_version_of_rule
36
+ refute Version.compare('0.7.0', '> 0.7.0')
37
+ end
38
+
39
+ def test_compare_with_one_or_more_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
40
+ assert Version.compare('0.7.0', '>= 0.7.0')
41
+ end
42
+
43
+ def test_compare_with_one_or_more_rule_should_return_true_when_the_given_version_is_larger_than_the_version_of_rule
44
+ assert Version.compare('0.7.0', '>= 0.6.0.pre3')
45
+ end
46
+
47
+ def test_compare_with_one_or_more_rule_should_return_false_when_the_give_version_is_not_more_than_the_version_of_rule
48
+ refute Version.compare('0.6.0.pre3', '>= 0.7.0')
49
+ end
50
+
51
+ def test_compare_with_one_or_less_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
52
+ assert Version.compare('0.7.0', '<= 0.7.0')
31
53
  end
32
54
 
33
- def test_compare_with_multiple_rules
34
- assert Version.compare('0.6.0', '> 0.5.0', '< 1.0.0')
35
- refute Version.compare('0.6.5', '> 0.6.0', '< 0.6.4')
55
+ def test_compare_with_one_or_less_rule_should_return_true_when_the_given_version_is_smaller_than_the_version_of_rule
56
+ assert Version.compare('0.7.0', '<= 0.7.1')
36
57
  end
37
58
 
38
- def test_compatible?
39
- required_rules('== 0.6.0.pre3') do
40
- assert Version.compatible?('0.6.0.pre3')
59
+ def test_compare_with_one_or_less_rule_should_return_false_when_the_given_version_is_not_less_than_the_version_of_rule
60
+ refute Version.compare('0.7.0', '<= 0.6.0.pre3')
61
+ end
62
+
63
+ def test_inspect_required_rules_should_properly_return_an_inspection_of_rule_when_one_rule_is_given
64
+ required_rules('== 0.6.0') do
65
+ assert_equal Version.inspect_required_rules, '(== 0.6.0)'
41
66
  end
42
67
  end
43
68
 
44
- def test_required_rules_inspect
45
- required_rules('== 0.6.0.pre3') do
46
- assert_equal Version.required_rules_inspect, '(== 0.6.0.pre3)'
69
+ def test_inspect_required_rules_should_properly_return_an_inspection_of_rules_when_multiple_rules_are_given
70
+ required_rules('>= 0.6.0.pre3', '< 0.8.0') do
71
+ assert_equal Version.inspect_required_rules, '(>= 0.6.0.pre3 and < 0.8.0)'
47
72
  end
48
- required_rules('> 0.6.0', '< 0.7.0') do
49
- assert_equal Version.required_rules_inspect, '(> 0.6.0 and < 0.7.0)'
73
+ end
74
+
75
+ def test_compatible_asker_should_return_true_when_the_given_version_matches_REEQUIRED_RULES
76
+ required_rules('>= 0.6.0.pre3', '< 0.8.0') do
77
+ assert Version.compatible?('0.7.0')
78
+ end
79
+ end
80
+
81
+ def test_compatible_asker_should_return_false_when_the_given_version_does_not_matches_REQUIRED_RULES
82
+ required_rules('>= 0.6.0.pre3', '< 0.8.0') do
83
+ refute Version.compatible?('0.8.0')
50
84
  end
51
85
  end
52
86
 
@@ -12,176 +12,272 @@ class ThinReports::Report::TestBase < MiniTest::Unit::TestCase
12
12
  @report = Report::Base.new
13
13
  end
14
14
 
15
- def test_initialize_with_options
16
- flexmock(Report::Internal).
17
- should_receive(:new).with(Report::Base, {:layout => 'layout.tlf'}).
18
- and_return(flexmock('report_internal')).once
19
-
20
- report = Report::Base.new(:layout => 'layout.tlf')
21
- assert_equal report.internal.flexmock_name, 'report_internal'
15
+ def test_initialize_should_register_layout_as_default_when_layout_is_specified_as_the_option
16
+ report = Report::Base.new :layout => data_file('basic_layout1.tlf')
17
+ assert_equal report.default_layout.filename, data_file('basic_layout1.tlf')
18
+ end
19
+
20
+ def test_initialize_should_initialize_new_Report_without_default_layout
21
+ assert_nil @report.default_layout
22
22
  end
23
23
 
24
- def test_use_layout
25
- flexmock(@report.internal).
26
- should_receive(:register_layout).with('layout.tlf', {:default => true}).
27
- and_return(flexmock('layout_config')).once
24
+ def test_use_layout_should_register_default_layout_when_default_property_is_omitted
25
+ @report.use_layout(data_file('basic_layout1.tlf'))
28
26
 
29
- assert_equal @report.use_layout('layout.tlf', :default => true).flexmock_name,
30
- 'layout_config'
27
+ assert_equal @report.default_layout.filename, data_file('basic_layout1.tlf')
31
28
  end
32
29
 
33
- def test_start_new_page
34
- layout = flexmock('layout')
35
- layout.should_receive(:init_new_page).once
30
+ def test_use_layout_should_register_default_layout_when_default_property_is_true
31
+ @report.use_layout(data_file('basic_layout2.tlf'), :default => true)
36
32
 
37
- flexmock(@report.internal).
38
- should_receive(:load_layout).and_return(layout).once.
39
- should_receive(:add_page).and_return(flexmock('new_page')).once
33
+ assert_equal @report.default_layout.filename, data_file('basic_layout2.tlf')
34
+ end
35
+
36
+ def test_start_new_page_should_properly_create_a_new_Page_and_return
37
+ @report.use_layout(data_file('basic_layout1'))
40
38
 
41
- assert_equal @report.start_new_page.flexmock_name, 'new_page'
39
+ assert_instance_of ThinReports::Core::Page, @report.start_new_page
42
40
  end
43
41
 
44
- def test_start_new_page_raise_when_no_layout_registered_yet
42
+ def test_start_new_page_should_raise_when_the_layout_has_not_been_registered_yet
45
43
  assert_raises ThinReports::Errors::NoRegisteredLayoutFound do
46
44
  @report.start_new_page(:layout => :unknown)
47
45
  end
48
46
  end
49
47
 
50
- def test_add_blank_page
51
- blank_page = flexmock('blank_page')
48
+ def test_start_new_page_should_create_a_new_page_using_a_default_layout
49
+ @report.use_layout(data_file('basic_layout1.tlf'), :default => true)
52
50
 
53
- flexmock(ThinReports::Core::BlankPage).
54
- should_receive(:new).and_return(blank_page)
51
+ assert_equal @report.start_new_page.layout.filename, data_file('basic_layout1.tlf')
52
+ end
53
+
54
+ def test_start_new_page_should_create_a_new_page_using_a_layout_with_specified_id
55
+ @report.use_layout(data_file('basic_layout1.tlf'), :id => :foo)
55
56
 
56
- flexmock(@report.internal).
57
- should_receive(:add_page).with(blank_page)
57
+ assert_equal @report.start_new_page(:layout => :foo).layout.filename,
58
+ data_file('basic_layout1.tlf')
59
+ end
60
+
61
+ def test_start_new_page_should_create_a_new_page_using_a_specified_layoutfile
62
+ new_page = @report.start_new_page(:layout => data_file('basic_layout1.tlf'))
63
+ assert_equal new_page.layout.filename, data_file('basic_layout1.tlf')
64
+ end
65
+
66
+ def test_add_blank_page_should_properly_create_a_new_blank_page
67
+ @report.use_layout(data_file('basic_layout1'))
58
68
 
59
- @report.add_blank_page
69
+ assert_instance_of ThinReports::Core::BlankPage, @report.add_blank_page
60
70
  end
61
71
 
62
- def test_layout_with_nil_return_the_default_layout
63
- flexmock(@report.internal).
64
- should_receive(:default_layout).and_return(flexmock('default_layout'))
72
+ def test_layout_should_return_the_default_layout_with_no_arguments
73
+ @report.use_layout(data_file('basic_layout1.tlf'), :default => true)
65
74
 
66
- assert_equal @report.layout.flexmock_name, 'default_layout'
75
+ assert_equal @report.layout.filename, data_file('basic_layout1.tlf')
67
76
  end
68
77
 
69
- def test_layout_with_id_raise_when_no_layout_found
78
+ def test_layout_should_raise_when_the_specified_layout_is_not_found
70
79
  assert_raises ThinReports::Errors::UnknownLayoutId do
71
- @report.layout(:unknown)
80
+ @report.layout(:unknown_layout_id)
72
81
  end
73
82
  end
74
83
 
75
- def test_generate
76
- setup_generator do |g|
77
- g.should_receive(:generate).and_return('output').once
78
- end
79
- assert_equal @report.generate(:pdf, {:option => :value}), 'output'
84
+ def test_layout_should_return_the_layout_with_specified_id
85
+ @report.use_layout(data_file('basic_layout2.tlf'), :id => :foo)
86
+
87
+ assert_equal @report.layout(:foo).filename, data_file('basic_layout2.tlf')
80
88
  end
81
89
 
82
- def test_generate_file
83
- setup_generator do |g|
84
- g.should_receive(:generate_file).with(String).once
85
- end
86
- @report.generate_file(:pdf, 'output.pdf', {:option => :value})
90
+ def test_generate_should_properly_initialize_Generator_and_call_generate_method_when_type_is_specified
91
+ flexmock(ThinReports::Generator).
92
+ should_receive(:new).
93
+ with(:pdf, @report, {:option => :value}).
94
+ and_return(flexmock(:generate => 'Success')).once
95
+
96
+ assert_equal @report.generate(:pdf, :option => :value), 'Success'
87
97
  end
88
98
 
89
- def test_events
90
- flexmock(@report.internal).
91
- should_receive(:events).and_return(flexmock('report_events')).once
99
+ def test_generate_should_properly_initialize_Generator_and_call_generate_method_when_type_is_omitted
100
+ flexmock(ThinReports::Generator).
101
+ should_receive(:new).
102
+ with(:pdf, @report, {:option => :value}).
103
+ and_return(flexmock(:generate => 'Success')).once
92
104
 
93
- assert_equal @report.events.flexmock_name, 'report_events'
105
+ assert_equal @report.generate(:option => :value), 'Success'
94
106
  end
95
107
 
96
- def test_page
97
- flexmock(@report.internal).
98
- should_receive(:page).and_return(flexmock('current_page')).once
108
+ def test_generate_file_should_properly_initialize_Generator_and_call_generate_file_method_when_type_is_specified
109
+ generator = flexmock('generator')
110
+ generator.should_receive(:generate_file).with('output.pdf').once
99
111
 
100
- assert_equal @report.page.flexmock_name, 'current_page'
112
+ flexmock(ThinReports::Generator).
113
+ should_receive(:new).
114
+ with(:pdf, @report, {}).
115
+ and_return(generator).once
116
+
117
+ @report.generate_file(:pdf, 'output.pdf')
118
+ end
119
+
120
+ def test_generate_file_should_properly_initialize_Generator_and_call_generate_file_method_when_type_is_omitted
121
+ generator = flexmock('generator')
122
+ generator.should_receive(:generate_file).with('output.pdf').once
123
+
124
+ flexmock(ThinReports::Generator).
125
+ should_receive(:new).
126
+ with(:pdf, @report, {:option => :value}).
127
+ and_return(generator).once
128
+
129
+ @report.generate_file('output.pdf', :option => :value)
130
+ end
131
+
132
+ def test_events_should_return_Report_Events
133
+ assert_instance_of ThinReports::Report::Events, @report.events
134
+ end
135
+
136
+ def test_page_should_return_the_current_page
137
+ @report.use_layout(data_file('basic_layout1.tlf'))
138
+ @report.start_new_page
139
+
140
+ assert_instance_of ThinReports::Core::Page, @report.page
141
+ end
142
+
143
+ def test_page_count_should_return_total_page_count
144
+ @report.use_layout(data_file('basic_layout1.tlf'))
145
+ 2.times { @report.start_new_page }
146
+
147
+ assert_equal @report.page_count, 2
148
+ end
149
+
150
+ def test_finalize_should_finalize_report
151
+ @report.finalize
152
+ assert_equal @report.finalized?, true
101
153
  end
102
154
 
103
- def test_page_count
104
- assert_equal @report.page_count, 0
155
+ def test_finalized_asker_should_return_false_when_report_has_not_been_finalized_yet
156
+ assert_equal @report.finalized?, false
105
157
  end
106
158
 
107
- def test_finalize
159
+ def test_finalized_asker_should_return_true_when_report_is_already_finalized
108
160
  @report.finalize
109
161
  assert_equal @report.finalized?, true
110
162
  end
111
163
 
112
- def test_Base_create
164
+ def test_Base_create_should_finalize_report
113
165
  report = Report::Base.create do |r|
114
166
  assert_instance_of Report::Base, r
115
167
  end
116
168
  assert_equal report.finalized?, true
117
169
  end
118
170
 
119
- def test_Base_create_raise_when_no_block_given
171
+ def test_Base_create_should_raise_when_no_block_given
120
172
  assert_raises ArgumentError do
121
173
  Report::Base.create
122
174
  end
123
175
  end
124
176
 
125
- def test_Base_generate
177
+ def test_Base_generate_should_properly_generate_when_type_is_specified
126
178
  flexmock(Report::Base).new_instances.
127
- should_receive(:generate).with(:pdf, Hash).once
179
+ should_receive(:generate).
180
+ with(:pdf, :option => :value).once
128
181
 
129
182
  flexmock(Report::Base).
130
- should_receive(:create).with(Hash, Proc).
183
+ should_receive(:create).
184
+ with({:layout => 'layout.tlf'}, Proc).
131
185
  and_return(Report::Base.new).once
132
186
 
133
187
  Report::Base.generate(:pdf, :report => {:layout => 'layout.tlf'},
134
188
  :generator => {:option => :value}) {}
135
189
  end
136
190
 
137
- def test_Base_generate_raise_when_no_block_given
138
- assert_raises ArgumentError do
139
- Report::Base.generate(:pdf)
140
- end
191
+ def test_Base_generate_should_properly_generate_when_type_is_omitted
192
+ flexmock(Report::Base).new_instances.
193
+ should_receive(:generate).
194
+ with({}).once
195
+
196
+ flexmock(Report::Base).
197
+ should_receive(:create).
198
+ with({}, Proc).
199
+ and_return(Report::Base.new).once
200
+
201
+ Report::Base.generate {}
141
202
  end
142
203
 
143
- def test_Base_generate_file
204
+ def test_Base_generate_file_should_properly_generate_file_when_type_is_specified
144
205
  flexmock(Report::Base).new_instances.
145
- should_receive(:generate_file).with(:pdf, String, Hash).once
206
+ should_receive(:generate_file).
207
+ with(:pdf, 'output.pdf', {}).once
208
+
209
+ flexmock(Report::Base).
210
+ should_receive(:create).
211
+ with({:layout => 'layout.tlf'}, Proc).
212
+ and_return(Report::Base.new).once
146
213
 
214
+ Report::Base.generate_file(:pdf, 'output.pdf', :report => {:layout => 'layout.tlf'}) {}
215
+ end
216
+
217
+ def test_Base_generate_file_should_properly_generate_file_when_type_is_omitted
218
+ flexmock(Report::Base).new_instances.
219
+ should_receive(:generate_file).
220
+ with('output.pdf', :option => :value).once
221
+
147
222
  flexmock(Report::Base).
148
- should_receive(:create).with(Hash, Proc).
223
+ should_receive(:create).
224
+ with({}, Proc).
149
225
  and_return(Report::Base.new).once
150
226
 
151
- Report::Base.generate_file(:pdf, 'output.pdf', :report => {:layout => 'layout.tlf'},
152
- :generator => {:option => :value}) {}
227
+ Report::Base.generate_file('output.pdf', :generator => {:option => :value}) {}
153
228
  end
154
229
 
155
- def test_Base_generate_file_raise_when_no_block_given
230
+ def test_Base_generate_should_raise_when_no_block_given
231
+ assert_raises ArgumentError do
232
+ Report::Base.generate(:pdf)
233
+ end
234
+ end
235
+
236
+ def test_Base_generate_file_should_raise_when_no_block_given
156
237
  assert_raises ArgumentError do
157
238
  Report::Base.generate_file(:pdf, 'output.pdf')
158
239
  end
159
240
  end
160
241
 
161
- def test_Base_init_generate_params_with_empty_options
162
- Report::Base.send(:init_generate_params, options = {}) {}
163
- assert_equal options.values_at(:report, :generator), [{}, {}]
242
+ def test_Base_extract_options_should_return_as_report_option_the_value_which_has_report_in_a_key
243
+ report, generator = Report::Base.send(:extract_options!, [{:report => {:layout => 'hoge.tlf'}}])
244
+ assert_equal report[:layout], 'hoge.tlf'
164
245
  end
165
246
 
166
- def test_Base_init_generate_params_with_configured_options
167
- options = {:report => {:layout => 'layout.tlf'},
168
- :generator => {:option => :value}}
169
- Report::Base.send(:init_generate_params, options) {}
170
-
171
- assert_equal options[:report], {:layout => 'layout.tlf'}
172
- assert_equal options[:generator], {:option => :value}
247
+ def test_Base_extract_options_should_operate_an_argument_destructively
248
+ args = [:pdf, 'output.pdf', {:report => {:layout => 'foo.tlf'}}]
249
+ Report::Base.send(:extract_options!, args)
250
+ assert_equal args, [:pdf, 'output.pdf']
173
251
  end
174
252
 
175
- def test_Base_init_generate_params_raise_when_no_block_given
176
- assert_raises ArgumentError do
177
- Report::Base.send(:init_generate_params)
178
- end
253
+ def test_Base_extract_options_should_include_the_layout_key_in_the_report_option
254
+ report, generator = Report::Base.send(:extract_options!, [{:layout => 'hoge.tlf'}])
255
+ assert_equal report[:layout], 'hoge.tlf'
179
256
  end
180
257
 
181
- def setup_generator(&block)
182
- block.call(generator = flexmock('generator'))
183
-
184
- flexmock(ThinReports::Generator).
185
- should_receive(:new).with(:pdf, @report, Hash).and_return(generator)
258
+ def test_Base_extract_options_should_give_priority_to_the_value_of_the_layout_key_over_in_the_report_option
259
+ report, generator = Report::Base.send(:extract_options!,
260
+ [{:report => {:layout => 'foo.tlf'}, :layout => 'hoge.tlf'}])
261
+ assert_equal report[:layout], 'hoge.tlf'
262
+ end
263
+
264
+ def test_Base_extract_options_should_return_as_generator_option_the_value_which_has_generator_in_a_key
265
+ report, generator = Report::Base.send(:extract_options!,
266
+ [{:generator => {:option => 'value'}}])
267
+ assert_equal generator[:option], 'value'
268
+ end
269
+
270
+ def test_Base_extract_options_should_give_priority_to_the_value_of_other_keys_over_in_the_generator_option
271
+ report, generator = Report::Base.send(:extract_options!,
272
+ [{:generator => {:option => 'value1'}, :option => 'value2'}])
273
+ assert_equal generator[:option], 'value2'
274
+ end
275
+
276
+ def test_Base_extract_options_should_return_all_the_values_except_the_report_option_as_a_generator_option
277
+ report, generator = Report::Base.send(:extract_options!,
278
+ [{:report => {:layout => 'foo.tlf'}, :layout => 'hoge.tlf',
279
+ :generator_opt1 => 'value1', :generator_opt2 => 'value2'}])
280
+ assert_equal generator.values_at(:generator_opt1, :generator_opt2),
281
+ ['value1', 'value2']
186
282
  end
187
283
  end