class RainforestCli::TestFiles
Constants
- DEFAULT_TEST_FOLDER
- FILE_EXTENSION
- SAMPLE_FILE
Attributes
test_data[R]
test_folder[R]
Public Class Methods
new(options)
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 24 def initialize(options) @options = options if @options.command == 'rm' @test_folder = File.dirname(@options.file_name) elsif @options.test_folder.nil? logger.info "No test folder supplied. Using default folder: #{DEFAULT_TEST_FOLDER}" @test_folder = File.expand_path(DEFAULT_TEST_FOLDER) else @test_folder = File.expand_path(@options.test_folder) end end
Public Instance Methods
count()
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 53 def count test_data.count end
create_file(file_name = @options.file_name)
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 67 def create_file(file_name = @options.file_name) ensure_directory_exists title = file_name || 'Unnamed Test' file_path = title.dup if title[-file_extension.length..-1] == file_extension title = title[0...-file_extension.length] else file_path += file_extension end file_path = unique_path(File.join(test_folder, file_path)) File.open(file_path, 'w') { |file| file.write(sprintf(SAMPLE_FILE, SecureRandom.uuid, title)) } logger.info "Created #{file_path}" file_path end
ensure_directory_exists()
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 63 def ensure_directory_exists FileUtils.mkdir_p(test_folder) unless Dir.exist?(test_folder) end
file_extension()
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 45 def file_extension FILE_EXTENSION end
rfml_ids()
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 49 def rfml_ids test_data.map(&:rfml_id) end
test_dictionary()
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 57 def test_dictionary {}.tap do |dictionary| test_data.each { |rfml_test| dictionary[rfml_test.rfml_id] = rfml_test } end end
test_paths()
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 37 def test_paths "#{@test_folder}/**/*#{FILE_EXTENSION}" end
Private Instance Methods
filter_tests(tests)
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 103 def filter_tests(tests) tests.select do |test| pass_tag_filter = (@options.tags - test.tags).empty? pass_site_filter = @options.site_id.nil? || @options.site_id == test.site_id pass_tag_filter || pass_site_filter end end
get_test_data()
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 89 def get_test_data if @options.file_name [RainforestCli::TestParser::Parser.new(@options.file_name).process] else data = [] if Dir.exist?(@test_folder) Dir.glob(test_paths) do |file_name| data << RainforestCli::TestParser::Parser.new(file_name).process end end filter_tests(data) end end
logger()
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 124 def logger RainforestCli.logger end
unique_path(file_path)
click to toggle source
# File lib/rainforest_cli/test_files.rb, line 111 def unique_path(file_path) path = file_path[0...-file_extension.length] identifier = 0 loop do id_string = (identifier > 0) ? " (#{identifier})" : '' test_path = path + id_string + file_extension return test_path unless File.exist?(test_path) identifier += 1 end end