Improve testing setup

This commit is contained in:
Brandon Robins
2018-03-11 16:38:50 -05:00
parent 19290d3832
commit 2ce668b9ea
9 changed files with 163 additions and 76 deletions

View File

@@ -0,0 +1,49 @@
# frozen_string_literal: true
RESOURCES_TO_TEST_AGAINST = [
Calligraphy::FileResource
].freeze
module RSpecMethods
def setup; end
def cleanup; end
def create(resource:, content: 'Hi hi!'); end
end
module FileResourceHelpers
def setup
tmp_dir = Rails.root.join('../../tmp').to_path
Dir.mkdir tmp_dir unless File.exist? tmp_dir
FileUtils.rm_r resource_root if File.exist? resource_root
Dir.mkdir resource_root
end
def cleanup
FileUtils.rm_r resource_root if File.exist? resource_root
end
def create(resource:, content: 'Hello world')
resource = Calligraphy::FileResource.new(
resource: resource,
root_dir: resource_root
)
resource.write content
end
def resource_root
Rails.root.join('../../tmp/webdav').to_path
end
end
RESOURCES_TO_TEST_AGAINST.each do |resource_class|
resource_class.send :extend, RSpecMethods
end
module Calligraphy
class FileResource
extend FileResourceHelpers
end
end