module XamarinTestCloud # Appropriate for files under features/, / and test_servers/ # # Not appropriate for app and dysm files. # # To create a Cucumber configuration instance, use `TestFile.cucumber_config`. class TestFile def self.file_digest(file, digest=:SHA256) case digest when :SHA256 require "digest" Digest::SHA256.file(file).hexdigest when :MD5 require "digest/md5" Digest::MD5.file(file).hexdigest else raise ArgumentError, %Q[Invalid digest type: #{digest}. Only :SHA256 or :MD5 are supported ] end end # Special handling for Cucumber configuration files. # # The server expects the remote file name to be _exactly_ config/cucumber.yml def self.cucumber_config(file) test_file = TestFile.new(file, File.dirname(file)) test_file.instance_variable_set(:@remote_path, "config/cucumber.yml") test_file end attr_reader :path, :file_instance, :digest, :remote_path # @param [String] path Needs to be expanded # @param [String] basedir Needs to be the beginning of the path def initialize(path, basedir) @path = path @basedir = basedir expanded = File.expand_path(path) if path != File.expand_path(expanded) raise ArgumentError, %Q[Path must be expanded: path: #{path} expanded: #{expanded} ] end if !path.start_with?(basedir) raise ArgumentError, %Q[Path must start with basedir: path: #{path} basedir: #{basedir} ] end end def to_s %Q[#] end def inspect to_s end def file_instance @file_instance ||= File.new(path) end def digest @digest ||= TestFile.file_digest(path) end def remote_path @remote_path ||= begin require "pathname" absolute = Pathname.new(path) root = Pathname.new(basedir) relative = absolute.relative_path_from(root) relative.to_s end end private def basedir @basedir end end end