textmagic 0.3.3 → 0.4.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.
data/lib/textmagic.rb CHANGED
@@ -1,6 +1,6 @@
1
- require 'rubygems'
2
- gem 'httparty'
3
- require 'httparty'
1
+ require "rubygems"
2
+ gem "httparty"
3
+ require "httparty"
4
4
  %w[charset validation api response executor error].each do |lib|
5
5
  require File.join(File.dirname(__FILE__), lib)
6
6
  end
data/test/test_api.rb CHANGED
@@ -1,16 +1,18 @@
1
- require 'test_helper'
1
+ # encoding: utf-8
2
+
3
+ require "test_helper"
2
4
 
3
5
  class APITest < Test::Unit::TestCase
4
6
 
5
- context 'Initialization' do
7
+ context "Initialization" do
6
8
 
7
- should 'require username and password' do
9
+ should "require username and password" do
8
10
  lambda { TextMagic::API.new }.should raise_error(ArgumentError)
9
11
  TextMagic::API.new(random_string, random_string)
10
12
  end
11
13
  end
12
14
 
13
- context 'Account command' do
15
+ context "Account command" do
14
16
 
15
17
  setup do
16
18
  @username, @password = random_string, random_string
@@ -21,19 +23,19 @@ class APITest < Test::Unit::TestCase
21
23
  TextMagic::API::Response.stubs(:account).returns(@processed_response)
22
24
  end
23
25
 
24
- should 'call Executor execute with correct arguments' do
25
- TextMagic::API::Executor.expects(:execute).with('account', @username, @password).returns(@response)
26
+ should "call Executor execute with correct arguments" do
27
+ TextMagic::API::Executor.expects(:execute).with("account", @username, @password).returns(@response)
26
28
  @api.account
27
29
  end
28
30
 
29
- should 'call Response.account method to process the response hash' do
31
+ should "call Response.account method to process the response hash" do
30
32
  processed_response = rand
31
33
  TextMagic::API::Response.expects(:account).with(@response).returns(processed_response)
32
34
  @api.account.should == processed_response
33
35
  end
34
36
  end
35
37
 
36
- context 'Send command' do
38
+ context "Send command" do
37
39
 
38
40
  setup do
39
41
  @username, @password = random_string, random_string
@@ -45,82 +47,82 @@ class APITest < Test::Unit::TestCase
45
47
  TextMagic::API::Response.stubs(:send).returns(@processed_response)
46
48
  end
47
49
 
48
- should 'call Executor execute with correct arguments' do
49
- TextMagic::API::Executor.expects(:execute).with('send', @username, @password, :text => @text, :phone => @phone, :unicode => 0).returns(@response)
50
+ should "call Executor execute with correct arguments" do
51
+ TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 0).returns(@response)
50
52
  @api.send(@text, @phone)
51
53
  end
52
54
 
53
- should 'join multiple phone numbers supplied as an array' do
55
+ should "join multiple phone numbers supplied as an array" do
54
56
  phones = Array.new(3) { random_phone }
55
- TextMagic::API::Executor.expects(:execute).with('send', @username, @password, :text => @text, :phone => phones.join(','), :unicode => 0).returns(@response)
57
+ TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => phones.join(","), :unicode => 0).returns(@response)
56
58
  @api.send(@text, phones)
57
59
  end
58
60
 
59
- should 'join multiple phone numbers supplied as arguments' do
61
+ should "join multiple phone numbers supplied as arguments" do
60
62
  phones = Array.new(3) { random_phone }
61
- TextMagic::API::Executor.expects(:execute).with('send', @username, @password, :text => @text, :phone => phones.join(','), :unicode => 0).returns(@response)
63
+ TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => phones.join(","), :unicode => 0).returns(@response)
62
64
  @api.send(@text, *phones)
63
65
  end
64
66
 
65
- should 'replace true with 1 for unicode' do
66
- TextMagic::API::Executor.expects(:execute).with('send', @username, @password, :text => @text, :phone => @phone, :unicode => 1).returns(@response)
67
+ should "replace true with 1 for unicode" do
68
+ TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 1).returns(@response)
67
69
  @api.send(@text, @phone, :unicode => true)
68
70
  end
69
71
 
70
- should 'set unicode value to 0 if it is not set to by user and text contains only characters from GSM 03.38 charset' do
71
- TextMagic::API::Executor.expects(:execute).with('send', @username, @password, :text => @text, :phone => @phone, :unicode => 0).returns(@response).times(2)
72
+ should "set unicode value to 0 if it is not set to by user and text contains only characters from GSM 03.38 charset" do
73
+ TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 0).returns(@response).times(2)
72
74
  @api.send(@text, @phone)
73
75
  @api.send(@text, @phone, :unicode => false)
74
76
  end
75
77
 
76
- should 'raise an error if unicode is set to 0 and text contains characters outside of GSM 03.38 charset' do
77
- text = 'Вильма Привет'
78
+ should "raise an error if unicode is set to 0 and text contains characters outside of GSM 03.38 charset" do
79
+ text = "Вильма Привет"
78
80
  lambda { @api.send(text, @phone, :unicode => false) }.should raise_error(TextMagic::API::Error)
79
81
  end
80
82
 
81
- should 'raise an error if unicode value is not valid' do
83
+ should "raise an error if unicode value is not valid" do
82
84
  lambda { @api.send(@text, @phone, :unicode => 2 + rand(10)) }.should raise_error(TextMagic::API::Error)
83
85
  lambda { @api.send(@text, @phone, :unicode => random_string) }.should raise_error(TextMagic::API::Error)
84
86
  end
85
87
 
86
- should 'raise an error if no phone numbers are specified' do
88
+ should "raise an error if no phone numbers are specified" do
87
89
  lambda { @api.send(@text) }.should raise_error(TextMagic::API::Error)
88
90
  lambda { @api.send(@text, []) }.should raise_error(TextMagic::API::Error)
89
91
  end
90
92
 
91
- should 'raise an error if format of any of the specified phone numbers is invalid' do
93
+ should "raise an error if format of any of the specified phone numbers is invalid" do
92
94
  TextMagic::API.expects(:validate_phones).returns(false)
93
95
  lambda { @api.send(@text, random_string) }.should raise_error(TextMagic::API::Error)
94
96
  end
95
97
 
96
- should 'raise an error if text is empty' do
97
- lambda { @api.send('', @phone) }.should raise_error(TextMagic::API::Error)
98
+ should "raise an error if text is empty" do
99
+ lambda { @api.send("", @phone) }.should raise_error(TextMagic::API::Error)
98
100
  end
99
101
 
100
- should 'raise an error if text is too long' do
102
+ should "raise an error if text is too long" do
101
103
  TextMagic::API.expects(:validate_text_length).returns(false)
102
104
  lambda { @api.send(@text, @phone) }.should raise_error(TextMagic::API::Error)
103
105
  end
104
106
 
105
- should 'support send_time option' do
107
+ should "support send_time option" do
106
108
  time = Time.now + rand
107
- TextMagic::API::Executor.expects(:execute).with('send', @username, @password, :text => @text, :phone => @phone, :unicode => 0, :send_time => time.to_i).returns(@response)
109
+ TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 0, :send_time => time.to_i).returns(@response)
108
110
  @api.send(@text, @phone, :send_time => time.to_i)
109
111
  end
110
112
 
111
- should 'convert send_time to Fixnum' do
113
+ should "convert send_time to Fixnum" do
112
114
  time = Time.now + rand
113
- TextMagic::API::Executor.expects(:execute).with('send', @username, @password, :text => @text, :phone => @phone, :unicode => 0, :send_time => time.to_i).returns(@response)
115
+ TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 0, :send_time => time.to_i).returns(@response)
114
116
  @api.send(@text, @phone, :send_time => time)
115
117
  end
116
118
 
117
- should 'call Response.send method to process the response hash (single phone)' do
119
+ should "call Response.send method to process the response hash (single phone)" do
118
120
  processed_response = rand
119
121
  TextMagic::API::Response.expects(:send).with(@response, true).returns(processed_response)
120
122
  @api.send(@text, random_phone).should == processed_response
121
123
  end
122
124
 
123
- should 'call Response.send method to process the response hash (multiple phones)' do
125
+ should "call Response.send method to process the response hash (multiple phones)" do
124
126
  processed_response = rand
125
127
  TextMagic::API::Response.expects(:send).with(@response, false).returns(processed_response).twice
126
128
  @api.send(@text, [random_phone]).should == processed_response
@@ -128,7 +130,7 @@ class APITest < Test::Unit::TestCase
128
130
  end
129
131
  end
130
132
 
131
- context 'Message status command' do
133
+ context "Message status command" do
132
134
 
133
135
  setup do
134
136
  @username, @password = random_string, random_string
@@ -139,42 +141,42 @@ class APITest < Test::Unit::TestCase
139
141
  TextMagic::API::Response.stubs(:message_status).returns(@processed_response)
140
142
  end
141
143
 
142
- should 'call Executor execute with correct arguments' do
144
+ should "call Executor execute with correct arguments" do
143
145
  id = random_string
144
- TextMagic::API::Executor.expects(:execute).with('message_status', @username, @password, :ids => id).returns(@response)
146
+ TextMagic::API::Executor.expects(:execute).with("message_status", @username, @password, :ids => id).returns(@response)
145
147
  @api.message_status(id)
146
148
  end
147
149
 
148
- should 'join ids supplied as array' do
150
+ should "join ids supplied as array" do
149
151
  ids = Array.new(3) { random_string }
150
- TextMagic::API::Executor.expects(:execute).with('message_status', @username, @password, :ids => ids.join(','))
152
+ TextMagic::API::Executor.expects(:execute).with("message_status", @username, @password, :ids => ids.join(","))
151
153
  @api.message_status(ids)
152
154
  end
153
155
 
154
- should 'join ids supplied as arguments' do
156
+ should "join ids supplied as arguments" do
155
157
  ids = Array.new(3) { random_string }
156
- TextMagic::API::Executor.expects(:execute).with('message_status', @username, @password, :ids => ids.join(','))
158
+ TextMagic::API::Executor.expects(:execute).with("message_status", @username, @password, :ids => ids.join(","))
157
159
  @api.message_status(*ids)
158
160
  end
159
161
 
160
- should 'not call execute and should raise an exception if no ids are specified' do
162
+ should "not call execute and should raise an exception if no ids are specified" do
161
163
  TextMagic::API::Executor.expects(:execute).never
162
164
  lambda { @api.message_status }.should raise_error(TextMagic::API::Error)
163
165
  end
164
166
 
165
- should 'call Response.message_status method to process the response hash (single id)' do
167
+ should "call Response.message_status method to process the response hash (single id)" do
166
168
  TextMagic::API::Response.expects(:message_status).with(@response, true).returns(@processed_response)
167
169
  @api.message_status(random_string).should == @processed_response
168
170
  end
169
171
 
170
- should 'call Response.message_status method to process the response hash (multiple ids)' do
172
+ should "call Response.message_status method to process the response hash (multiple ids)" do
171
173
  TextMagic::API::Response.expects(:message_status).with(@response, false).returns(@processed_response).twice
172
174
  @api.message_status([random_string]).should == @processed_response
173
175
  @api.message_status(random_string, random_string).should == @processed_response
174
176
  end
175
177
  end
176
178
 
177
- context 'Receive command' do
179
+ context "Receive command" do
178
180
 
179
181
  setup do
180
182
  @username, @password = random_string, random_string
@@ -185,24 +187,24 @@ class APITest < Test::Unit::TestCase
185
187
  TextMagic::API::Response.stubs(:receive).returns(@processed_response)
186
188
  end
187
189
 
188
- should 'call Executor execute with correct arguments' do
189
- TextMagic::API::Executor.expects(:execute).with('receive', @username, @password, :last_retrieved_id => nil)
190
+ should "call Executor execute with correct arguments" do
191
+ TextMagic::API::Executor.expects(:execute).with("receive", @username, @password, :last_retrieved_id => nil)
190
192
  @api.receive
191
193
  end
192
194
 
193
- should 'accept last_retrieved_id optional value' do
195
+ should "accept last_retrieved_id optional value" do
194
196
  last_retrieved_id = rand(1e10)
195
- TextMagic::API::Executor.expects(:execute).with('receive', @username, @password, :last_retrieved_id => last_retrieved_id)
197
+ TextMagic::API::Executor.expects(:execute).with("receive", @username, @password, :last_retrieved_id => last_retrieved_id)
196
198
  @api.receive(last_retrieved_id)
197
199
  end
198
200
 
199
- should 'call Response.receive method to process the response hash' do
201
+ should "call Response.receive method to process the response hash" do
200
202
  TextMagic::API::Response.expects(:receive).with(@response).returns(@processed_response)
201
203
  @api.receive(random_string).should == @processed_response
202
204
  end
203
205
  end
204
206
 
205
- context 'Delete reply command' do
207
+ context "Delete reply command" do
206
208
 
207
209
  setup do
208
210
  @username, @password = random_string, random_string
@@ -213,35 +215,35 @@ class APITest < Test::Unit::TestCase
213
215
  TextMagic::API::Response.stubs(:delete_reply).returns(@processed_response)
214
216
  end
215
217
 
216
- should 'call Executor execute with correct arguments' do
218
+ should "call Executor execute with correct arguments" do
217
219
  id = random_string
218
- TextMagic::API::Executor.expects(:execute).with('delete_reply', @username, @password, :ids => id)
220
+ TextMagic::API::Executor.expects(:execute).with("delete_reply", @username, @password, :ids => id)
219
221
  @api.delete_reply(id)
220
222
  end
221
223
 
222
- should 'join ids supplied as array' do
224
+ should "join ids supplied as array" do
223
225
  ids = Array.new(3) { random_string }
224
- TextMagic::API::Executor.expects(:execute).with('delete_reply', @username, @password, :ids => ids.join(','))
226
+ TextMagic::API::Executor.expects(:execute).with("delete_reply", @username, @password, :ids => ids.join(","))
225
227
  @api.delete_reply(ids)
226
228
  end
227
229
 
228
- should 'join ids supplied as arguments' do
230
+ should "join ids supplied as arguments" do
229
231
  ids = Array.new(3) { random_string }
230
- TextMagic::API::Executor.expects(:execute).with('delete_reply', @username, @password, :ids => ids.join(','))
232
+ TextMagic::API::Executor.expects(:execute).with("delete_reply", @username, @password, :ids => ids.join(","))
231
233
  @api.delete_reply(*ids)
232
234
  end
233
235
 
234
- should 'not call execute and should raise an exception if no ids are specified' do
236
+ should "not call execute and should raise an exception if no ids are specified" do
235
237
  TextMagic::API::Executor.expects(:execute).never
236
238
  lambda { @api.delete_reply }.should raise_error(TextMagic::API::Error)
237
239
  end
238
240
 
239
- should 'return true' do
241
+ should "return true" do
240
242
  @api.delete_reply(random_string).should == true
241
243
  end
242
244
  end
243
245
 
244
- context 'Check number command' do
246
+ context "Check number command" do
245
247
 
246
248
  setup do
247
249
  @username, @password = random_string, random_string
@@ -252,35 +254,35 @@ class APITest < Test::Unit::TestCase
252
254
  TextMagic::API::Response.stubs(:check_number).returns(@processed_response)
253
255
  end
254
256
 
255
- should 'call Executor execute with correct arguments' do
257
+ should "call Executor execute with correct arguments" do
256
258
  phone = random_phone
257
- TextMagic::API::Executor.expects(:execute).with('check_number', @username, @password, :phone => phone)
259
+ TextMagic::API::Executor.expects(:execute).with("check_number", @username, @password, :phone => phone)
258
260
  @api.check_number(phone)
259
261
  end
260
262
 
261
- should 'join phones supplied as array' do
263
+ should "join phones supplied as array" do
262
264
  phones = Array.new(3) { random_phone }
263
- TextMagic::API::Executor.expects(:execute).with('check_number', @username, @password, :phone => phones.join(','))
265
+ TextMagic::API::Executor.expects(:execute).with("check_number", @username, @password, :phone => phones.join(","))
264
266
  @api.check_number(phones)
265
267
  end
266
268
 
267
- should 'join phones supplied as arguments' do
269
+ should "join phones supplied as arguments" do
268
270
  phones = Array.new(3) { random_phone }
269
- TextMagic::API::Executor.expects(:execute).with('check_number', @username, @password, :phone => phones.join(','))
271
+ TextMagic::API::Executor.expects(:execute).with("check_number", @username, @password, :phone => phones.join(","))
270
272
  @api.check_number(*phones)
271
273
  end
272
274
 
273
- should 'not call execute and should raise an exception if no phones are specified' do
275
+ should "not call execute and should raise an exception if no phones are specified" do
274
276
  TextMagic::API::Executor.expects(:execute).never
275
277
  lambda { @api.check_number }.should raise_error(TextMagic::API::Error)
276
278
  end
277
279
 
278
- should 'call Response.check_number method to process the response hash (single phone)' do
280
+ should "call Response.check_number method to process the response hash (single phone)" do
279
281
  TextMagic::API::Response.expects(:check_number).with(@response, true).returns(@processed_response)
280
282
  @api.check_number(random_string).should == @processed_response
281
283
  end
282
284
 
283
- should 'call Response.check_number method to process the response hash (mulitple phones)' do
285
+ should "call Response.check_number method to process the response hash (mulitple phones)" do
284
286
  TextMagic::API::Response.expects(:check_number).with(@response, false).returns(@processed_response).twice
285
287
  @api.check_number([random_string]).should == @processed_response
286
288
  @api.check_number(random_string, random_string).should == @processed_response
data/test/test_charset.rb CHANGED
@@ -1,14 +1,15 @@
1
- require 'test_helper'
2
- require 'json'
1
+ # encoding: utf-8
2
+
3
+ require "test_helper"
3
4
 
4
5
  class CharsetTest < Test::Unit::TestCase
5
6
 
6
- context 'is_gsm method' do
7
+ context "is_gsm method" do
7
8
 
8
- should 'return true if all characters are in GSM 03.38 charset' do
9
- TextMagic::API.is_gsm(('a'..'z').to_a.join).should == true
10
- TextMagic::API.is_gsm(('A'..'Z').to_a.join).should == true
11
- TextMagic::API.is_gsm(('0'..'9').to_a.join).should == true
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
12
13
  TextMagic::API.is_gsm("@£$¥€").should == true
13
14
  TextMagic::API.is_gsm("\n\r\e\f\\\"").should == true
14
15
  TextMagic::API.is_gsm("èéùìòÇØøÅåÉÆæß").should == true
@@ -18,24 +19,24 @@ class CharsetTest < Test::Unit::TestCase
18
19
  TextMagic::API.is_gsm("ÖÑÜöñüàäÄ").should == true
19
20
  end
20
21
 
21
- should 'return false if some characters are outside of GSM 03.38 charset' do
22
- TextMagic::API.is_gsm('Arabic: مرحبا فيلما').should == false
23
- TextMagic::API.is_gsm('Chinese: 您好').should == false
24
- TextMagic::API.is_gsm('Cyrilic: Вильма Привет').should == false
25
- TextMagic::API.is_gsm('Thai: สวัสดี').should == false
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
26
27
  end
27
28
  end
28
29
 
29
- context 'real_length method' do
30
+ context "real_length method" do
30
31
 
31
- should 'count escaped characters as two and all others as one for non-unicode text' do
32
+ should "count escaped characters as two and all others as one for non-unicode text" do
32
33
  escaped = "{}\\~[]|€"
33
34
  unescaped = random_string
34
35
  text = "#{escaped}#{unescaped}".scan(/./).sort_by { rand }.join
35
36
  TextMagic::API.real_length(text, false).should == unescaped.size + escaped.size * 2
36
37
  end
37
38
 
38
- should 'count all characters as one for unicode text' do
39
+ should "count all characters as one for unicode text" do
39
40
  escaped = "{}\\~[]|€"
40
41
  unescaped = random_string
41
42
  text = "#{escaped}#{unescaped}".scan(/./).sort_by { rand }.join
data/test/test_error.rb CHANGED
@@ -1,21 +1,21 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  class ErrorTest < Test::Unit::TestCase
4
4
 
5
- context 'Initialization' do
5
+ context "Initialization" do
6
6
 
7
7
  setup 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
13
- e = TextMagic::API::Error.new('error_code' => @code, 'error_message' => @message)
12
+ should "accept a hash with error_code and error_message" do
13
+ e = TextMagic::API::Error.new("error_code" => @code, "error_message" => @message)
14
14
  e.code.should == @code
15
15
  e.message.should == @message
16
16
  end
17
17
 
18
- should 'accept error_code and error_message' do
18
+ should "accept error_code and error_message" do
19
19
  e = TextMagic::API::Error.new(@code, @message)
20
20
  e.code.should == @code
21
21
  e.message.should == @message
@@ -1,5 +1,4 @@
1
- require 'test_helper'
2
- require 'json'
1
+ require "test_helper"
3
2
 
4
3
  class ExecutorTest < Test::Unit::TestCase
5
4
 
@@ -13,58 +12,58 @@ class ExecutorTest < Test::Unit::TestCase
13
12
  @uri = "http://www.textmagic.com/app/api"
14
13
  end
15
14
 
16
- should 'not send HTTP request without command' do
15
+ should "not send HTTP request without command" do
17
16
  TextMagic::API::Executor.expects(:post).never
18
17
  lambda {
19
18
  TextMagic::API::Executor.execute(nil, @username, @password, @options)
20
19
  }.should raise_error(TextMagic::API::Error)
21
20
  end
22
21
 
23
- should 'not send HTTP request without username' do
22
+ should "not send HTTP request without username" do
24
23
  TextMagic::API::Executor.expects(:post).never
25
24
  lambda {
26
25
  TextMagic::API::Executor.execute(@command, nil, @password, @options)
27
26
  }.should raise_error(TextMagic::API::Error)
28
27
  end
29
28
 
30
- should 'not send HTTP request without password' do
29
+ should "not send HTTP request without password" do
31
30
  TextMagic::API::Executor.expects(:post).never
32
31
  lambda {
33
32
  TextMagic::API::Executor.execute(@command, @username, nil, @options)
34
33
  }.should raise_error(TextMagic::API::Error)
35
34
  end
36
35
 
37
- should 'send a POST request to proper uri' do
36
+ should "send a POST request to proper uri" do
38
37
  response = random_string
39
- FakeWeb.register_uri(:post, @uri, :string => response)
38
+ FakeWeb.register_uri(:post, @uri, :body => response)
40
39
  TextMagic::API::Executor.execute(@command, @username, @password, @options)
41
40
  end
42
41
 
43
- should 'not send parameters with empty keys' do
44
- options_with_empty_values = @options.merge(nil => random_string, '' => random_string)
42
+ should "not send parameters with empty keys" do
43
+ options_with_empty_values = @options.merge(nil => random_string, "" => random_string)
45
44
  @options.merge!(:username => @username, :password => @password, :cmd => @command)
46
- TextMagic::API::Executor.expects(:post).with('/api', :body => @options, :format => :json)
45
+ TextMagic::API::Executor.expects(:post).with("/api", :body => @options, :format => :json)
47
46
  TextMagic::API::Executor.execute(@command, @username, @password, options_with_empty_values)
48
47
  end
49
48
 
50
- should 'not send parameters with empty values' do
51
- options_with_empty_values = @options.merge(random_string => nil, random_string => '')
49
+ should "not send parameters with empty values" do
50
+ options_with_empty_values = @options.merge(random_string => nil, random_string => "")
52
51
  @options.merge!(:username => @username, :password => @password, :cmd => @command)
53
- TextMagic::API::Executor.expects(:post).with('/api', :body => @options, :format => :json)
52
+ TextMagic::API::Executor.expects(:post).with("/api", :body => @options, :format => :json)
54
53
  TextMagic::API::Executor.execute(@command, @username, @password, options_with_empty_values)
55
54
  end
56
55
 
57
- should 'raise an error if the response contains error_code' do
56
+ should "raise an error if the response contains error_code" do
58
57
  response = "{error_code:#{1 + rand(10)}}"
59
- FakeWeb.register_uri(:post, @uri, :string => response)
58
+ FakeWeb.register_uri(:post, @uri, :body => response)
60
59
  lambda {
61
60
  TextMagic::API::Executor.execute(@command, @username, @password, @options)
62
61
  }.should raise_error(TextMagic::API::Error)
63
62
  end
64
63
 
65
- should 'return a hash with values from the response' do
66
- hash = random_hash
67
- FakeWeb.register_uri(:post, @uri, :string => hash.to_json)
64
+ should "return a hash with values from the response" do
65
+ hash = { "this" => "is", "just" => "a", "random" => "hash" }
66
+ FakeWeb.register_uri(:post, @uri, :body => '{"this":"is","just":"a","random":"hash"}')
68
67
  response = TextMagic::API::Executor.execute(@command, @username, @password, @options)
69
68
  response.should == hash
70
69
  end