bubble-wrap 0.2.1 → 0.3.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/.gitignore +2 -0
- data/CHANGELOG.md +4 -0
- data/README.md +26 -15
- data/Rakefile +3 -2
- data/lib/bubble-wrap.rb +2 -2
- data/lib/bubble-wrap/app.rb +58 -33
- data/lib/bubble-wrap/device.rb +66 -0
- data/lib/bubble-wrap/device/screen.rb +69 -0
- data/lib/bubble-wrap/gestures.rb +15 -14
- data/lib/bubble-wrap/http.rb +25 -19
- data/lib/bubble-wrap/module.rb +24 -0
- data/lib/bubble-wrap/ns_notification_center.rb +8 -10
- data/lib/bubble-wrap/persistence.rb +27 -0
- data/lib/bubble-wrap/time.rb +8 -0
- data/lib/bubble-wrap/{ui_button.rb → ui_control.rb} +1 -1
- data/lib/bubble-wrap/version.rb +1 -1
- data/lib/pollute.rb +1 -1
- data/lib/tests/test_suite_delegate.rb +2 -0
- data/spec/app_spec.rb +83 -0
- data/spec/device/screen_spec.rb +153 -0
- data/spec/device_spec.rb +112 -0
- data/spec/gestures_spec.rb +51 -0
- data/spec/http_spec.rb +363 -0
- data/spec/json_spec.rb +0 -2
- data/spec/module_spec.rb +2 -0
- data/spec/ns_index_path_spec.rb +8 -6
- data/spec/ns_notification_center_spec.rb +14 -9
- data/spec/persistence_spec.rb +20 -0
- data/spec/time_spec.rb +41 -0
- data/spec/{ui_button_spec.rb → ui_control_spec.rb} +11 -1
- metadata +24 -6
- data/lib/bubble-wrap/kernel.rb +0 -105
@@ -0,0 +1,51 @@
|
|
1
|
+
describe UIView do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@view = App.delegate.window.rootViewController.view
|
5
|
+
@orig = @view.isUserInteractionEnabled
|
6
|
+
@view.setUserInteractionEnabled false
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
@view.setUserInteractionEnabled @orig
|
11
|
+
end
|
12
|
+
|
13
|
+
testMethod = proc do |method|
|
14
|
+
it 'enables interaction when called' do
|
15
|
+
@view.send(method, &:nil)
|
16
|
+
@view.isUserInteractionEnabled.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "doesn't enable interaction if asked not to" do
|
20
|
+
@view.send(method, false, &:nil)
|
21
|
+
@view.isUserInteractionEnabled.should == false
|
22
|
+
end
|
23
|
+
|
24
|
+
# it 'responds to interaction'
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#whenTapped' do
|
28
|
+
testMethod.call :whenTapped
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#whenPinched' do
|
32
|
+
testMethod.call :whenPinched
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#whenRotated' do
|
36
|
+
testMethod.call :whenRotated
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#whenSwiped' do
|
40
|
+
testMethod.call :whenSwiped
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#whenPanned' do
|
44
|
+
testMethod.call :whenPanned
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#whenPressed' do
|
48
|
+
testMethod.call :whenPressed
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/spec/http_spec.rb
CHANGED
@@ -0,0 +1,363 @@
|
|
1
|
+
describe "HTTP" do
|
2
|
+
|
3
|
+
end
|
4
|
+
|
5
|
+
|
6
|
+
describe "HTTP::Response" do
|
7
|
+
before do
|
8
|
+
@response = BubbleWrap::HTTP::Response.new({ status_code: 200, url: 'http://localhost' })
|
9
|
+
end
|
10
|
+
|
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
|
15
|
+
|
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
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
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
|
55
|
+
|
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
|
70
|
+
|
71
|
+
describe "When initialized" do
|
72
|
+
|
73
|
+
it "should upcase the HTTP method" do
|
74
|
+
@query.method.should.equal "GET"
|
75
|
+
end
|
76
|
+
|
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
|
81
|
+
|
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 => ''})
|
89
|
+
|
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
|
97
|
+
|
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
|
103
|
+
|
104
|
+
it "should set default timeout to 30s or the one from hash" do
|
105
|
+
@query.instance_variable_get(:@timeout).should == 30
|
106
|
+
|
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
|
119
|
+
|
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
|
+
end
|
127
|
+
|
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
|
132
|
+
|
133
|
+
it "should create a new response before instantiating a new request" do
|
134
|
+
@query.response.should.not.equal nil
|
135
|
+
end
|
136
|
+
|
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
|
+
end
|
141
|
+
|
142
|
+
it "should start the connection" do
|
143
|
+
@query.connection.was_started.should.equal true
|
144
|
+
end
|
145
|
+
|
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
|
151
|
+
|
152
|
+
it "should turn on the network indicator" do
|
153
|
+
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should.equal true
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
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
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "when didReceiveResponse:" do
|
175
|
+
|
176
|
+
it "should assign status_code, headers and response_size" do
|
177
|
+
headers = { foo: 'bar' }
|
178
|
+
status_code = 234
|
179
|
+
length = 123.53
|
180
|
+
|
181
|
+
response = FakeURLResponse.new(status_code, headers, length)
|
182
|
+
@query.connection(nil, didReceiveResponse:response)
|
183
|
+
|
184
|
+
@query.status_code.should.equal status_code
|
185
|
+
@query.response_headers.should.equal headers
|
186
|
+
@query.response_size.should.equal length
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "when didRecieveData:" do
|
192
|
+
|
193
|
+
def query_received_data
|
194
|
+
@query.instance_variable_get(:@received_data)
|
195
|
+
end
|
196
|
+
|
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
|
+
|
201
|
+
@query.connection(nil, didReceiveData:nil)
|
202
|
+
query_received_data.should.not.equal nil
|
203
|
+
|
204
|
+
@query.connection(nil, didReceiveData:data)
|
205
|
+
query_received_data.length.should.equal 24
|
206
|
+
|
207
|
+
@query.connection(nil, didReceiveData:data)
|
208
|
+
query_received_data.length.should.equal 48
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
describe "when requestDidFailWithError:" do
|
216
|
+
before do
|
217
|
+
@fake_error = NSError.errorWithDomain('testing', code:7768, userInfo:nil)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should turn off network indicator" do
|
221
|
+
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
|
222
|
+
|
223
|
+
@query.connection(nil, didFailWithError:@fake_error)
|
224
|
+
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should set request_done to true" do
|
228
|
+
@query.request.done_loading.should == false
|
229
|
+
|
230
|
+
@query.connection(nil, didFailWithError:@fake_error)
|
231
|
+
@query.request.done_loading.should == true
|
232
|
+
end
|
233
|
+
|
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
|
+
end
|
240
|
+
|
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 }
|
245
|
+
|
246
|
+
query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
|
247
|
+
query.instance_variable_set(:@response, expected_response)
|
248
|
+
|
249
|
+
query.connection(nil, didFailWithError:@fake_error)
|
250
|
+
real_response.should.equal expected_response
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "when connectionDidFinishLoading:" do
|
256
|
+
|
257
|
+
it "should turn off the network indicator" do
|
258
|
+
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
|
259
|
+
|
260
|
+
@query.connectionDidFinishLoading(nil)
|
261
|
+
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should set request_done to true" do
|
265
|
+
@query.request.done_loading.should == false
|
266
|
+
|
267
|
+
@query.connectionDidFinishLoading(nil)
|
268
|
+
@query.request.done_loading.should == true
|
269
|
+
end
|
270
|
+
|
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)
|
276
|
+
|
277
|
+
@query.connection(nil, didReceiveResponse:response)
|
278
|
+
@query.connection(nil, didReceiveData:data)
|
279
|
+
@query.connectionDidFinishLoading(nil)
|
280
|
+
|
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
|
+
end
|
286
|
+
|
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 }
|
291
|
+
|
292
|
+
query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
|
293
|
+
query.instance_variable_set(:@response, expected_response)
|
294
|
+
|
295
|
+
query.connectionDidFinishLoading(nil)
|
296
|
+
real_response.should.equal expected_response
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
describe "when connection:willSendRequest:redirectResponse:" do
|
302
|
+
before do
|
303
|
+
@request = NSURLRequest.requestWithURL NSURL.URLWithString('http://fakehost.local/')
|
304
|
+
end
|
305
|
+
|
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)
|
309
|
+
|
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
|
316
|
+
|
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)
|
320
|
+
|
321
|
+
old_connection.should.not.equal @query.connection
|
322
|
+
end
|
323
|
+
|
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
|
327
|
+
end
|
328
|
+
|
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
|
332
|
+
end
|
333
|
+
|
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
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
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
|
+
end
|
361
|
+
|
362
|
+
|
363
|
+
end
|
data/spec/json_spec.rb
CHANGED
@@ -47,7 +47,6 @@ EOS
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should convert an array into a Ruby array" do
|
50
|
-
p Bacon::Counter.inspect
|
51
50
|
obj = BubbleWrap::JSON.parse("[1,2,3]")
|
52
51
|
obj.class.should == Array
|
53
52
|
obj.size.should == 3
|
@@ -78,7 +77,6 @@ EOS
|
|
78
77
|
end
|
79
78
|
|
80
79
|
it "should convert an array into a Ruby array" do
|
81
|
-
p Bacon::Counter.inspect
|
82
80
|
obj = BubbleWrap::JSON.parse("[1,2,3]")
|
83
81
|
obj.class.should == Array
|
84
82
|
obj.size.should == 3
|
data/spec/module_spec.rb
ADDED
data/spec/ns_index_path_spec.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
describe "NSIndexPathWrap" do
|
2
2
|
|
3
|
+
before do
|
4
|
+
@index = NSIndexPath.indexPathForRow(0, inSection:3)
|
5
|
+
end
|
6
|
+
|
3
7
|
it "should be able to use an array like accessor" do
|
4
|
-
index
|
5
|
-
index[0].should == index.indexAtPosition(0)
|
8
|
+
@index[0].should == @index.indexAtPosition(0)
|
6
9
|
end
|
7
10
|
|
8
11
|
it "should support the each iterator" do
|
9
|
-
index
|
10
|
-
puts index.inspect
|
12
|
+
puts @index.inspect
|
11
13
|
i = []
|
12
|
-
index.each do |idx|
|
14
|
+
@index.each do |idx|
|
13
15
|
i << idx
|
14
16
|
end
|
15
|
-
i.should == [
|
17
|
+
i.should == [3, 0]
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|