textmagic 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,45 +2,45 @@
2
2
 
3
3
  require "test_helper"
4
4
 
5
- class CharsetTest < Test::Unit::TestCase
6
-
7
- context "is_gsm method" do
8
-
9
- should "return true if all characters are in GSM 03.38 charset" do
10
- TextMagic::API.is_gsm(("a".."z").to_a.join).should == true
11
- TextMagic::API.is_gsm(("A".."Z").to_a.join).should == true
12
- TextMagic::API.is_gsm(("0".."9").to_a.join).should == true
13
- TextMagic::API.is_gsm("@£$¥€").should == true
14
- TextMagic::API.is_gsm("\n\r\e\f\\\"").should == true
15
- TextMagic::API.is_gsm("èéùìòÇØøÅåÉÆæß").should == true
16
- TextMagic::API.is_gsm("ΔΦΓΛΩΠΨΣΘΞ").should == true
17
- TextMagic::API.is_gsm("^{}[~]| !#¤%&'()").should == true
18
- TextMagic::API.is_gsm("*+,-./_:;<=>?¡¿§").should == true
19
- TextMagic::API.is_gsm("ÖÑÜöñüàäÄ").should == true
5
+ describe "Charset" do
6
+
7
+ describe "is_gsm method" do
8
+
9
+ it "should return true if all characters are in GSM 03.38 charset" do
10
+ assert_equal true, TextMagic::API.is_gsm(("a".."z").to_a.join)
11
+ assert_equal true, TextMagic::API.is_gsm(("A".."Z").to_a.join)
12
+ assert_equal true, TextMagic::API.is_gsm(("0".."9").to_a.join)
13
+ assert_equal true, TextMagic::API.is_gsm("@£$¥€")
14
+ assert_equal true, TextMagic::API.is_gsm("\n\r\e\f\\\"")
15
+ assert_equal true, TextMagic::API.is_gsm("èéùìòÇØøÅåÉÆæß")
16
+ assert_equal true, TextMagic::API.is_gsm("ΔΦΓΛΩΠΨΣΘΞ")
17
+ assert_equal true, TextMagic::API.is_gsm("^{}[~]| !#¤%&'()")
18
+ assert_equal true, TextMagic::API.is_gsm("*+,-./_:;<=>?¡¿§")
19
+ assert_equal true, TextMagic::API.is_gsm("ÖÑÜöñüàäÄ")
20
20
  end
21
21
 
22
- should "return false if some characters are outside of GSM 03.38 charset" do
23
- TextMagic::API.is_gsm("Arabic: مرحبا فيلما").should == false
24
- TextMagic::API.is_gsm("Chinese: 您好").should == false
25
- TextMagic::API.is_gsm("Cyrilic: Вильма Привет").should == false
26
- TextMagic::API.is_gsm("Thai: สวัสดี").should == false
22
+ it "should return false if some characters are outside of GSM 03.38 charset" do
23
+ assert_equal false, TextMagic::API.is_gsm("Arabic: مرحبا فيلما")
24
+ assert_equal false, TextMagic::API.is_gsm("Chinese: 您好")
25
+ assert_equal false, TextMagic::API.is_gsm("Cyrilic: Вильма Привет")
26
+ assert_equal false, TextMagic::API.is_gsm("Thai: สวัสดี")
27
27
  end
28
28
  end
29
29
 
30
- context "real_length method" do
30
+ describe "real_length method" do
31
31
 
32
- should "count escaped characters as two and all others as one for non-unicode text" do
32
+ it "should count escaped characters as two and all others as one for non-unicode text" do
33
33
  escaped = "{}\\~[]|€"
34
34
  unescaped = random_string
35
35
  text = "#{escaped}#{unescaped}".scan(/./).sort_by { rand }.join
36
- TextMagic::API.real_length(text, false).should == unescaped.size + escaped.size * 2
36
+ assert_equal unescaped.size + escaped.size * 2, TextMagic::API.real_length(text, false)
37
37
  end
38
38
 
39
- should "count all characters as one for unicode text" do
39
+ it "should count all characters as one for unicode text" do
40
40
  escaped = "{}\\~[]|€"
41
41
  unescaped = random_string
42
42
  text = "#{escaped}#{unescaped}".scan(/./).sort_by { rand }.join
43
- TextMagic::API.real_length(text, true).should == unescaped.size + escaped.size
43
+ assert_equal unescaped.size + escaped.size, TextMagic::API.real_length(text, true)
44
44
  end
45
45
  end
46
46
  end
@@ -1,24 +1,24 @@
1
1
  require "test_helper"
2
2
 
3
- class ErrorTest < Test::Unit::TestCase
3
+ describe "Error" do
4
4
 
5
- context "Initialization" do
5
+ describe "Initialization" do
6
6
 
7
- setup do
7
+ before do
8
8
  @code = rand(1e3)
9
9
  @message = random_string
10
10
  end
11
11
 
12
- should "accept a hash with error_code and error_message" do
12
+ it "should accept a hash with error_code and error_message" do
13
13
  e = TextMagic::API::Error.new("error_code" => @code, "error_message" => @message)
14
- e.code.should == @code
15
- e.message.should == @message
14
+ assert_equal @code, e.code
15
+ assert_equal @message, e.message
16
16
  end
17
17
 
18
- should "accept error_code and error_message" do
18
+ it "should accept error_code and error_message" do
19
19
  e = TextMagic::API::Error.new(@code, @message)
20
- e.code.should == @code
21
- e.message.should == @message
20
+ assert_equal @code, e.code
21
+ assert_equal @message, e.message
22
22
  end
23
23
  end
24
24
  end
@@ -1,71 +1,68 @@
1
1
  require "test_helper"
2
2
 
3
- class ExecutorTest < Test::Unit::TestCase
3
+ describe "Executor" do
4
4
 
5
- context "execute method" do
5
+ describe "execute method" do
6
6
 
7
- setup do
7
+ before do
8
8
  FakeWeb.allow_net_connect = false
9
9
 
10
10
  @username, @password = random_string, random_string
11
11
  @command, @options = random_string, random_hash
12
- @uri = "http://www.textmagic.com/app/api"
12
+ @uri = "https://www.textmagic.com/app/api"
13
13
  end
14
14
 
15
- should "not send HTTP request without command" do
16
- TextMagic::API::Executor.expects(:post).never
17
- lambda {
15
+ it "should not send HTTP request without command" do
16
+ assert_raises TextMagic::API::Error do
18
17
  TextMagic::API::Executor.execute(nil, @username, @password, @options)
19
- }.should raise_error(TextMagic::API::Error)
18
+ end
20
19
  end
21
20
 
22
- should "not send HTTP request without username" do
21
+ it "should not send HTTP request without username" do
23
22
  TextMagic::API::Executor.expects(:post).never
24
- lambda {
25
- TextMagic::API::Executor.execute(@command, nil, @password, @options)
26
- }.should raise_error(TextMagic::API::Error)
23
+ assert_raises(TextMagic::API::Error) { TextMagic::API::Executor.execute(@command, nil, @password, @options) }
27
24
  end
28
25
 
29
- should "not send HTTP request without password" do
26
+ it "should not send HTTP request without password" do
30
27
  TextMagic::API::Executor.expects(:post).never
31
- lambda {
28
+ assert_raises TextMagic::API::Error do
32
29
  TextMagic::API::Executor.execute(@command, @username, nil, @options)
33
- }.should raise_error(TextMagic::API::Error)
30
+ end
34
31
  end
35
32
 
36
- should "send a POST request to proper uri" do
33
+ it "should send a POST request to proper uri" do
37
34
  response = "{}"
38
35
  FakeWeb.register_uri(:post, @uri, :body => response)
39
36
  TextMagic::API::Executor.execute(@command, @username, @password, @options)
40
37
  end
41
38
 
42
- should "not send parameters with nil keys" do
39
+ it "should not send parameters with nil keys" do
43
40
  options_with_empty_values = @options.merge(nil => random_string)
44
41
  @options.merge!(:username => @username, :password => @password, :cmd => @command)
45
42
  TextMagic::API::Executor.expects(:post).with("/api", :body => @options, :format => :json)
46
43
  TextMagic::API::Executor.execute(@command, @username, @password, options_with_empty_values)
47
44
  end
48
45
 
49
- should "not send parameters with nil values" do
46
+ it "should not send parameters with nil values" do
50
47
  options_with_empty_values = @options.merge(random_string => nil)
51
48
  @options.merge!(:username => @username, :password => @password, :cmd => @command)
52
49
  TextMagic::API::Executor.expects(:post).with("/api", :body => @options, :format => :json)
53
50
  TextMagic::API::Executor.execute(@command, @username, @password, options_with_empty_values)
54
51
  end
55
52
 
56
- should "raise an error if the response contains error_code" do
53
+ it "should raise an error if the response contains error_code" do
57
54
  response = "{\"error_code\":#{1 + rand(10)}}"
58
55
  FakeWeb.register_uri(:post, @uri, :body => response)
59
- lambda {
56
+ assert_raises TextMagic::API::Error do
60
57
  TextMagic::API::Executor.execute(@command, @username, @password, @options)
61
- }.should raise_error(TextMagic::API::Error)
58
+ end
62
59
  end
63
60
 
64
- should "return a hash with values from the response" do
61
+ it "should return a hash with values from the response" do
65
62
  hash = { "this" => "is", "just" => "a", "random" => "hash" }
66
63
  FakeWeb.register_uri(:post, @uri, :body => '{"this":"is","just":"a","random":"hash"}')
67
64
  response = TextMagic::API::Executor.execute(@command, @username, @password, @options)
68
- response.should == hash
65
+ assert_equal hash, response.to_hash
69
66
  end
70
67
  end
71
68
  end
@@ -1,17 +1,5 @@
1
- require "rubygems"
2
- require "test/unit"
3
- require "shoulda"
4
- require "mocha"
5
- require "matchy"
6
- require "fakeweb"
7
-
8
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
9
- $LOAD_PATH.unshift(File.dirname(__FILE__))
10
-
11
- require "textmagic"
12
-
13
- class Test::Unit::TestCase
14
- end
1
+ require "bundler"
2
+ Bundler.require
15
3
 
16
4
  def random_string(legth = 5 + rand(10))
17
5
  Array.new(legth) { rand(36).to_s(36) }.join
@@ -26,3 +14,11 @@ def random_hash
26
14
  3.times { hash[random_string] = random_string }
27
15
  hash
28
16
  end
17
+
18
+ class Minitest::Test
19
+
20
+ def self.it(name, &block)
21
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
22
+ define_method(test_name, &block)
23
+ end
24
+ end
@@ -1,27 +1,27 @@
1
1
  require "test_helper"
2
2
 
3
- class ResponseTest < Test::Unit::TestCase
3
+ describe "Response" do
4
4
 
5
- context "Response to account command" do
5
+ describe "Response to account command" do
6
6
 
7
- setup do
7
+ before do
8
8
  @balance = 0.1 * rand(1e4)
9
9
  @hash = { "balance" => @balance.to_s }
10
10
  @response = TextMagic::API::Response.account(@hash)
11
11
  end
12
12
 
13
- should "be an OpenStruct instance" do
14
- @response.class.should == OpenStruct
13
+ it "should be an OpenStruct instance" do
14
+ assert_kind_of OpenStruct, @response
15
15
  end
16
16
 
17
- should "have balance" do
18
- @response.balance.should be_close(@balance, 1e-10)
17
+ it "should have balance" do
18
+ assert_in_delta @response.balance, @balance, 1e-10
19
19
  end
20
20
  end
21
21
 
22
- context "Response to send command with single phone number" do
22
+ describe "Response to send command with single phone number" do
23
23
 
24
- setup do
24
+ before do
25
25
  @message_id, @phone = random_string, random_phone
26
26
  @text = random_string
27
27
  @parts_count = 1 + rand(3)
@@ -29,22 +29,22 @@ class ResponseTest < Test::Unit::TestCase
29
29
  @response = TextMagic::API::Response.send(@hash, true)
30
30
  end
31
31
 
32
- should "equal to the message_id" do
33
- @response.should == @message_id
32
+ it "should equal to the message_id" do
33
+ assert_equal @message_id, @response
34
34
  end
35
35
 
36
- should "have sent_text" do
37
- @response.sent_text.should == @text
36
+ it "should have sent_text" do
37
+ assert_equal @text, @response.sent_text
38
38
  end
39
39
 
40
- should "have parts_count" do
41
- @response.parts_count.should == @parts_count
40
+ it "should have parts_count" do
41
+ assert_equal @parts_count, @response.parts_count
42
42
  end
43
43
  end
44
44
 
45
- context "Response to send command with multiple phone numbers" do
45
+ describe "Response to send command with multiple phone numbers" do
46
46
 
47
- setup do
47
+ before do
48
48
  @message_id1, @phone1 = random_string, random_phone
49
49
  @message_id2, @phone2 = random_string, random_phone
50
50
  @text = random_string
@@ -53,31 +53,31 @@ class ResponseTest < Test::Unit::TestCase
53
53
  @response = TextMagic::API::Response.send(@hash, false)
54
54
  end
55
55
 
56
- should "be a hash" do
57
- @response.class.should == Hash
56
+ it "should be a hash" do
57
+ assert_kind_of Hash, @response
58
58
  end
59
59
 
60
- should "have phone numbers as keys" do
61
- @response.keys.sort.should == [@phone1, @phone2].sort
60
+ it "should have phone numbers as keys" do
61
+ assert_equal [@phone1, @phone2].sort, @response.keys.sort
62
62
  end
63
63
 
64
- should "have message ids as values" do
65
- @response[@phone1].should == @message_id1
66
- @response[@phone2].should == @message_id2
64
+ it "should have message ids as values" do
65
+ assert_equal @message_id1, @response[@phone1]
66
+ assert_equal @message_id2, @response[@phone2]
67
67
  end
68
68
 
69
- should "have sent_text" do
70
- @response.sent_text.should == @text
69
+ it "should have sent_text" do
70
+ assert_equal @text, @response.sent_text
71
71
  end
72
72
 
73
- should "have parts_count" do
74
- @response.parts_count.should == @parts_count
73
+ it "should have parts_count" do
74
+ assert_equal @parts_count, @response.parts_count
75
75
  end
76
76
  end
77
77
 
78
- context "Response to message_status command with single id" do
78
+ describe "Response to message_status command with single id" do
79
79
 
80
- setup do
80
+ before do
81
81
  @text = random_string
82
82
  @status = random_string
83
83
  @reply_number = random_phone
@@ -97,38 +97,38 @@ class ResponseTest < Test::Unit::TestCase
97
97
  @response = TextMagic::API::Response.message_status(@hash, true)
98
98
  end
99
99
 
100
- should "equal to the message status" do
101
- @response.should == @status
100
+ it "should equal to the message status" do
101
+ assert_equal @status, @response
102
102
  end
103
103
 
104
- should "have text" do
105
- @response.text.should == @text
104
+ it "should have text" do
105
+ assert_equal @text, @response.text
106
106
  end
107
107
 
108
- should "have created_time" do
109
- @response.created_time.should == Time.at(@created_time)
108
+ it "should have created_time" do
109
+ assert_equal Time.at(@created_time), @response.created_time
110
110
  end
111
111
 
112
- should "have completed_time" do
113
- @response.completed_time.should == Time.at(@completed_time)
112
+ it "should have completed_time" do
113
+ assert_equal Time.at(@completed_time), @response.completed_time
114
114
  end
115
115
 
116
- should "have reply_number" do
117
- @response.reply_number.should == @reply_number
116
+ it "should have reply_number" do
117
+ assert_equal @reply_number, @response.reply_number
118
118
  end
119
119
 
120
- should "have credits_cost" do
121
- @response.credits_cost.should be_close(@credits_cost, 1e-10)
120
+ it "should have credits_cost" do
121
+ assert_in_delta @response.credits_cost, @credits_cost, 1e-10
122
122
  end
123
123
 
124
- should "have status" do
125
- @response.status.should == @status
124
+ it "should have status" do
125
+ assert_equal @status, @response.status
126
126
  end
127
127
  end
128
128
 
129
- context "Response to message_status command with multiple ids" do
129
+ describe "Response to message_status command with multiple ids" do
130
130
 
131
- setup do
131
+ before do
132
132
  @text = random_string
133
133
  @status = random_string
134
134
  @reply_number = random_phone
@@ -148,46 +148,46 @@ class ResponseTest < Test::Unit::TestCase
148
148
  @response = TextMagic::API::Response.message_status(@hash, false)
149
149
  end
150
150
 
151
- should "be a hash" do
152
- @response.class.should == Hash
151
+ it "should be a hash" do
152
+ assert_kind_of Hash, @response
153
153
  end
154
154
 
155
- should "have message_ids as keys" do
156
- @response.keys.should == ["141421"]
155
+ it "should have message_ids as keys" do
156
+ assert_equal ["141421"], @response.keys
157
157
  end
158
158
 
159
- should "contain statuses" do
160
- @response.values.first.should == @status
159
+ it "should contain statuses" do
160
+ assert_equal @status, @response.values.first
161
161
  end
162
162
 
163
- should "have text for all statuses" do
164
- @response.values.first.text.should == @text
163
+ it "should have text for all statuses" do
164
+ assert_equal @text, @response.values.first.text
165
165
  end
166
166
 
167
- should "have created_time for all statuses" do
168
- @response.values.first.created_time.should == Time.at(@created_time)
167
+ it "should have created_time for all statuses" do
168
+ assert_equal Time.at(@created_time), @response.values.first.created_time
169
169
  end
170
170
 
171
- should "have completed_time for all statuses" do
172
- @response.values.first.completed_time.should == Time.at(@completed_time)
171
+ it "should have completed_time for all statuses" do
172
+ assert_equal Time.at(@completed_time), @response.values.first.completed_time
173
173
  end
174
174
 
175
- should "have reply_number for all statuses" do
176
- @response.values.first.reply_number.should == @reply_number
175
+ it "should have reply_number for all statuses" do
176
+ assert_equal @reply_number, @response.values.first.reply_number
177
177
  end
178
178
 
179
- should "have status for all statuses" do
180
- @response.values.first.status.should == @status
179
+ it "should have status for all statuses" do
180
+ assert_equal @status, @response.values.first.status
181
181
  end
182
182
 
183
- should "have credits_cost for all statuses" do
184
- @response.values.first.credits_cost.should be_close(@credits_cost, 1e-10)
183
+ it "should have credits_cost for all statuses" do
184
+ assert_in_delta @response.values.first.credits_cost, @credits_cost, 1e-10
185
185
  end
186
186
  end
187
187
 
188
- context "Response to receive command" do
188
+ describe "Response to receive command" do
189
189
 
190
- setup do
190
+ before do
191
191
  @timestamp = (Time.now - 30).to_i
192
192
  @text, @phone, @message_id = random_string, random_phone, random_string
193
193
  @message = {
@@ -201,38 +201,38 @@ class ResponseTest < Test::Unit::TestCase
201
201
  @response = TextMagic::API::Response.receive(@hash)
202
202
  end
203
203
 
204
- should "have unread" do
205
- @response.unread.should == @unread
204
+ it "should have unread" do
205
+ assert_equal @unread, @response.unread
206
206
  end
207
207
 
208
- should "be an array" do
209
- @response.class.should == Array
208
+ it "should be an array" do
209
+ assert_kind_of Array, @response
210
210
  end
211
211
 
212
- should "contain strings with phones numbers and texts" do
213
- @response.first.should == "#{@phone}: #{@text}"
212
+ it "should contain strings with phones numbers and texts" do
213
+ assert_equal "#{@phone}: #{@text}", @response.first
214
214
  end
215
215
 
216
- should "have timestamp for all messages" do
217
- @response.first.timestamp.should == Time.at(@timestamp)
216
+ it "should have timestamp for all messages" do
217
+ assert_equal Time.at(@timestamp), @response.first.timestamp
218
218
  end
219
219
 
220
- should "have from for all messages" do
221
- @response.first.from.should == @phone
220
+ it "should have from for all messages" do
221
+ assert_equal @phone, @response.first.from
222
222
  end
223
223
 
224
- should "have text for all messages" do
225
- @response.first.text.should == @text
224
+ it "should have text for all messages" do
225
+ assert_equal @text, @response.first.text
226
226
  end
227
227
 
228
- should "have message_id for all messages" do
229
- @response.first.message_id.should == @message_id
228
+ it "should have message_id for all messages" do
229
+ assert_equal @message_id, @response.first.message_id
230
230
  end
231
231
  end
232
232
 
233
- context "Response to check_number command with single phone" do
233
+ describe "Response to check_number command with single phone" do
234
234
 
235
- setup do
235
+ before do
236
236
  @phone = random_phone
237
237
  @price = rand
238
238
  @country = random_string
@@ -245,22 +245,22 @@ class ResponseTest < Test::Unit::TestCase
245
245
  @response = TextMagic::API::Response.check_number(@hash, true)
246
246
  end
247
247
 
248
- should "be an OpenStruct instance" do
249
- @response.class.should == OpenStruct
248
+ it "should be an OpenStruct instance" do
249
+ assert_kind_of OpenStruct, @response
250
250
  end
251
251
 
252
- should "have price" do
253
- @response.price.should be_close(@price, 1e-10)
252
+ it "should have price" do
253
+ assert_in_delta @response.price, @price, 1e-10
254
254
  end
255
255
 
256
- should "have country" do
257
- @response.country.should == @country
256
+ it "should have country" do
257
+ assert_equal @country, @response.country
258
258
  end
259
259
  end
260
260
 
261
- context "Response to check_number command with multiple phones" do
261
+ describe "Response to check_number command with multiple phones" do
262
262
 
263
- setup do
263
+ before do
264
264
  @phone = random_phone
265
265
  @price = rand
266
266
  @country = random_string
@@ -273,24 +273,24 @@ class ResponseTest < Test::Unit::TestCase
273
273
  @response = TextMagic::API::Response.check_number(@hash, false)
274
274
  end
275
275
 
276
- should "be a hash" do
277
- @response.class.should == Hash
276
+ it "should be a hash" do
277
+ assert_kind_of Hash, @response
278
278
  end
279
279
 
280
- should "have phones as keys" do
281
- @response.keys.should == [@phone]
280
+ it "should have phones as keys" do
281
+ assert_equal [@phone], @response.keys
282
282
  end
283
283
 
284
- should "contain OpenStruct instances" do
285
- @response.values.first.class.should == OpenStruct
284
+ it "should contain OpenStruct instances" do
285
+ assert_kind_of OpenStruct, @response.values.first
286
286
  end
287
287
 
288
- should "have price for all phones" do
289
- @response.values.first.price.should be_close(@price, 1e-10)
288
+ it "should have price for all phones" do
289
+ assert_in_delta @response.values.first.price, @price, 1e-10
290
290
  end
291
291
 
292
- should "have country for all phones" do
293
- @response.values.first.country.should == @country
292
+ it "should have country for all phones" do
293
+ assert_equal @response.values.first.country, @country
294
294
  end
295
295
  end
296
296
  end