Module: Longleaf::FileHelpers
- Defined in:
- lib/longleaf/specs/file_helpers.rb
Overview
Test helper methods for creating test files
Class Method Summary collapse
- .create_test_file(dir: nil, name: nil, content: 'content') ⇒ Object
- .create_work_class(lib_dir, class_name, file_name, module_name, is_applicable, init_body, perform) ⇒ Object
- .make_test_dir(parent: nil, name: 'dir') ⇒ Object
Instance Method Summary collapse
- #create_test_file(dir: nil, name: nil, content: 'content') ⇒ Object
- #create_work_class(lib_dir, class_name, file_name, module_name = nil, is_applicable: true, init_body: "", perform: "") ⇒ Object
- #make_test_dir(parent: nil, name: 'dir') ⇒ Object
Class Method Details
.create_test_file(dir: nil, name: nil, content: 'content') ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/longleaf/specs/file_helpers.rb', line 25 def self.create_test_file(dir: nil, name: nil, content: 'content') if dir.nil? || name.nil? name = 'test_file' if name.nil? file = Tempfile.create(name, dir) file << content file.close return file.path else path = File.join(dir, name) File.open(path, 'w') { |f| f.write(content) } path end end |
.create_work_class(lib_dir, class_name, file_name, module_name, is_applicable, init_body, perform) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/longleaf/specs/file_helpers.rb', line 43 def self.create_work_class(lib_dir, class_name, file_name, module_name, is_applicable, init_body, perform) class_contents = %Q( class #{class_name} def initialize(service_def, app_manager) #{init_body} end def perform(file_rec, event) #{perform} end def is_applicable?(event) #{is_applicable} end end ) class_contents = "module #{module_name}\n#{class_contents}\nend" unless module_name.nil? create_test_file(dir: lib_dir, name: file_name, content: class_contents) end |
.make_test_dir(parent: nil, name: 'dir') ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/longleaf/specs/file_helpers.rb', line 11 def self.make_test_dir(parent: nil, name: 'dir') if parent.nil? Dir.mktmpdir(name) else path = File.join(parent, name) Dir.mkdir(path) path end end |
Instance Method Details
#create_test_file(dir: nil, name: nil, content: 'content') ⇒ Object
21 22 23 |
# File 'lib/longleaf/specs/file_helpers.rb', line 21 def create_test_file(dir: nil, name: nil, content: 'content') FileHelpers.create_test_file(dir: dir, name: name, content: content) end |
#create_work_class(lib_dir, class_name, file_name, module_name = nil, is_applicable: true, init_body: "", perform: "") ⇒ Object
39 40 41 |
# File 'lib/longleaf/specs/file_helpers.rb', line 39 def create_work_class(lib_dir, class_name, file_name, module_name = nil, is_applicable: true, init_body: "", perform: "") FileHelpers.create_work_class(lib_dir, class_name, file_name, module_name, is_applicable, init_body, perform) end |
#make_test_dir(parent: nil, name: 'dir') ⇒ Object
7 8 9 |
# File 'lib/longleaf/specs/file_helpers.rb', line 7 def make_test_dir(parent: nil, name: 'dir') FileHelpers.make_test_dir(parent: parent, name: name) end |