test/unit/report/test_base.rb in thinreports-0.8.2 vs test/unit/report/test_base.rb in thinreports-0.9.0
- old
+ new
@@ -3,19 +3,19 @@
require 'test_helper'
class Thinreports::Report::TestBase < Minitest::Test
include Thinreports::TestHelper
- # Alias
Report = Thinreports::Report
def setup
@report = Report::Base.new
+ @layout_file = layout_file
end
def test_on_page_create_callback
- report = Report::Base.new layout: data_file('layout_text1.tlf')
+ report = Report::Base.new layout: @layout_file.path
counter = 0
callback = -> page {
assert_instance_of Report::Page, page
counter += 1
@@ -26,32 +26,32 @@
2.times { report.start_new_page }
assert_equal counter, 2
end
def test_initialize_should_register_layout_as_default_when_layout_is_specified_as_the_option
- report = Report::Base.new layout: data_file('layout_text1.tlf')
- assert_equal report.default_layout.filename, data_file('layout_text1.tlf')
+ report = Report::Base.new layout: @layout_file.path
+ assert_equal report.default_layout.filename, @layout_file.path
end
def test_initialize_should_initialize_new_Report_without_default_layout
assert_nil @report.default_layout
end
def test_use_layout_should_register_default_layout_when_default_property_is_omitted
- @report.use_layout(data_file('layout_text1.tlf'))
+ @report.use_layout(@layout_file.path)
- assert_equal @report.default_layout.filename, data_file('layout_text1.tlf')
+ assert_equal @report.default_layout.filename, @layout_file.path
end
def test_use_layout_should_register_default_layout_when_default_property_is_true
- @report.use_layout(data_file('layout_text2.tlf'), default: true)
+ @report.use_layout(@layout_file.path, default: true)
- assert_equal @report.default_layout.filename, data_file('layout_text2.tlf')
+ assert_equal @report.default_layout.filename, @layout_file.path
end
def test_start_new_page_should_properly_create_a_new_Page_and_return
- @report.use_layout(data_file('layout_text1'))
+ @report.use_layout(@layout_file.path)
assert_instance_of Thinreports::Report::Page, @report.start_new_page
end
def test_start_new_page_should_raise_when_the_layout_has_not_been_registered_yet
@@ -59,29 +59,29 @@
@report.start_new_page(layout: :unknown)
end
end
def test_start_new_page_should_create_a_new_page_using_a_default_layout
- @report.use_layout(data_file('layout_text1.tlf'), default: true)
+ @report.use_layout(@layout_file.path, default: true)
- assert_equal @report.start_new_page.layout.filename, data_file('layout_text1.tlf')
+ assert_equal @report.start_new_page.layout.filename, @layout_file.path
end
def test_start_new_page_should_create_a_new_page_using_a_layout_with_specified_id
- @report.use_layout(data_file('layout_text1.tlf'), id: :foo)
+ @report.use_layout(@layout_file.path, id: :foo)
assert_equal @report.start_new_page(layout: :foo).layout.filename,
- data_file('layout_text1.tlf')
+ @layout_file.path
end
def test_start_new_page_should_create_a_new_page_using_a_specified_layoutfile
- new_page = @report.start_new_page(layout: data_file('layout_text1.tlf'))
- assert_equal new_page.layout.filename, data_file('layout_text1.tlf')
+ new_page = @report.start_new_page(layout: @layout_file.path)
+ assert_equal new_page.layout.filename, @layout_file.path
end
def test_start_new_page_with_count_option
- @report.use_layout data_file('layout_text1.tlf'), default: true
+ @report.use_layout @layout_file.path, default: true
new_page = @report.start_new_page count: false
assert_nil new_page.no
assert_equal @report.page_count, 0
@@ -93,35 +93,35 @@
assert_equal new_page.no, 2
assert_equal @report.page_count, 2
end
def test_add_blank_page_should_properly_create_a_new_blank_page
- @report.use_layout(data_file('layout_text1'))
+ @report.use_layout(@layout_file.path)
assert_instance_of Thinreports::Report::BlankPage, @report.add_blank_page
end
def test_layout_should_return_the_default_layout_with_no_arguments
- @report.use_layout(data_file('layout_text1.tlf'), default: true)
+ @report.use_layout(@layout_file.path, default: true)
- assert_equal @report.layout.filename, data_file('layout_text1.tlf')
+ assert_equal @report.layout.filename, @layout_file.path
end
def test_layout_should_raise_when_the_specified_layout_is_not_found
assert_raises Thinreports::Errors::UnknownLayoutId do
@report.layout(:unknown_layout_id)
end
end
def test_layout_should_return_the_layout_with_specified_id
- @report.use_layout(data_file('layout_text2.tlf'), id: :foo)
+ @report.use_layout(@layout_file.path, id: :foo)
- assert_equal @report.layout(:foo).filename, data_file('layout_text2.tlf')
+ assert_equal @report.layout(:foo).filename, @layout_file.path
end
def test_generate_with_filename
- report = Report::Base.new layout: data_file('layout_text1.tlf')
+ report = Report::Base.new layout: @layout_file.path
report.generate :pdf, filename: temp_path.join('result1.pdf')
report.generate filename: temp_path.join('result2.pdf')
assert File.exist?(temp_path.join('result1.pdf'))
@@ -129,30 +129,19 @@
assert_equal File.read(temp_path.join('result1.pdf')),
File.read(temp_path.join('result2.pdf'))
end
- def test_events_should_return_Report_Events
- assert_instance_of Thinreports::Report::Events, @report.events
- end
-
- def test_events_should_deprecated
- _out, err = capture_io do
- @report.events
- end
- assert_includes err, '[DEPRECATION]'
- end
-
def test_page_should_return_the_current_page
- @report.use_layout(data_file('layout_text1.tlf'))
+ @report.use_layout(@layout_file.path)
@report.start_new_page
assert_instance_of Thinreports::Report::Page, @report.page
end
def test_page_count_should_return_total_page_count
- @report.use_layout(data_file('layout_text1.tlf'))
+ @report.use_layout(@layout_file.path)
2.times { @report.start_new_page }
assert_equal @report.page_count, 2
end
@@ -169,31 +158,31 @@
@report.finalize
assert_equal @report.finalized?, true
end
def test_list_should_create_new_page_when_page_is_not_created
- @report.use_layout(data_file('layout_list.tlf'))
- @report.list(:list)
+ @report.use_layout(@layout_file.path)
+ @report.list
refute_nil @report.page
end
def test_list_should_create_new_page_when_page_is_finalized
@report.tap do |r|
- r.use_layout(data_file('layout_list.tlf'))
+ r.use_layout(@layout_file.path)
r.start_new_page
r.page.finalize
end
- @report.list(:list)
+ @report.list
assert_equal @report.page.finalized?, false
end
def test_list_should_properly_return_shape_with_the_specified_id
- @report.use_layout(data_file('layout_list.tlf'))
+ @report.use_layout(@layout_file.path)
- assert_equal @report.list(:list).id, 'list'
+ assert_equal @report.list.id, 'default'
end
def test_start_page_number
assert_equal @report.start_page_number, 1
@report.start_page_number_from 10
@@ -212,14 +201,12 @@
Report::Base.create
end
end
def test_Base_generate_with_filename
- layout_file = data_file 'layout_text1.tlf'
-
- Report::Base.generate(:pdf, report: { layout: layout_file },
+ Report::Base.generate(:pdf, report: { layout: @layout_file.path },
generator: { filename: temp_path.join('result1.pdf') }) {}
- Report::Base.generate(report: { layout: layout_file },
+ Report::Base.generate(report: { layout: @layout_file.path },
generator: { filename: temp_path.join('result2.pdf') }) {}
assert_equal temp_path.join('result1.pdf').read,
temp_path.join('result2.pdf').read
end