Class: StormForge::Thor::Testrun

Inherits:
Base
  • Object
show all
Defined in:
lib/thor/testrun.rb

Instance Method Summary collapse

Instance Method Details

#abort(test_run_id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/thor/testrun.rb', line 59

def abort(test_run_id)
  require_stormfile!

  test_run = client.abort_test_run(test_run_id)
  puts test_run.inspect
rescue Faraday::Error::ConnectionFailed
  raise Thor::Error, "StormForger API not available :-/ (connection failed)"
rescue Faraday::Error::ResourceNotFound
  raise Thor::Error, "Test Run #{test_run_id} not found"
rescue Faraday::Error::ClientError => e
  if e.response[:status] == 422
    raise Thor::Error, "Test Run #{test_run_id} cannot be aborted!"
  else
    raise e
  end
end

#create(test_case_slug, description = "") ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/thor/testrun.rb', line 25

def create(test_case_slug, description="")
  require_stormfile!

  p client.create_test_run(test_case_slug, description)
rescue Faraday::Error::ConnectionFailed
  raise Thor::Error, "StormForger API not available :-/ (connection failed)"
rescue Faraday::Error::ResourceNotFound
  raise Thor::Error, "Test Run could not be created, test case '#{test_case_slug}' not found!"
end

#list(test_case_slug = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/thor/testrun.rb', line 3

def list(test_case_slug=nil)
  require_stormfile!

  test_runs = client.list_test_runs(test_case_slug)["test_runs"]
  test_case = test_case_slug.present? ? "test case '#{test_case_slug}'" : "all test cases"
  puts "Test Run ID & Description for #{test_case}"
  test_runs.each do |test_run|
    puts "#{test_run["id"].to_s} (#{test_run["state"]}): #{test_run["description"] || '-'}"
  end
rescue Faraday::Error::ConnectionFailed
  raise Thor::Error, "StormForger API not available :-/ (connection failed)"
rescue Faraday::Error::ResourceNotFound
  raise Thor::Error, "Test case '#{test_case_slug}' not found!"
rescue Faraday::Error::ClientError => e
  if e.response[:status] == 401
    handle_authentication_error(e)
  else
    raise e
  end
end

#show(test_run_id) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/thor/testrun.rb', line 36

def show(test_run_id)
  require_stormfile!

  test_run = client.fetch_test_run(test_run_id)
  pp test_run
rescue Faraday::Error::ConnectionFailed
  raise Thor::Error, "StormForger API not available :-/ (connection failed)"
rescue Faraday::Error::ResourceNotFound
  raise Thor::Error, "Test Run #{test_run_id} not found!"
end

#stats(test_run_id, since = 0) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/thor/testrun.rb', line 50

def stats(test_run_id, since=0)
  require_stormfile!

  client.test_run_log(test_run_id, since, options[:limit], options[:stream]) do |stats|
    puts stats.to_json
  end
end