Top Level Namespace

Defined Under Namespace

Modules: Hiptest Classes: CliOptions, ConsoleFormatter, FileConfigParser, LanguageConfigParser, LanguageGroupConfig, NodeRenderingContext, NullReporter, Option, OptionsParser, Reporter, String, TemplateFinder

Instance Method Summary collapse

Instance Method Details

#fetch_project_export(options) ⇒ Object



57
58
59
60
61
# File 'lib/hiptest-publisher/utils.rb', line 57

def fetch_project_export(options)
  url = make_url(options)

  open(url, "User-Agent" => 'Ruby/hiptest-publisher', :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)
end

#hiptest_publisher_pathObject



7
8
9
10
11
# File 'lib/hiptest-publisher/utils.rb', line 7

def hiptest_publisher_path
  Gem.loaded_specs['hiptest-publisher'].full_gem_path
rescue
  '.'
end

#hiptest_publisher_versionObject



13
14
15
16
17
# File 'lib/hiptest-publisher/utils.rb', line 13

def hiptest_publisher_version
  Gem.loaded_specs['hiptest-publisher'].version.to_s
rescue
  File.read("#{hiptest_publisher_path}/VERSION").strip if File.exists?("#{hiptest_publisher_path}/VERSION")
end

#make_filter(options) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/hiptest-publisher/utils.rb', line 36

def make_filter(options)
  ids = options.filter_ids.split(',').map {|id| "filter[]=id:#{id}"}
  tags = options.filter_tags.split(',').map {|tag| "filter[]=tag:#{tag}"}

  filter = (ids + tags).join("&")
  filter.empty? ? '' : "?#{filter}"
end

#make_url(options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hiptest-publisher/utils.rb', line 44

def make_url(options)
  if push?(options)
    "#{options.site}/import_test_results/#{options.token}/#{options.push_format}"
  else
    base_url = "#{options.site}/publication/#{options.token}"
    if options.test_run_id.nil? || options.test_run_id.empty?
      "#{base_url}/#{options.leafless_export ? 'leafless_tests' : 'project'}#{make_filter(options)}"
    else
      "#{base_url}/test_run/#{options.test_run_id}"
    end
  end
end

#pluralize(count, singular, plural = nil) ⇒ Object



27
28
29
30
# File 'lib/hiptest-publisher/utils.rb', line 27

def pluralize(count, singular, plural=nil)
  word = pluralize_word(count, singular, plural)
  "#{count} #{word}"
end

#pluralize_word(count, singular, plural = nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/hiptest-publisher/utils.rb', line 19

def pluralize_word(count, singular, plural=nil)
  if count == 1
    singular
  else
    "#{singular}s"
  end
end

#push?(options) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/hiptest-publisher/utils.rb', line 96

def push?(options)
  options.push && !options.push.empty?
end

#push_results(options) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/hiptest-publisher/utils.rb', line 100

def push_results(options)
  # Code from: https://github.com/nicksieger/multipart-post
  url = URI.parse(make_url(options))
  use_ssl = (url.scheme == 'https')

  File.open(options.push) do |results|
    req = Net::HTTP::Post::Multipart.new(url.path, "file" => UploadIO.new(results, "text", "results.tap"))

    response = Net::HTTP.start(url.host, url.port, :use_ssl => use_ssl, :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
      http.request(req)
    end
  end
end

#show_status_message(message, status = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/hiptest-publisher/utils.rb', line 63

def show_status_message(message, status=nil)
  status_icon = " "
  output = STDOUT

  if status == :success
    status_icon = "v".green
  elsif status == :failure
    status_icon = "x".red
    output = STDERR
  end
  if status
    cursor_offset = ""
  else
    return unless $stdout.tty?
    rows, columns = IO.console.winsize
    vertical_offset = (4 + message.length) / columns
    cursor_offset = "\r\e[#{vertical_offset + 1}A"
  end

  output.print "[#{status_icon}] #{message}#{cursor_offset}\n"
end

#singularize(name) ⇒ Object



32
33
34
# File 'lib/hiptest-publisher/utils.rb', line 32

def singularize(name)
  name.to_s.chomp("s")
end

#with_status_message(message, &blk) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/hiptest-publisher/utils.rb', line 85

def with_status_message(message, &blk)
  show_status_message message
  status = :success
  yield
rescue
  status = :failure
  raise
ensure
  show_status_message message, status
end