Module: RepoManager::TestApi

Defined in:
lib/repo_manager/test/test_api.rb

Instance Method Summary collapse

Instance Method Details

#_create_fixed_size_file(file_name, file_size, check_presence) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/repo_manager/test/test_api.rb', line 59

def _create_fixed_size_file(file_name, file_size, check_presence)
  in_current_dir do
    raise "expected #{file_name} to be present" if check_presence && !File.file?(file_name)
    _mkdir(File.dirname(file_name))
    File.open(file_name, "wb"){ |f| f.seek(file_size - 1); f.write("\0") }
  end
end

#expand_tabs(data, indent = 8) ⇒ Object

expand tabs to spaces



21
22
23
24
25
# File 'lib/repo_manager/test/test_api.rb', line 21

def expand_tabs(data, indent=8)
  data.gsub(/([^\t\n]*)\t/) {
    $1 + " " * (indent - ($1.size % indent))
  }
end

#fullpath(filename) ⇒ Object

Returns full path to files in the aruba tmp folder.

Returns:

  • full path to files in the aruba tmp folder



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/repo_manager/test/test_api.rb', line 68

def fullpath(filename)
  path = File.expand_path(File.join(current_dir, filename))
  #if path.match(/^\/cygdrive/)
  #  # match /cygdrive/c/path/to and return c:\\path\\to
  #  path = `cygpath -w #{path}`.chomp
  #elsif path.match(/.\:/)
  #  # match c:/path/to and return c:\\path\\to
  #  path = path.gsub(/\//, '\\')
  #end
  path
end

#get_file_contents(filename) ⇒ Object

Returns the contents of “filename” in the aruba tmp folder.

Returns:

  • the contents of “filename” in the aruba tmp folder



81
82
83
84
85
# File 'lib/repo_manager/test/test_api.rb', line 81

def get_file_contents(filename)
  in_current_dir do
    IO.read(filename)
  end
end

#in_path(path, &block) ⇒ Object

execute a block in a specific working directory (path)



16
17
18
# File 'lib/repo_manager/test/test_api.rb', line 16

def in_path(path, &block)
  Dir.chdir(path, &block)
end

#normalize(str) ⇒ Object

account for differences in line endings and tabs



28
29
30
31
32
33
34
35
# File 'lib/repo_manager/test/test_api.rb', line 28

def normalize(str)
  # convert/normalize DOS CRLF endings
  str.gsub!(/\r\n/, "\n") if str.match("\r\n")
  if str.match("\t")
    str = expand_tabs(str)
  end
  str
end

#process_and_check_file_content(file, partial_content, expect_match) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/repo_manager/test/test_api.rb', line 37

def process_and_check_file_content(file, partial_content, expect_match)
  str = process_regex_tokens(Regexp.escape(partial_content))
  content = IO.read(file)
  if expect_match
    content.should =~ Regexp.compile(str)
  else
    content.should_not =~ Regexp.compile(str)
  end
end

#process_regex_tokens(str) ⇒ Object

substitute back in each tokenized regexp after all text has been escaped



48
49
50
51
52
53
# File 'lib/repo_manager/test/test_api.rb', line 48

def process_regex_tokens(str)
  str = str.gsub(/<%NUMBER[^%]*%>/, '\d+')
  str = str.gsub(/<%PK[^%]*%>/, '\d+')
  str = str.gsub(/<%STRING[^%]*%>/, '.+')
  str
end

#which(binary) ⇒ Object

cross platform ‘which` command



5
6
7
8
9
10
11
12
13
# File 'lib/repo_manager/test/test_api.rb', line 5

def which(binary)
  separator = RepoManager::WINDOWS ? ';' : ':'
  paths = ENV['PATH'].split(separator)
  paths.each do |path|
    fullpath = File.join(path, binary)
    return fullpath if File.exists?(fullpath)
  end
  return nil
end

#write_fixed_size_file(file_name, file_size) ⇒ Object



55
56
57
# File 'lib/repo_manager/test/test_api.rb', line 55

def write_fixed_size_file(file_name, file_size)
  _create_fixed_size_file(file_name, file_size, false)
end