bixby-common 0.4.11 → 0.4.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18fbe02200bf8cecce22d6f30e11997917d262ab
4
- data.tar.gz: 67c2cfdff3c661bfe232aeaaee87947ad9305669
3
+ metadata.gz: c42be708d73846920649d7e5d751739ec25457a5
4
+ data.tar.gz: 75b57b797385e2e5f9f5ecb00d3a95c0340f4286
5
5
  SHA512:
6
- metadata.gz: 46d249eb473d1801fc704e9695e4a82f19abf11fc99b7086e0201185dbc2c8b2f3165d972e3a4ef15f1039ee5b83d4e5eecb8d7150956554aca3d164d4c7651c
7
- data.tar.gz: ae4e61b4408a7f32887a7a87f0e8d920009aea26f3fbc526deb23e4e9b13791257316ce0ec91c0126eab2f9bc5d1e7fbc6d445219381f53280c2bf8842100c7b
6
+ metadata.gz: f994c619270d896ccb1a26084d4bda47755bdb1bf77453006137503873e68f9aeda766481f4241412855ac8411673e0605bf0b222ad2131f9e487f8923b24ccf
7
+ data.tar.gz: 74c12adcccc39bb244d26bd3fa41437e159df8c7a81810835f9cf6c56a22baa312c97161f642ab9a99d44b234e8b5be0f232d7a950535eb1d827db55a37a5504
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.11
1
+ 0.4.12
data/bixby-common.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bixby-common 0.4.11 ruby lib
5
+ # stub: bixby-common 0.4.12 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bixby-common"
9
- s.version = "0.4.11"
9
+ s.version = "0.4.12"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -6,16 +6,23 @@ class CommandResponse
6
6
 
7
7
  attr_accessor :status, :stdout, :stderr
8
8
 
9
- # Create a new CommandResponse from the given from_json_response
9
+ SUCCESS = 0
10
+ UNKNOWN_FAILURE = 255
11
+
12
+ # Create a new CommandResponse from the given JsonResponse
10
13
  #
11
14
  # @param [JsonResponse] res
12
15
  #
13
16
  # @return [CommandResponse]
14
17
  def self.from_json_response(res)
15
18
  cr = CommandResponse.new(res.data)
16
- if !(res.message.nil? || res.message.empty?) then
17
- cr.status ||= 255
18
- cr.stderr ||= res.message
19
+ if res.fail? then
20
+ if !(res.message.nil? || res.message.empty?) then
21
+ cr.status ||= UNKNOWN_FAILURE
22
+ cr.stderr ||= res.message
23
+ else
24
+ cr.status ||= UNKNOWN_FAILURE
25
+ end
19
26
  end
20
27
  return cr
21
28
  end
@@ -24,7 +31,7 @@ class CommandResponse
24
31
  #
25
32
  # @return [JsonResponse]
26
33
  def to_json_response
27
- return JsonResponse.new((status == 0 ? "success" : "fail"), nil, self.to_hash)
34
+ return JsonResponse.new((success?() ? "success" : "fail"), nil, self.to_hash)
28
35
  end
29
36
 
30
37
  def initialize(params = nil)
@@ -39,7 +46,7 @@ class CommandResponse
39
46
  end
40
47
 
41
48
  def success?
42
- @status.to_i == 0
49
+ @status && @status.to_i == SUCCESS
43
50
  end
44
51
 
45
52
  def fail?
@@ -15,6 +15,11 @@ class TestCommandResponse < TestCase
15
15
  assert_kind_of CommandResponse, cr
16
16
  assert_equal 255, cr.status
17
17
  assert_equal "unknown", cr.stderr
18
+
19
+ assert_throws(CommandException) do
20
+ cr.raise!
21
+ end
22
+
18
23
  begin
19
24
  cr.raise!
20
25
  rescue CommandException => ex
@@ -29,6 +34,16 @@ class TestCommandResponse < TestCase
29
34
  assert_equal 0, cr.status
30
35
  assert_equal "foobar", cr.stdout
31
36
  assert_nil cr.stderr
37
+
38
+ # empty failure message
39
+ res = JsonResponse.new("fail")
40
+ assert res.fail?
41
+ refute res.success?
42
+ cr = CommandResponse.from_json_response(res)
43
+ refute cr.success?
44
+ assert cr.fail?
45
+ assert cr.error?
46
+ assert_equal 255, cr.status
32
47
  end
33
48
 
34
49
  def test_to_json_response
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bixby-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chetan Sarva