Class: ErrorTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/vendor/xmpp4r/test/tc_errors.rb

Instance Method Summary collapse

Instance Method Details

#test_codeObject



102
103
104
105
106
107
108
109
110
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 102

def test_code
  e = ErrorResponse.new
  assert_nil(e.code)
  e.code = 404
  assert_equal(404, e.code)
  assert_equal("<error code='404'/>", e.to_s)
  e.code = nil
  assert_nil(e.code)
end

#test_createObject



55
56
57
58
59
60
61
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 55

def test_create
  e = ErrorResponse.new
  assert_equal(nil, e.error)
  assert_equal(nil, e.code)
  assert_equal(nil, e.type)
  assert_equal(nil, e.text)
end

#test_create2Object



63
64
65
66
67
68
69
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 63

def test_create2
  e = ErrorResponse.new('payment-required')
  assert_equal('payment-required', e.error)
  assert_equal(402, e.code)
  assert_equal(:auth, e.type)
  assert_equal(nil, e.text)
end

#test_create3Object



71
72
73
74
75
76
77
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 71

def test_create3
  e = ErrorResponse.new('gone', 'User moved to afterlife.gov')
  assert_equal('gone', e.error)
  assert_equal(302, e.code)
  assert_equal(:modify, e.type)
  assert_equal('User moved to afterlife.gov', e.text)
end

#test_create_invalidObject



79
80
81
82
83
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 79

def test_create_invalid
  assert_raise(Jabber::ArgumentError) {
    e = ErrorResponse.new('invalid error')
  }
end

#test_errorObject



112
113
114
115
116
117
118
119
120
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 112

def test_error
  e = ErrorResponse.new
  assert_nil(e.error)
  e.error = 'gone'
  assert_equal('gone', e.error)
  assert_raise(RuntimeError) {
    e.error = nil
  }
end

#test_sample_mucObject



138
139
140
141
142
143
144
145
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 138

def test_sample_muc
  src = '<error code="409">Please choose a different nickname.</error>'
  e = ErrorResponse.new.import(REXML::Document.new(src).root)
  assert_equal(nil, e.type)
  assert_equal(409, e.code)
  assert_equal(nil, e.error)
  assert_equal('Please choose a different nickname.', e.text)
end

#test_sample_normalObject



129
130
131
132
133
134
135
136
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 129

def test_sample_normal
  src = '<error code="302" type="modify"><gone xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">...</text></error>'
  e = ErrorResponse.new.import(REXML::Document.new(src).root)
  assert_equal(:modify, e.type)
  assert_equal(302, e.code)
  assert_equal('gone', e.error)
  assert_equal('...', e.text)
end

#test_stanzasObject



122
123
124
125
126
127
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 122

def test_stanzas
  m = Message.new
  assert_equal(nil, m.error)
  m.typed_add(ErrorResponse.new)
  assert_equal('<error/>', m.error.to_s)
end

#test_typeObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/vendor/xmpp4r/test/tc_errors.rb', line 85

def test_type
  e = ErrorResponse.new
  assert_nil(e.type)
  e.type = :auth
  assert_equal(:auth, e.type)
  e.type = :cancel
  assert_equal(:cancel, e.type)
  e.type = :continue
  assert_equal(:continue, e.type)
  e.type = :modify
  assert_equal(:modify, e.type)
  e.type = :wait
  assert_equal(:wait, e.type)
  e.type = nil
  assert_nil(e.type)
end