bubble-wrap 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,11 @@
1
+ ## 0.3.1
2
+
3
+ * Added App.run_after(delay){ }
4
+ * HTTP responses return true to ok? when the status code is 20x.
5
+
1
6
  ## 0.3.0
2
7
 
3
- * Major refactoring preparing for 1.0: https://github.com/mattetti/BubbleWrap/compare/v0.2.1v0.3.0
8
+ * Major refactoring preparing for 1.0: [List of commits](https://github.com/mattetti/BubbleWrap/compare/v0.2.1...v0.3.0)
4
9
 
5
10
  ## 0.2.1
6
11
 
data/README.md CHANGED
@@ -96,6 +96,10 @@ A module with useful methods related to the running application
96
96
  # "testSuite"
97
97
  > App.identifier
98
98
  # "io.bubblewrap.testSuite"
99
+ > App.alert("BubbleWrap is awesome!")
100
+ # creates and shows an alert message.
101
+ > App.run_after(0.5) { p "It's #{Time.now}" }
102
+ # Runs the block after 0.5 seconds.
99
103
  ```
100
104
 
101
105
  ## NSUserDefaults
@@ -11,7 +11,7 @@ module Motion
11
11
  # dependencies.
12
12
  def files_dependencies(deps_hash)
13
13
  res_path = lambda do |x|
14
- path = /^\.|\/Users\//.match(x) ? x : File.join('.', x)
14
+ path = /^\.?\//.match(x) ? x : File.join('.', x)
15
15
  unless @files.include?(path)
16
16
  App.fail "Can't resolve dependency `#{x}' because #{path} is not in #{@files.inspect}"
17
17
  end
@@ -36,6 +36,18 @@ module BubbleWrap
36
36
  alert
37
37
  end
38
38
 
39
+ # Executes a block after a certain delay
40
+ # Usage example:
41
+ # App.run_after(0.5) { p "It's #{Time.now}" }
42
+ def run_after(delay,&block)
43
+ NSTimer.scheduledTimerWithTimeInterval( delay,
44
+ target: block,
45
+ selector: "call:",
46
+ userInfo: nil,
47
+ repeats: false)
48
+ end
49
+
50
+
39
51
  @states = {}
40
52
 
41
53
  def states
@@ -73,7 +73,7 @@ module BubbleWrap
73
73
  end
74
74
 
75
75
  def ok?
76
- status_code == 200
76
+ status_code.to_s =~ /20\d/ ? true : false
77
77
  end
78
78
 
79
79
  end
@@ -1,3 +1,3 @@
1
1
  module BubbleWrap
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -80,4 +80,19 @@ describe BubbleWrap::App do
80
80
  BW::App.delegate.class.should == TestSuiteDelegate
81
81
  end
82
82
  end
83
+
84
+ describe '.run_after' do
85
+ class DelayedRunAfterTest; attr_accessor :test_value end
86
+
87
+ it 'should run a block after the provided delay' do
88
+ @test_obj = DelayedRunAfterTest.new
89
+
90
+ App.run_after(0.1){ @test_obj.test_value = true }
91
+ wait_for_change(@test_obj, 'test_value') do
92
+ @test_obj.test_value.should == true
93
+ end
94
+ end
95
+
96
+ end
97
+
83
98
  end
@@ -1,363 +1,365 @@
1
1
  describe "HTTP" do
2
2
 
3
- end
3
+ describe "HTTP::Response" do
4
+ before do
5
+ @response = BubbleWrap::HTTP::Response.new({ status_code: 200, url: 'http://localhost' })
6
+ end
4
7
 
8
+ it 'should turn the initialization Hash to instance variables' do
9
+ @response.instance_variable_get(:@status_code).should == 200
10
+ @response.instance_variable_get(:@url).should == 'http://localhost'
11
+ end
5
12
 
6
- describe "HTTP::Response" do
7
- before do
8
- @response = BubbleWrap::HTTP::Response.new({ status_code: 200, url: 'http://localhost' })
9
- end
13
+ it "says OK status code 20x" do
14
+ @response.ok?.should.equal true
15
+ (200..206).each do |code|
16
+ BubbleWrap::HTTP::Response.new({status_code: code}).ok?.should.be.true
17
+ end
18
+ [100..101, 300..307, 400..417, 500..505].inject([]){|codes, rg| codes += rg.to_a}.each do |code|
19
+ BubbleWrap::HTTP::Response.new({status_code: code}).ok?.should.be.false
20
+ end
21
+ end
10
22
 
11
- it 'should turn the initialization Hash to instance variables' do
12
- @response.instance_variable_get(:@status_code).should == 200
13
- @response.instance_variable_get(:@url).should == 'http://localhost'
14
- end
23
+ it "has appropriate attributes" do
24
+ @response.should.respond_to :body
25
+ @response.should.respond_to :headers
26
+ @response.should.respond_to :url
27
+ @response.should.respond_to :status_code=
28
+ @response.should.respond_to :error_message=
29
+ end
15
30
 
16
- it "says OK only for status code 200" do
17
- @response.ok?.should.equal true
18
- BubbleWrap::HTTP::Response.new({status_code: 205}).ok?.should.not.equal true
19
- end
20
-
21
- it "has appropriate attributes" do
22
- @response.should.respond_to :body
23
- @response.should.respond_to :headers
24
- @response.should.respond_to :url
25
- @response.should.respond_to :status_code=
26
- @response.should.respond_to :error_message=
27
31
  end
28
32
 
29
- end
33
+ describe "HTTP::Query" do
30
34
 
31
- describe "HTTP::Query" do
32
-
33
- before do
34
- @credentials = { credit_card: 23423948234 }
35
- @payload = {
36
- user: { name: 'marin', surname: 'usalj' },
37
- twitter: '@mneorr',
38
- website: 'mneorr.com',
39
- values: [1, 2, 3],
40
- credentials: @credentials
41
- }
42
- @action = lambda{|fa, ke|}
43
- @cache_policy = 24234
44
- @leftover_option = 'trololo'
45
- @headers = { 'User-Agent' => "Mozilla/5.0 (X11; Linux x86_64; rv:12.0) \n Gecko/20100101 Firefox/12.0" }
46
- @options = { action: @action,
47
- payload: @payload,
48
- credentials: @credentials,
49
- headers: @headers,
50
- cache_policy: @cache_policy,
51
- leftover_option: @leftover_option
52
- }
53
- @query = BubbleWrap::HTTP::Query.new( 'http://localhost' , :get, @options )
54
- end
35
+ before do
36
+ @credentials = { credit_card: 23423948234 }
37
+ @payload = {
38
+ user: { name: 'marin', surname: 'usalj' },
39
+ twitter: '@mneorr',
40
+ website: 'mneorr.com',
41
+ values: [1, 2, 3],
42
+ credentials: @credentials
43
+ }
44
+ @action = lambda{|fa, ke|}
45
+ @cache_policy = 24234
46
+ @leftover_option = 'trololo'
47
+ @headers = { 'User-Agent' => "Mozilla/5.0 (X11; Linux x86_64; rv:12.0) \n Gecko/20100101 Firefox/12.0" }
48
+ @options = { action: @action,
49
+ payload: @payload,
50
+ credentials: @credentials,
51
+ headers: @headers,
52
+ cache_policy: @cache_policy,
53
+ leftover_option: @leftover_option
54
+ }
55
+ @query = BubbleWrap::HTTP::Query.new( 'http://localhost' , :get, @options )
56
+ end
57
+
58
+ it "has appropriate attributes" do
59
+ @query.should.respond_to :request=
60
+ @query.should.respond_to :connection=
61
+ @query.should.respond_to :credentials=
62
+ @query.should.respond_to :proxy_credential=
63
+ @query.should.respond_to :post_data=
64
+
65
+ @query.should.respond_to :method
66
+ @query.should.respond_to :response
67
+ @query.should.respond_to :status_code
68
+ @query.should.respond_to :response_headers
69
+ @query.should.respond_to :response_size
70
+ @query.should.respond_to :options
71
+ end
72
+
73
+ describe "When initialized" do
74
+
75
+ it "should upcase the HTTP method" do
76
+ @query.method.should.equal "GET"
77
+ end
78
+
79
+ it "should set the deleted delegator from options" do
80
+ @query.instance_variable_get(:@delegator).should.equal @action
81
+ @options.should.not.has_key? :action
82
+ end
83
+
84
+ it "should set self as the delegator if action not passed in" do
85
+ new_query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, {})
86
+ new_query.instance_variable_get(:@delegator).should.equal new_query
87
+ end
88
+
89
+ it "should merge :username and :password in loaded credentials" do
90
+ @query.credentials.should.equal @credentials.merge({:username => '', :password => ''})
91
+
92
+ new_credentials = {:username => 'user', :password => 'pass'}
93
+ options = { credentials: new_credentials }
94
+ new_query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, options)
95
+
96
+ new_query.credentials.should.equal new_credentials
97
+ options.should.be.empty
98
+ end
99
+
100
+ it "should set payload from options{} to @payload" do
101
+ payload = "user[name]=marin&user[surname]=usalj&twitter=@mneorr&website=mneorr.com&values=[1, 2, 3]&credentials[credit_card]=23423948234"
102
+ @query.instance_variable_get(:@payload).should.equal payload
103
+ @options.should.not.has_key? :payload
104
+ end
105
+
106
+ it "should set default timeout to 30s or the one from hash" do
107
+ @query.instance_variable_get(:@timeout).should == 30
108
+
109
+ options = {timeout: 10}
110
+ new_query = BubbleWrap::HTTP::Query.new( 'http://localhost/', :get, options)
111
+
112
+ new_query.instance_variable_get(:@timeout).should == 10
113
+ options.should.be.empty
114
+ end
55
115
 
56
- it "has appropriate attributes" do
57
- @query.should.respond_to :request=
58
- @query.should.respond_to :connection=
59
- @query.should.respond_to :credentials=
60
- @query.should.respond_to :proxy_credential=
61
- @query.should.respond_to :post_data=
62
-
63
- @query.should.respond_to :method
64
- @query.should.respond_to :response
65
- @query.should.respond_to :status_code
66
- @query.should.respond_to :response_headers
67
- @query.should.respond_to :response_size
68
- @query.should.respond_to :options
69
- end
116
+ it "should delete :headers from options and escape Line Feeds" do
117
+ gsubbed = @headers['User-Agent'].gsub("\n", '\\n')
118
+ @headers['User-Agent'] = gsubbed
119
+ @query.instance_variable_get(:@headers).should.equal @headers
120
+ end
70
121
 
71
- describe "When initialized" do
122
+ it "should delete :cache_policy or set NSURLRequestUseProtocolCachePolicy" do
123
+ @query.instance_variable_get(:@cachePolicy).should.equal @cache_policy
124
+ @options.should.not.has_key? :cache_policy
72
125
 
73
- it "should upcase the HTTP method" do
74
- @query.method.should.equal "GET"
75
- end
126
+ new_query = BubbleWrap::HTTP::Query.new( 'http://fakehost.local/', :get, {})
127
+ new_query.instance_variable_get(:@cachePolicy).should.equal NSURLRequestUseProtocolCachePolicy
128
+ end
76
129
 
77
- it "should set the deleted delegator from options" do
78
- @query.instance_variable_get(:@delegator).should.equal @action
79
- @options.should.not.has_key? :action
80
- end
130
+ it "should set the rest of options{} to ivar @options" do
131
+ @query.options.size.should.equal 1
132
+ @query.options.values[0].should.equal @leftover_option
133
+ end
81
134
 
82
- it "should set self as the delegator if action not passed in" do
83
- new_query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, {})
84
- new_query.instance_variable_get(:@delegator).should.equal new_query
85
- end
86
-
87
- it "should merge :username and :password in loaded credentials" do
88
- @query.credentials.should.equal @credentials.merge({:username => '', :password => ''})
135
+ it "should create a new response before instantiating a new request" do
136
+ @query.response.should.not.equal nil
137
+ end
89
138
 
90
- new_credentials = {:username => 'user', :password => 'pass'}
91
- options = { credentials: new_credentials }
92
- new_query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, options)
93
-
94
- new_query.credentials.should.equal new_credentials
95
- options.should.be.empty
96
- end
139
+ it "should call initiate_request with the URL passed in" do
140
+ processed_url = "http://localhost?user%5Bname%5D=marin&user%5Bsurname%5D=usalj&twitter=@mneorr&website=mneorr.com&values=%5B1,%202,%203%5D&credentials%5Bcredit_card%5D=23423948234"
141
+ @query.instance_variable_get(:@url).description.should.equal processed_url
142
+ end
97
143
 
98
- it "should set payload from options{} to @payload" do
99
- payload = "user[name]=marin&user[surname]=usalj&twitter=@mneorr&website=mneorr.com&values=[1, 2, 3]&credentials[credit_card]=23423948234"
100
- @query.instance_variable_get(:@payload).should.equal payload
101
- @options.should.not.has_key? :payload
102
- end
144
+ it "should start the connection" do
145
+ @query.connection.was_started.should.equal true
146
+ end
103
147
 
104
- it "should set default timeout to 30s or the one from hash" do
105
- @query.instance_variable_get(:@timeout).should == 30
148
+ it "should return the connection" do
149
+ # @query.call(:initialize)('http://localhost', :get, {}).connection.should.equal @query
150
+ #not sure about this one
151
+ true.should.equal true
152
+ end
106
153
 
107
- options = {timeout: 10}
108
- new_query = BubbleWrap::HTTP::Query.new( 'http://localhost/', :get, options)
109
-
110
- new_query.instance_variable_get(:@timeout).should == 10
111
- options.should.be.empty
112
- end
113
-
114
- it "should delete :headers from options and escape Line Feeds" do
115
- gsubbed = @headers['User-Agent'].gsub("\n", '\\n')
116
- @headers['User-Agent'] = gsubbed
117
- @query.instance_variable_get(:@headers).should.equal @headers
118
- end
154
+ it "should turn on the network indicator" do
155
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should.equal true
156
+ end
119
157
 
120
- it "should delete :cache_policy or set NSURLRequestUseProtocolCachePolicy" do
121
- @query.instance_variable_get(:@cachePolicy).should.equal @cache_policy
122
- @options.should.not.has_key? :cache_policy
123
-
124
- new_query = BubbleWrap::HTTP::Query.new( 'http://fakehost.local/', :get, {})
125
- new_query.instance_variable_get(:@cachePolicy).should.equal NSURLRequestUseProtocolCachePolicy
126
158
  end
127
159
 
128
- it "should set the rest of options{} to ivar @options" do
129
- @query.options.size.should.equal 1
130
- @query.options.values[0].should.equal @leftover_option
131
- end
160
+ describe "Generating GET params" do
132
161
 
133
- it "should create a new response before instantiating a new request" do
134
- @query.response.should.not.equal nil
135
- end
162
+ it "should create params with nested hashes with prefix[key]=value" do
163
+ expected_params = [
164
+ 'user[name]=marin',
165
+ 'user[surname]=usalj',
166
+ 'twitter=@mneorr',
167
+ 'website=mneorr.com',
168
+ 'values=[1, 2, 3]',
169
+ 'credentials[credit_card]=23423948234'
170
+ ]
171
+ @query.generate_get_params(@payload).should.equal expected_params
172
+ end
136
173
 
137
- it "should call initiate_request with the URL passed in" do
138
- processed_url = "http://localhost?user%5Bname%5D=marin&user%5Bsurname%5D=usalj&twitter=@mneorr&website=mneorr.com&values=%5B1,%202,%203%5D&credentials%5Bcredit_card%5D=23423948234"
139
- @query.instance_variable_get(:@url).description.should.equal processed_url
140
174
  end
141
175
 
142
- it "should start the connection" do
143
- @query.connection.was_started.should.equal true
144
- end
176
+ describe "when didReceiveResponse:" do
145
177
 
146
- it "should return the connection" do
147
- # @query.call(:initialize)('http://localhost', :get, {}).connection.should.equal @query
148
- #not sure about this one
149
- true.should.equal true
150
- end
178
+ it "should assign status_code, headers and response_size" do
179
+ headers = { foo: 'bar' }
180
+ status_code = 234
181
+ length = 123.53
151
182
 
152
- it "should turn on the network indicator" do
153
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should.equal true
154
- end
183
+ response = FakeURLResponse.new(status_code, headers, length)
184
+ @query.connection(nil, didReceiveResponse:response)
155
185
 
156
- end
186
+ @query.status_code.should.equal status_code
187
+ @query.response_headers.should.equal headers
188
+ @query.response_size.should.equal length
189
+ end
157
190
 
158
- describe "Generating GET params" do
159
-
160
- it "should create params with nested hashes with prefix[key]=value" do
161
- expected_params = [
162
- 'user[name]=marin',
163
- 'user[surname]=usalj',
164
- 'twitter=@mneorr',
165
- 'website=mneorr.com',
166
- 'values=[1, 2, 3]',
167
- 'credentials[credit_card]=23423948234'
168
- ]
169
- @query.generate_get_params(@payload).should.equal expected_params
170
191
  end
171
192
 
172
- end
173
-
174
- describe "when didReceiveResponse:" do
193
+ describe "when didRecieveData:" do
175
194
 
176
- it "should assign status_code, headers and response_size" do
177
- headers = { foo: 'bar' }
178
- status_code = 234
179
- length = 123.53
195
+ def query_received_data
196
+ @query.instance_variable_get(:@received_data)
197
+ end
180
198
 
181
- response = FakeURLResponse.new(status_code, headers, length)
182
- @query.connection(nil, didReceiveResponse:response)
199
+ it "should initialize @received_data and append the received data" do
200
+ query_received_data.should.equal nil
201
+ data = NSData.dataWithBytesNoCopy(Pointer.new(:char, 'abc'), length:24)
183
202
 
184
- @query.status_code.should.equal status_code
185
- @query.response_headers.should.equal headers
186
- @query.response_size.should.equal length
187
- end
203
+ @query.connection(nil, didReceiveData:nil)
204
+ query_received_data.should.not.equal nil
188
205
 
189
- end
206
+ @query.connection(nil, didReceiveData:data)
207
+ query_received_data.length.should.equal 24
190
208
 
191
- describe "when didRecieveData:" do
209
+ @query.connection(nil, didReceiveData:data)
210
+ query_received_data.length.should.equal 48
211
+ end
192
212
 
193
- def query_received_data
194
- @query.instance_variable_get(:@received_data)
195
213
  end
196
214
 
197
- it "should initialize @received_data and append the received data" do
198
- query_received_data.should.equal nil
199
- data = NSData.dataWithBytesNoCopy(Pointer.new(:char, 'abc'), length:24)
200
215
 
201
- @query.connection(nil, didReceiveData:nil)
202
- query_received_data.should.not.equal nil
203
216
 
204
- @query.connection(nil, didReceiveData:data)
205
- query_received_data.length.should.equal 24
217
+ describe "when requestDidFailWithError:" do
218
+ before do
219
+ @fake_error = NSError.errorWithDomain('testing', code:7768, userInfo:nil)
220
+ end
206
221
 
207
- @query.connection(nil, didReceiveData:data)
208
- query_received_data.length.should.equal 48
209
- end
222
+ it "should turn off network indicator" do
223
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
210
224
 
211
- end
225
+ @query.connection(nil, didFailWithError:@fake_error)
226
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
227
+ end
212
228
 
229
+ it "should set request_done to true" do
230
+ @query.request.done_loading.should == false
213
231
 
232
+ @query.connection(nil, didFailWithError:@fake_error)
233
+ @query.request.done_loading.should == true
234
+ end
214
235
 
215
- describe "when requestDidFailWithError:" do
216
- before do
217
- @fake_error = NSError.errorWithDomain('testing', code:7768, userInfo:nil)
218
- end
236
+ it "should set the error message to response object" do
237
+ @query.response.error_message.should.equal nil
219
238
 
220
- it "should turn off network indicator" do
221
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
239
+ @query.connection(nil, didFailWithError:@fake_error)
240
+ @query.response.error_message.should.equal @fake_error.localizedDescription
241
+ end
222
242
 
223
- @query.connection(nil, didFailWithError:@fake_error)
224
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
225
- end
243
+ it "should check if there's a callback block and pass the response in" do
244
+ expected_response = BubbleWrap::HTTP::Response.new
245
+ real_response = nil
246
+ block = lambda{ |response, query| real_response = response }
226
247
 
227
- it "should set request_done to true" do
228
- @query.request.done_loading.should == false
248
+ query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
249
+ query.instance_variable_set(:@response, expected_response)
229
250
 
230
- @query.connection(nil, didFailWithError:@fake_error)
231
- @query.request.done_loading.should == true
232
- end
251
+ query.connection(nil, didFailWithError:@fake_error)
252
+ real_response.should.equal expected_response
253
+ end
233
254
 
234
- it "should set the error message to response object" do
235
- @query.response.error_message.should.equal nil
236
-
237
- @query.connection(nil, didFailWithError:@fake_error)
238
- @query.response.error_message.should.equal @fake_error.localizedDescription
239
255
  end
240
256
 
241
- it "should check if there's a callback block and pass the response in" do
242
- expected_response = BubbleWrap::HTTP::Response.new
243
- real_response = nil
244
- block = lambda{ |response, query| real_response = response }
257
+ describe "when connectionDidFinishLoading:" do
245
258
 
246
- query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
247
- query.instance_variable_set(:@response, expected_response)
259
+ it "should turn off the network indicator" do
260
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
248
261
 
249
- query.connection(nil, didFailWithError:@fake_error)
250
- real_response.should.equal expected_response
251
- end
262
+ @query.connectionDidFinishLoading(nil)
263
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
264
+ end
252
265
 
253
- end
266
+ it "should set request_done to true" do
267
+ @query.request.done_loading.should == false
254
268
 
255
- describe "when connectionDidFinishLoading:" do
269
+ @query.connectionDidFinishLoading(nil)
270
+ @query.request.done_loading.should == true
271
+ end
256
272
 
257
- it "should turn off the network indicator" do
258
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
273
+ it "should set response_body to @received data if not nil" do
274
+ data = NSData.dataWithBytesNoCopy(Pointer.new(:char, 'abc'), length:24)
275
+ headers = { foo: 'bar' }
276
+ status_code = 234
277
+ response = FakeURLResponse.new(status_code, headers, 65456)
259
278
 
260
- @query.connectionDidFinishLoading(nil)
261
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
262
- end
279
+ @query.connection(nil, didReceiveResponse:response)
280
+ @query.connection(nil, didReceiveData:data)
281
+ @query.connectionDidFinishLoading(nil)
263
282
 
264
- it "should set request_done to true" do
265
- @query.request.done_loading.should == false
283
+ @query.response.body.should.equal data
284
+ @query.response.status_code.should.equal status_code
285
+ @query.response.headers.should.equal headers
286
+ @query.response.url.should.equal @query.instance_variable_get(:@url)
287
+ end
266
288
 
267
- @query.connectionDidFinishLoading(nil)
268
- @query.request.done_loading.should == true
269
- end
289
+ it "should check if there's a callback block and pass the response in" do
290
+ expected_response = BubbleWrap::HTTP::Response.new
291
+ real_response = nil
292
+ block = lambda{ |response, query| real_response = response }
270
293
 
271
- it "should set response_body to @received data if not nil" do
272
- data = NSData.dataWithBytesNoCopy(Pointer.new(:char, 'abc'), length:24)
273
- headers = { foo: 'bar' }
274
- status_code = 234
275
- response = FakeURLResponse.new(status_code, headers, 65456)
294
+ query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
295
+ query.instance_variable_set(:@response, expected_response)
276
296
 
277
- @query.connection(nil, didReceiveResponse:response)
278
- @query.connection(nil, didReceiveData:data)
279
- @query.connectionDidFinishLoading(nil)
297
+ query.connectionDidFinishLoading(nil)
298
+ real_response.should.equal expected_response
299
+ end
280
300
 
281
- @query.response.body.should.equal data
282
- @query.response.status_code.should.equal status_code
283
- @query.response.headers.should.equal headers
284
- @query.response.url.should.equal @query.instance_variable_get(:@url)
285
301
  end
286
302
 
287
- it "should check if there's a callback block and pass the response in" do
288
- expected_response = BubbleWrap::HTTP::Response.new
289
- real_response = nil
290
- block = lambda{ |response, query| real_response = response }
303
+ describe "when connection:willSendRequest:redirectResponse:" do
304
+ before do
305
+ @request = NSURLRequest.requestWithURL NSURL.URLWithString('http://fakehost.local/')
306
+ end
291
307
 
292
- query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
293
- query.instance_variable_set(:@response, expected_response)
308
+ it "should make a mutableCopy of passed in request and set headers from @headers" do
309
+ expected_headers = { new_header: 'should_be_here' }
310
+ @query.instance_variable_set(:@headers, expected_headers)
294
311
 
295
- query.connectionDidFinishLoading(nil)
296
- real_response.should.equal expected_response
297
- end
312
+ new_request = @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
298
313
 
299
- end
314
+ @query.request.should.not.be.equal @request
315
+ new_request.URL.description.should.equal @request.URL.description
316
+ new_request.allHTTPHeaderFields.should.equal expected_headers
317
+ end
300
318
 
301
- describe "when connection:willSendRequest:redirectResponse:" do
302
- before do
303
- @request = NSURLRequest.requestWithURL NSURL.URLWithString('http://fakehost.local/')
304
- end
319
+ it "should create a new Connection with the request passed in" do
320
+ old_connection = @query.connection
321
+ @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
305
322
 
306
- it "should make a mutableCopy of passed in request and set headers from @headers" do
307
- expected_headers = { new_header: 'should_be_here' }
308
- @query.instance_variable_set(:@headers, expected_headers)
323
+ old_connection.should.not.equal @query.connection
324
+ end
309
325
 
310
- new_request = @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
311
-
312
- @query.request.should.not.be.equal @request
313
- new_request.URL.description.should.equal @request.URL.description
314
- new_request.allHTTPHeaderFields.should.equal expected_headers
315
- end
326
+ it "should set itself as a delegate of new NSURLConnection" do
327
+ @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
328
+ @query.connection.delegate.should.equal @query
329
+ end
316
330
 
317
- it "should create a new Connection with the request passed in" do
318
- old_connection = @query.connection
319
- @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
331
+ it "should pass the new request in the new connection" do
332
+ @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
333
+ @query.connection.request.URL.description.should.equal @request.URL.description
334
+ end
320
335
 
321
- old_connection.should.not.equal @query.connection
322
336
  end
323
337
 
324
- it "should set itself as a delegate of new NSURLConnection" do
325
- @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
326
- @query.connection.delegate.should.equal @query
338
+ class BubbleWrap::HTTP::Query
339
+ def create_connection(request, delegate); FakeURLConnection.new(request, delegate); end
327
340
  end
328
341
 
329
- it "should pass the new request in the new connection" do
330
- @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
331
- @query.connection.request.URL.description.should.equal @request.URL.description
342
+ class FakeURLConnection < NSURLConnection
343
+ attr_reader :delegate, :request, :was_started
344
+ def initialize(request, delegate)
345
+ @request = request
346
+ @delegate = delegate
347
+ self.class.connectionWithRequest(request, delegate:delegate)
348
+ end
349
+ def start
350
+ @was_started = true
351
+ super
352
+ end
332
353
  end
333
354
 
334
- end
335
-
336
- class BubbleWrap::HTTP::Query
337
- def create_connection(request, delegate); FakeURLConnection.new(request, delegate); end
338
- end
339
-
340
- class FakeURLConnection < NSURLConnection
341
- attr_reader :delegate, :request, :was_started
342
- def initialize(request, delegate)
343
- @request = request
344
- @delegate = delegate
345
- self.class.connectionWithRequest(request, delegate:delegate)
346
- end
347
- def start
348
- @was_started = true
349
- super
355
+ class FakeURLResponse
356
+ attr_reader :statusCode, :allHeaderFields, :expectedContentLength
357
+ def initialize(status_code, headers, length)
358
+ @statusCode = status_code
359
+ @allHeaderFields = headers
360
+ @expectedContentLength = length
361
+ end
350
362
  end
351
- end
352
363
 
353
- class FakeURLResponse
354
- attr_reader :statusCode, :allHeaderFields, :expectedContentLength
355
- def initialize(status_code, headers, length)
356
- @statusCode = status_code
357
- @allHeaderFields = headers
358
- @expectedContentLength = length
359
- end
360
364
  end
361
-
362
-
363
- end
365
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bubble-wrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-03 00:00:00.000000000 Z
13
+ date: 2012-06-04 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: RubyMotion wrappers and helpers (Ruby for iOS) - Making Cocoa APIs more
16
16
  Ruby like, one API at a time. Fork away and send your pull request.