Files
danbooru/test/test_helpers/download_helper.rb
evazion 4f543671a2 tests: move test/helpers to test/test_helpers.
The Rails convention is for test/helpers to be used for testing the view
helpers in app/helpers. We were using it to store certain utility
methods instead. Move these to test/test_helpers so that test/helpers
can be used for its intended purpose.
2018-01-14 16:11:15 -06:00

25 lines
769 B
Ruby

module DownloadTestHelper
def assert_downloaded(expected_filesize, source)
tempfile = Tempfile.new("danbooru-test")
download = Downloads::File.new(source, tempfile.path)
assert_nothing_raised(Downloads::File::Error) do
download.download!
end
assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}")
end
def assert_rewritten(expected_source, test_source)
tempfile = Tempfile.new("danbooru-test")
download = Downloads::File.new(test_source, tempfile.path)
rewritten_source, _, _ = download.before_download(test_source, {})
assert_equal(expected_source, rewritten_source, "Tested source URL: #{test_source}")
end
def assert_not_rewritten(source)
assert_rewritten(source, source)
end
end