thinreports 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,227 +8,240 @@ class ThinReports::Report::TestInternal < MiniTest::Unit::TestCase
8
8
  # Alias
9
9
  Report = ThinReports::Report
10
10
 
11
- def setup
12
- # Setting for instance of Layout::Base as mock.
13
- layout = flexmock('layout_base')
14
- layout.should_receive(:config).and_return(flexmock('layout_configuration'))
15
-
16
- flexmock(ThinReports::Layout).
17
- should_receive(:new).and_return(layout)
11
+ def report
12
+ Report::Base.new
18
13
  end
19
-
20
- def test_initialize_with_default_layout
21
- report = init_report(:layout => 'default.tlf')
22
- assert_equal report.default_layout.flexmock_name, 'layout_base'
14
+
15
+ def sample_layout1
16
+ data_file('basic_layout1.tlf')
23
17
  end
24
-
25
- def test_register_layout_properly_set_the_default_layout
26
- report = init_report
27
- report.register_layout('default.tlf')
28
-
29
- assert_equal report.default_layout.flexmock_name, 'layout_base'
18
+
19
+ def sample_layout2
20
+ data_file('basic_layout2.tlf')
21
+ end
22
+
23
+ def test_layout_specified_in_new_method_should_be_defined_as_default_layout
24
+ internal = Report::Internal.new(report, :layout => sample_layout1)
25
+ assert_equal internal.default_layout.filename, sample_layout1
26
+ end
27
+
28
+ def test_register_layout_should_be_set_as_default_layout_when_options_are_omitted
29
+ internal = Report::Internal.new(report, {})
30
+ internal.register_layout(sample_layout1)
31
+
32
+ assert_equal internal.default_layout.filename, sample_layout1
30
33
  end
31
34
 
32
- def test_register_layout_properly_set_the_default_layout_with_option
33
- report = init_report
34
- report.register_layout('default.tlf', :default => true)
35
+ def test_register_layout_should_be_set_as_default_layout_when_default_option_is_true
36
+ internal = Report::Internal.new(report, {})
37
+ internal.register_layout(sample_layout1, :default => true)
35
38
 
36
- assert_equal report.default_layout.flexmock_name, 'layout_base'
39
+ assert_equal internal.default_layout.filename, sample_layout1
37
40
  end
38
41
 
39
- def test_register_layout_raise_when_default_layout_is_already_set
40
- assert_raises ArgumentError do
41
- init_report(:layout => 'default.tlf').register_layout('other.tlf')
42
- end
42
+ def test_register_layout_should_be_able_to_change_the_default_layout
43
+ internal = Report::Internal.new(report, :layout => sample_layout1)
44
+ internal.register_layout(sample_layout2, :default => true)
45
+
46
+ assert_equal internal.default_layout.filename, sample_layout2
43
47
  end
44
48
 
45
- def test_register_layout_properly_set_the_layout
46
- report = init_report
47
- report.register_layout('foo.tlf', :id => :foo)
48
-
49
- assert_equal report.layout_registry[:foo].flexmock_name, 'layout_base'
49
+ def test_register_layout_should_be_set_as_with_id_when_id_option_is_set
50
+ internal = Report::Internal.new(report, {})
51
+ internal.register_layout(sample_layout1, :id => :foo)
52
+
53
+ assert_equal internal.layout_registry[:foo].filename, sample_layout1
50
54
  end
51
55
 
52
- def test_register_layout_raise_when_specified_id_is_already_registered
53
- report = init_report
54
- report.register_layout('foo.tlf', :id => :foo)
56
+ def test_register_layout_should_raise_an_error_when_id_is_already_registered
57
+ internal = Report::Internal.new(report, {})
58
+ internal.register_layout(sample_layout2, :id => :foo)
55
59
 
56
60
  assert_raises ArgumentError do
57
- report.register_layout('hoge.tlf', :id => :foo)
61
+ internal.register_layout(sample_layout1, :id => :foo)
58
62
  end
59
63
  end
60
64
 
61
- def test_register_layout_call_layout_config_method_with_block
62
- report = init_report
63
- assert_equal report.register_layout('layout.tlf').flexmock_name,
64
- 'layout_configuration'
65
+ def test_register_layout_should_return_the_instance_of_LayoutConfiguration
66
+ internal = Report::Internal.new(report, {})
67
+
68
+ assert_instance_of ThinReports::Layout::Configuration,
69
+ internal.register_layout(sample_layout1)
65
70
  end
66
71
 
67
- def test_add_page_count_up_the_page_count
68
- new_page = proc {
69
- mock_page.should_receive(:finalize).mock
70
- }
71
-
72
- report = init_report
73
- assert_equal report.page_count, 0
74
-
75
- report.add_page(new_page.call)
76
- assert_equal report.page_count, 1
72
+ def test_add_page_should_finalize_the_current_page
73
+ layout = ThinReports::Layout.new(sample_layout1)
77
74
 
78
- report.add_page(new_page.call)
79
- assert_equal report.page_count, 2
75
+ internal = Report::Internal.new(report, :layout => sample_layout1)
76
+ page = internal.add_page(ThinReports::Core::Page.new(report, layout))
77
+ internal.add_page(ThinReports::Core::Page.new(report, layout))
78
+
79
+ assert_equal page.finalized?, true
80
80
  end
81
-
82
- def test_add_page_finalize_current_page
83
- report = init_report
84
-
85
- report.add_page(mock_page.should_receive(:finalize).once.mock)
86
- report.add_page(mock_page)
81
+
82
+ def test_add_page_should_return_the_current_page
83
+ layout = ThinReports::Layout.new(sample_layout1)
84
+ new_page = ThinReports::Core::Page.new(report, layout)
85
+
86
+ internal = Report::Internal.new(report, :layout => sample_layout1)
87
+
88
+ assert_same new_page, internal.add_page(new_page)
87
89
  end
88
-
89
- def test_add_page_switch_currently_page_of_report
90
- new_page = proc {|name|
91
- mock_page(name).should_receive(:finalize).mock
92
- }
93
-
94
- report = init_report
95
-
96
- report.add_page(new_page.call('page1'))
97
- assert_equal report.page.flexmock_name, 'page1'
98
-
99
- report.add_page(new_page.call('page2'))
100
- assert_equal report.page.flexmock_name, 'page2'
90
+
91
+ def test_add_page_should_add_the_initialized_page
92
+ layout = ThinReports::Layout.new(sample_layout1)
93
+ new_page = ThinReports::Core::Page.new(report, layout)
94
+
95
+ internal = Report::Internal.new(report, :layout => sample_layout1)
96
+ internal.add_page(new_page)
97
+
98
+ assert_same new_page, internal.pages.last
101
99
  end
102
-
103
- def test_add_page_store_specified_page_to_report_pages
104
- report = init_report
105
- report.add_page(new_page = mock_page)
100
+
101
+ def test_add_page_should_count_up_the_total_page_count
102
+ layout = ThinReports::Layout.new(sample_layout1)
106
103
 
107
- assert_includes report.pages, new_page
104
+ internal = Report::Internal.new(report, :layout => sample_layout1)
105
+ internal.add_page(ThinReports::Core::Page.new(report, layout))
106
+
107
+ assert_equal internal.page_count, 1
108
108
  end
109
109
 
110
- def test_add_page_dispatch_the_page_create_event
111
- pass = false
112
- report = init_report
113
- report.events.on(:page_create) {|e| pass = true }
114
-
115
- report.add_page(mock_page)
116
-
117
- assert_equal pass, true
118
- end
119
-
120
- def test_add_blank_page_not_dispatch_the_page_create_event
121
- pass = true
122
- report = init_report
123
- report.events.on(:page_create) {|e| pass = false }
124
-
125
- report.add_page(mock_blank_page)
126
-
127
- assert_equal pass, true
110
+ def test_add_page_should_switch_to_a_reference_to_the_current_page
111
+ layout = ThinReports::Layout.new(sample_layout1)
112
+ new_pages = (1..2).inject([]) do |pages, i|
113
+ pages << ThinReports::Core::Page.new(report, layout)
114
+ end
115
+
116
+ internal = Report::Internal.new(report, :layout => sample_layout1)
117
+ internal.add_page(new_pages[0])
118
+
119
+ assert_same internal.page, new_pages[0]
120
+
121
+ internal.add_page(new_pages[1])
122
+
123
+ assert_same internal.page, new_pages[1]
128
124
  end
129
-
130
- def test_add_blank_page_not_count_up_the_page_count_when_count_is_disabled
131
- report = init_report
132
- report.add_page(mock_not_counting_blank_page)
133
- report.add_page(mock_not_counting_blank_page)
134
125
 
135
- assert_equal report.page_count, 0
126
+ def test_add_page_should_dispatch_the_event_page_creation
127
+ dispatched = false
128
+ layout = ThinReports::Layout.new(sample_layout1)
129
+
130
+ internal = Report::Internal.new(report, :layout => sample_layout1)
131
+ internal.events.on(:page_create) {|e| dispatched = true }
132
+ internal.add_page(ThinReports::Core::Page.new(report, layout))
133
+
134
+ assert dispatched
136
135
  end
137
-
138
- def test_finalize
139
- pass = false
140
-
141
- report = init_report
142
- report.events.on(:generate) {|e| pass = true }
143
-
144
- report.add_page(mock_page.should_receive(:finalize).once.mock)
145
- report.finalize
146
-
147
- assert_equal report.finalized?, true
148
- assert_equal pass, true
136
+
137
+ def test_add_blank_page_should_not_dispatch_the_event_page_creation
138
+ dispatched = false
139
+ layout = ThinReports::Layout.new(sample_layout1)
140
+
141
+ internal = Report::Internal.new(report, :layout => sample_layout1)
142
+ internal.events.on(:page_create) {|e| dispatched = true }
143
+ internal.add_page(ThinReports::Core::BlankPage.new)
144
+
145
+ refute dispatched
149
146
  end
150
147
 
151
- def test_finalize_never_work_when_report_is_already_finalized
152
- report = init_report
153
- report.finalize
154
-
155
- flexmock(report).should_receive(:finalize_current_page).times(0)
156
- report.finalize
148
+ def test_add_blank_page_should_not_count_up_the_total_page_count_when_count_is_disabled
149
+ layout = ThinReports::Layout.new(sample_layout1)
150
+
151
+ internal = Report::Internal.new(report, :layout => sample_layout1)
152
+ internal.add_page(ThinReports::Core::BlankPage.new(false))
153
+
154
+ assert_equal internal.page_count, 0
157
155
  end
158
-
159
- def test_finalize_not_finalize_current_page_when_page_is_blank
160
- report = init_report
161
- report.add_page(mock_blank_page.should_receive(:finalize).times(0).mock)
162
- report.finalize
156
+
157
+ def test_add_blank_page_should_count_up_the_total_page_count_when_count_is_enabled
158
+ layout = ThinReports::Layout.new(sample_layout1)
159
+
160
+ internal = Report::Internal.new(report, :layout => sample_layout1)
161
+ internal.add_page(ThinReports::Core::BlankPage.new)
162
+
163
+ assert_equal internal.page_count, 1
163
164
  end
164
165
 
165
- def test_load_layout_with_String
166
- report = init_report
167
- assert_equal report.load_layout('layout.tlf').flexmock_name, 'layout_base'
166
+ def test_finalize_should_dispatch_the_event_report_generation
167
+ dispatched = false
168
+
169
+ internal = Report::Internal.new(report, :layout => sample_layout1)
170
+ internal.events.on(:generate) {|e| dispatched = true }
171
+ internal.finalize
172
+
173
+ assert dispatched
168
174
  end
169
-
170
- def test_load_layout_with_id
171
- report = init_report
172
- report.register_layout('layout.tlf', :id => :foo)
173
-
174
- assert_equal report.load_layout(:foo).flexmock_name, 'layout_base'
175
+
176
+ def test_finalize_should_finalize_the_report
177
+ internal = Report::Internal.new(report, :layout => sample_layout1)
178
+ internal.finalize
179
+
180
+ assert internal.finalized?
175
181
  end
176
-
177
- def test_load_layout_with_unknown_id
178
- report = init_report
179
- assert_nil report.load_layout(:unknown)
182
+
183
+ def test_finalize_should_not_work_when_report_is_already_finalized
184
+ internal = Report::Internal.new(report, :layout => sample_layout1)
185
+
186
+ flexmock(internal).
187
+ should_receive(:finalize_current_page).once
188
+
189
+ internal.finalize
190
+ internal.finalize
180
191
  end
181
-
182
- def test_load_layout_raise_when_invalid_value_set
183
- report = init_report
184
- assert_raises ArgumentError do
185
- report.load_layout(1)
186
- end
187
- assert_raises ArgumentError do
188
- report.load_layout(ThinReports::Layout.new('layout.tlf'))
189
- end
192
+
193
+ def test_finalized_should_return_true_when_report_is_already_finalized
194
+ internal = Report::Internal.new(report, :layout => sample_layout1)
195
+ internal.finalize
196
+
197
+ assert internal.finalized?
190
198
  end
191
199
 
192
- def test_load_layout_with_nil
193
- report = init_report
194
- report.register_layout('default.tlf', :default => true)
200
+ def test_load_layout_with_String
201
+ internal = Report::Internal.new(report, :layout => sample_layout1)
195
202
 
196
- assert_equal report.load_layout(nil).flexmock_name, 'layout_base'
203
+ assert_equal internal.load_layout(sample_layout2).filename,
204
+ sample_layout2
197
205
  end
198
206
 
199
- def test_copy_page
200
- page = mock_page
201
-
202
- flexmock(page).
203
- should_receive(:finalize).with(:at => :copy).once.
204
- should_receive(:copy).and_return(mock_page('copied_page')).once
205
-
206
- report = init_report
207
- report.add_page(page)
208
- report.copy_page
209
-
210
- assert_equal report.page.flexmock_name, 'copied_page'
211
- end
212
-
213
- def init_report(options = {})
214
- Report::Internal.new(flexmock('report_base'), options)
207
+ def test_load_layout_with_id
208
+ internal = Report::Internal.new(report, {})
209
+ internal.register_layout(sample_layout1, :id => :sample)
210
+
211
+ assert_equal internal.load_layout(:sample).filename,
212
+ sample_layout1
215
213
  end
216
214
 
217
- def mock_page(page_name = 'page')
218
- flexmock(page_name).
219
- should_receive(:count? => true, :blank? => false).
220
- should_receive(:no=).with(::Numeric).once.mock
215
+ def test_load_layout_with_unknown_id
216
+ internal = Report::Internal.new(report, {})
217
+ assert_nil internal.load_layout(:unknown)
221
218
  end
222
219
 
223
- def mock_blank_page
224
- flexmock('blank_page').
225
- should_receive(:count? => true, :blank? => true).
226
- should_receive(:no=).with(::Numeric).once.mock
220
+ def test_load_layout_should_raise_error_when_invalid_value_set
221
+ internal = Report::Internal.new(report, {})
222
+
223
+ assert_raises ThinReports::Errors::LayoutFileNotFound do
224
+ internal.load_layout('/path/to/unkown.tlf')
225
+ end
227
226
  end
228
227
 
229
- def mock_not_counting_blank_page
230
- flexmock('blank_page').
231
- should_receive(:count? => false, :blank? => true).
232
- should_receive(:no=).with(::Numeric).times(0).mock
228
+ def test_copy_page_should_finalize_current_page
229
+ layout = ThinReports::Layout.new(sample_layout1)
230
+
231
+ internal = Report::Internal.new(report, :layout => sample_layout1)
232
+ internal.add_page(page = ThinReports::Core::Page.new(report, layout))
233
+ internal.copy_page
234
+
235
+ assert page.finalized?
236
+ end
237
+
238
+ def test_copy_page_should_add_the_copied_page
239
+ layout = ThinReports::Layout.new(sample_layout1)
240
+
241
+ internal = Report::Internal.new(report, :layout => sample_layout1)
242
+ internal.add_page(page = ThinReports::Core::Page.new(report, layout))
243
+ internal.copy_page
244
+
245
+ assert_equal internal.page_count, 2
233
246
  end
234
247
  end
data/thinreports.gemspec CHANGED
@@ -28,8 +28,9 @@ Gem::Specification.new do |s|
28
28
  s.add_dependency('prawn', '>= 0.12.0', '<= 0.12.0')
29
29
 
30
30
  s.add_development_dependency('bundler', ['>= 1.0.0'])
31
- s.add_development_dependency('flexmock', ['>= 0'])
31
+ s.add_development_dependency('flexmock', ['~> 0.9.0'])
32
32
  s.add_development_dependency('yard', ['>= 0'])
33
33
  s.add_development_dependency('rake', ['>=0'])
34
34
  s.add_development_dependency('turn', ['>=0'])
35
+ s.add_development_dependency('simplecov', ['>=0'])
35
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thinreports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-02 00:00:00.000000000 Z
12
+ date: 2012-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: prawn
@@ -51,6 +51,22 @@ dependencies:
51
51
  version: 1.0.0
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: flexmock
54
+ requirement: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: 0.9.0
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 0.9.0
68
+ - !ruby/object:Gem::Dependency
69
+ name: yard
54
70
  requirement: !ruby/object:Gem::Requirement
55
71
  none: false
56
72
  requirements:
@@ -66,7 +82,7 @@ dependencies:
66
82
  - !ruby/object:Gem::Version
67
83
  version: '0'
68
84
  - !ruby/object:Gem::Dependency
69
- name: yard
85
+ name: rake
70
86
  requirement: !ruby/object:Gem::Requirement
71
87
  none: false
72
88
  requirements:
@@ -82,7 +98,7 @@ dependencies:
82
98
  - !ruby/object:Gem::Version
83
99
  version: '0'
84
100
  - !ruby/object:Gem::Dependency
85
- name: rake
101
+ name: turn
86
102
  requirement: !ruby/object:Gem::Requirement
87
103
  none: false
88
104
  requirements:
@@ -98,7 +114,7 @@ dependencies:
98
114
  - !ruby/object:Gem::Version
99
115
  version: '0'
100
116
  - !ruby/object:Gem::Dependency
101
- name: turn
117
+ name: simplecov
102
118
  requirement: !ruby/object:Gem::Requirement
103
119
  none: false
104
120
  requirements: