bubble-wrap 0.3.1 → 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.
Files changed (48) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/README.md +183 -66
  3. data/Rakefile +6 -6
  4. data/bubble-wrap.gemspec +10 -5
  5. data/lib/bubble-wrap.rb +4 -39
  6. data/lib/bubble-wrap/core.rb +7 -0
  7. data/lib/bubble-wrap/ext.rb +2 -0
  8. data/lib/bubble-wrap/ext/motion_project_app.rb +26 -0
  9. data/lib/bubble-wrap/ext/motion_project_config.rb +21 -0
  10. data/lib/bubble-wrap/http.rb +2 -249
  11. data/lib/bubble-wrap/loader.rb +23 -0
  12. data/lib/bubble-wrap/requirement.rb +88 -0
  13. data/lib/bubble-wrap/requirement/path_manipulation.rb +40 -0
  14. data/lib/bubble-wrap/version.rb +1 -1
  15. data/lib_spec/bubble-wrap/requirement/path_manipulation_spec.rb +51 -0
  16. data/lib_spec/bubble-wrap/requirement_spec.rb +72 -0
  17. data/lib_spec/bubble-wrap_spec.rb +17 -0
  18. data/lib_spec/motion_stub.rb +12 -0
  19. data/{lib/bubble-wrap/module.rb → motion/core.rb} +0 -0
  20. data/{lib/bubble-wrap → motion/core}/app.rb +0 -0
  21. data/{lib/bubble-wrap → motion/core}/device.rb +0 -16
  22. data/{lib/bubble-wrap → motion/core}/device/screen.rb +0 -0
  23. data/{lib/bubble-wrap → motion/core}/gestures.rb +0 -0
  24. data/{lib/bubble-wrap → motion/core}/json.rb +0 -0
  25. data/{lib/bubble-wrap → motion/core}/ns_index_path.rb +0 -0
  26. data/{lib/bubble-wrap → motion/core}/ns_notification_center.rb +0 -0
  27. data/{lib/bubble-wrap → motion/core}/ns_user_defaults.rb +0 -0
  28. data/{lib/bubble-wrap → motion/core}/persistence.rb +0 -0
  29. data/{lib → motion/core}/pollute.rb +1 -1
  30. data/motion/core/string.rb +38 -0
  31. data/{lib/bubble-wrap → motion/core}/time.rb +0 -0
  32. data/{lib/bubble-wrap → motion/core}/ui_control.rb +0 -0
  33. data/{lib/bubble-wrap → motion/core}/ui_view_controller.rb +0 -0
  34. data/motion/http.rb +249 -0
  35. data/spec/{app_spec.rb → core/app_spec.rb} +2 -2
  36. data/spec/{device → core/device}/screen_spec.rb +0 -0
  37. data/spec/{device_spec.rb → core/device_spec.rb} +0 -0
  38. data/spec/{gestures_spec.rb → core/gestures_spec.rb} +0 -0
  39. data/spec/{json_spec.rb → core/json_spec.rb} +0 -0
  40. data/spec/{ns_index_path_spec.rb → core/ns_index_path_spec.rb} +0 -0
  41. data/spec/{ns_notification_center_spec.rb → core/ns_notification_center_spec.rb} +0 -0
  42. data/spec/{persistence_spec.rb → core/persistence_spec.rb} +0 -0
  43. data/spec/core/string_spec.rb +69 -0
  44. data/spec/{time_spec.rb → core/time_spec.rb} +0 -0
  45. data/spec/{ui_control_spec.rb → core/ui_control_spec.rb} +0 -0
  46. data/spec/{module_spec.rb → core_spec.rb} +0 -0
  47. data/spec/http_spec.rb +300 -280
  48. metadata +115 -42
@@ -6,8 +6,8 @@ describe BubbleWrap::App do
6
6
  end
7
7
 
8
8
  describe '.resources_path' do
9
- it 'should end in "/MotionLibTestSuite.app"' do
10
- BW::App.resources_path[-19..-1].should == '/testSuite_spec.app'
9
+ it 'should end in "/testSuite.app"' do
10
+ BW::App.resources_path.should =~ /\/testSuite(_spec)?.app$/
11
11
  end
12
12
  end
13
13
 
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,69 @@
1
+ describe BubbleWrap::String do
2
+
3
+ describe ::String do
4
+ it 'should include BubbleWrap::String' do
5
+ ::String.ancestors.member?(BubbleWrap::String).should == true
6
+ end
7
+ end
8
+
9
+ describe 'CamelCase input' do
10
+ describe '.camelize(true)' do
11
+ it "doesn't change the value" do
12
+ 'CamelCase'.camelize(true).should == 'CamelCase'
13
+ end
14
+ end
15
+
16
+ describe '.camelize(false)' do
17
+ it 'lower cases the first character' do
18
+ 'CamelCase'.camelize(false).should == 'camelCase'
19
+ end
20
+ end
21
+
22
+ describe '.underscore' do
23
+ it 'converts it to underscores' do
24
+ 'CamelCase'.underscore.should == 'camel_case'
25
+ end
26
+ end
27
+ end
28
+
29
+ describe 'camelCase input' do
30
+ describe '.camelize(true)' do
31
+ it "upper cases the first character" do
32
+ 'camelCase'.camelize(true).should == 'CamelCase'
33
+ end
34
+ end
35
+
36
+ describe '.camelize(false)' do
37
+ it "doesn't change the value" do
38
+ 'camelCase'.camelize(false).should == 'camelCase'
39
+ end
40
+ end
41
+
42
+ describe '.underscore' do
43
+ it 'converts it to underscores' do
44
+ 'camelCase'.underscore.should == 'camel_case'
45
+ end
46
+ end
47
+ end
48
+
49
+ describe 'snake_case input' do
50
+ describe '.camelize(true)' do
51
+ it 'converts to CamelCase' do
52
+ 'snake_case'.camelize(true).should == 'SnakeCase'
53
+ end
54
+ end
55
+
56
+ describe '.camelize(false)' do
57
+ it 'converts to camelCase' do
58
+ 'snake_case'.camelize(false).should == 'snakeCase'
59
+ end
60
+ end
61
+
62
+ describe '.underscore' do
63
+ it "doesn't change the value" do
64
+ 'snake_case'.underscore.should == 'snake_case'
65
+ end
66
+ end
67
+ end
68
+
69
+ end
File without changes
File without changes
data/spec/http_spec.rb CHANGED
@@ -1,365 +1,385 @@
1
1
  describe "HTTP" do
2
2
 
3
- describe "HTTP::Response" do
4
- before do
5
- @response = BubbleWrap::HTTP::Response.new({ status_code: 200, url: 'http://localhost' })
6
- end
7
3
 
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
12
4
 
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
5
+ describe "HTTP::Response" do
6
+ before do
7
+ @response = BubbleWrap::HTTP::Response.new({ status_code: 200, url: 'http://localhost' })
8
+ end
9
+
10
+ it 'should turn the initialization Hash to instance variables' do
11
+ @response.instance_variable_get(:@status_code).should == 200
12
+ @response.instance_variable_get(:@url).should == 'http://localhost'
13
+ end
14
+
22
15
 
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=
16
+ it "says OK status code 20x" do
17
+ @response.ok?.should.equal true
18
+ (200..206).each do |code|
19
+ BubbleWrap::HTTP::Response.new({status_code: code}).ok?.should.be.true
29
20
  end
21
+ [100..101, 300..307, 400..417, 500..505].inject([]){|codes, rg| codes += rg.to_a}.each do |code|
22
+ BubbleWrap::HTTP::Response.new({status_code: code}).ok?.should.be.false
23
+ end
24
+ end
30
25
 
26
+
27
+ it "has appropriate attributes" do
28
+ @response.should.respond_to :body
29
+ @response.should.respond_to :headers
30
+ @response.should.respond_to :url
31
+ @response.should.respond_to :status_code=
32
+ @response.should.respond_to :error_message=
31
33
  end
32
34
 
33
- describe "HTTP::Query" do
35
+ end
34
36
 
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
37
+ describe "HTTP::Query" do
38
+
39
+ before do
40
+ @credentials = { credit_card: 23423948234 }
41
+ @payload = {
42
+ user: { name: 'marin', surname: 'usalj' },
43
+ twitter: '@mneorr',
44
+ website: 'mneorr.com',
45
+ values: [1, 2, 3],
46
+ credentials: @credentials
47
+ }
48
+ @action = lambda{|fa, ke|}
49
+ @cache_policy = 24234
50
+ @leftover_option = 'trololo'
51
+ @headers = { 'User-Agent' => "Mozilla/5.0 (X11; Linux x86_64; rv:12.0) \n Gecko/20100101 Firefox/12.0" }
52
+ @options = { action: @action,
53
+ payload: @payload,
54
+ credentials: @credentials,
55
+ headers: @headers,
56
+ cache_policy: @cache_policy,
57
+ leftover_option: @leftover_option
58
+ }
59
+ @query = BubbleWrap::HTTP::Query.new( 'http://localhost' , :get, @options )
60
+ end
61
+
62
+ it "has appropriate attributes" do
63
+ @query.should.respond_to :request=
64
+ @query.should.respond_to :connection=
65
+ @query.should.respond_to :credentials=
66
+ @query.should.respond_to :proxy_credential=
67
+ @query.should.respond_to :post_data=
68
+
69
+ @query.should.respond_to :method
70
+ @query.should.respond_to :response
71
+ @query.should.respond_to :status_code
72
+ @query.should.respond_to :response_headers
73
+ @query.should.respond_to :response_size
74
+ @query.should.respond_to :options
75
+ end
76
+
77
+ describe "When initialized" do
115
78
 
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
79
+ it "should upcase the HTTP method" do
80
+ @query.method.should.equal "GET"
81
+ end
82
+
83
+ it "should set the deleted delegator from options" do
84
+ @query.instance_variable_get(:@delegator).should.equal @action
85
+ @options.should.not.has_key? :action
86
+ end
121
87
 
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
88
+ it "should set self as the delegator if action not passed in" do
89
+ new_query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, {})
90
+ new_query.instance_variable_get(:@delegator).should.equal new_query
91
+ end
125
92
 
126
- new_query = BubbleWrap::HTTP::Query.new( 'http://fakehost.local/', :get, {})
127
- new_query.instance_variable_get(:@cachePolicy).should.equal NSURLRequestUseProtocolCachePolicy
128
- end
93
+ it "should merge :username and :password in loaded credentials" do
94
+ @query.credentials.should.equal @credentials.merge({:username => '', :password => ''})
129
95
 
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
96
+ new_credentials = {:username => 'user', :password => 'pass'}
97
+ options = { credentials: new_credentials }
98
+ new_query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, options)
99
+
100
+ new_query.credentials.should.equal new_credentials
101
+ options.should.be.empty
102
+ end
134
103
 
135
- it "should create a new response before instantiating a new request" do
136
- @query.response.should.not.equal nil
137
- end
104
+ it "should set payload from options{} to @payload" do
105
+ payload = "user[name]=marin&user[surname]=usalj&twitter=@mneorr&website=mneorr.com&values=[1, 2, 3]&credentials[credit_card]=23423948234"
106
+ @query.instance_variable_get(:@payload).should.equal payload
107
+ @options.should.not.has_key? :payload
108
+ end
138
109
 
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
110
+ it "should set default timeout to 30s or the one from hash" do
111
+ @query.instance_variable_get(:@timeout).should == 30
143
112
 
144
- it "should start the connection" do
145
- @query.connection.was_started.should.equal true
146
- end
113
+ options = {timeout: 10}
114
+ new_query = BubbleWrap::HTTP::Query.new( 'http://localhost/', :get, options)
115
+
116
+ new_query.instance_variable_get(:@timeout).should == 10
117
+ options.should.be.empty
118
+ end
147
119
 
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
120
+ it "should delete :headers from options and escape Line Feeds" do
121
+ gsubbed = @headers['User-Agent'].gsub("\n", '\\n')
122
+ @headers['User-Agent'] = gsubbed
123
+ @query.instance_variable_get(:@headers).should.equal @headers
124
+ end
153
125
 
154
- it "should turn on the network indicator" do
155
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should.equal true
156
- end
126
+ it "should delete :cache_policy or set NSURLRequestUseProtocolCachePolicy" do
127
+ @query.instance_variable_get(:@cachePolicy).should.equal @cache_policy
128
+ @options.should.not.has_key? :cache_policy
129
+
130
+ new_query = BubbleWrap::HTTP::Query.new( 'http://fakehost.local/', :get, {})
131
+ new_query.instance_variable_get(:@cachePolicy).should.equal NSURLRequestUseProtocolCachePolicy
132
+ end
157
133
 
134
+ it "should set the rest of options{} to ivar @options" do
135
+ @query.options.size.should.equal 1
136
+ @query.options.values[0].should.equal @leftover_option
158
137
  end
159
138
 
160
- describe "Generating GET params" do
139
+ it "should create a new response before instantiating a new request" do
140
+ @query.response.should.not.equal nil
141
+ end
161
142
 
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
143
+ it "should call initiate_request with the URL passed in" do
144
+ 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"
145
+ @query.instance_variable_get(:@url).description.should.equal processed_url
146
+ end
173
147
 
148
+ it "should start the connection" do
149
+ @query.connection.was_started.should.equal true
174
150
  end
175
151
 
176
- describe "when didReceiveResponse:" do
152
+ it "should turn on the network indicator" do
153
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should.equal true
154
+ end
155
+
156
+ end
157
+
158
+ describe "initiate request" do
159
+
160
+ before do
161
+ @url_string = 'http://initiated-request.dev'
162
+
163
+ @get_query = BubbleWrap::HTTP::Query.new( 'nil' , :get, { payload: {name: 'apple', model: 'macbook'} } )
164
+ @get_query.initiate_request @url_string
165
+
166
+ @post_query = BubbleWrap::HTTP::Query.new( 'nil' , :post, { payload: {name: 'apple', model: 'macbook'}} )
167
+ @post_query.initiate_request @url_string
168
+ end
177
169
 
178
- it "should assign status_code, headers and response_size" do
179
- headers = { foo: 'bar' }
180
- status_code = 234
181
- length = 123.53
170
+ it "should check if @payload is a hash before generating params" do
171
+ @get_query.instance_variable_get(:@payload).should.equal 'name=apple&model=macbook'
182
172
 
183
- response = FakeURLResponse.new(status_code, headers, length)
184
- @query.connection(nil, didReceiveResponse:response)
173
+ query_string_payload = BubbleWrap::HTTP::Query.new( 'nil' , :get, { payload: "name=apple&model=macbook"} )
174
+ query_string_payload.instance_variable_get(:@payload).should.equal 'name=apple&model=macbook'
175
+ end
185
176
 
186
- @query.status_code.should.equal status_code
187
- @query.response_headers.should.equal headers
188
- @query.response_size.should.equal length
189
- end
177
+ end
190
178
 
179
+ describe "Generating GET params" do
180
+
181
+ it "should create params with nested hashes with prefix[key]=value" do
182
+ expected_params = [
183
+ 'user[name]=marin',
184
+ 'user[surname]=usalj',
185
+ 'twitter=@mneorr',
186
+ 'website=mneorr.com',
187
+ 'values=[1, 2, 3]',
188
+ 'credentials[credit_card]=23423948234'
189
+ ]
190
+ @query.generate_get_params(@payload).should.equal expected_params
191
191
  end
192
192
 
193
- describe "when didRecieveData:" do
193
+ end
194
+
195
+ describe "when didReceiveResponse:" do
194
196
 
195
- def query_received_data
196
- @query.instance_variable_get(:@received_data)
197
- end
197
+ it "should assign status_code, headers and response_size" do
198
+ headers = { foo: 'bar' }
199
+ status_code = 234
200
+ length = 123.53
198
201
 
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)
202
+ response = FakeURLResponse.new(status_code, headers, length)
203
+ @query.connection(nil, didReceiveResponse:response)
202
204
 
203
- @query.connection(nil, didReceiveData:nil)
204
- query_received_data.should.not.equal nil
205
+ @query.status_code.should.equal status_code
206
+ @query.response_headers.should.equal headers
207
+ @query.response_size.should.equal length
208
+ end
205
209
 
206
- @query.connection(nil, didReceiveData:data)
207
- query_received_data.length.should.equal 24
210
+ end
208
211
 
209
- @query.connection(nil, didReceiveData:data)
210
- query_received_data.length.should.equal 48
211
- end
212
+ describe "when didRecieveData:" do
212
213
 
214
+ def query_received_data
215
+ @query.instance_variable_get(:@received_data)
213
216
  end
214
217
 
218
+ it "should initialize @received_data and append the received data" do
219
+ query_received_data.should.equal nil
220
+ data = NSData.dataWithBytesNoCopy(Pointer.new(:char, 'abc'), length:24)
221
+
222
+ @query.connection(nil, didReceiveData:nil)
223
+ query_received_data.should.not.equal nil
215
224
 
225
+ @query.connection(nil, didReceiveData:data)
226
+ query_received_data.length.should.equal 24
216
227
 
217
- describe "when requestDidFailWithError:" do
218
- before do
219
- @fake_error = NSError.errorWithDomain('testing', code:7768, userInfo:nil)
220
- end
228
+ @query.connection(nil, didReceiveData:data)
229
+ query_received_data.length.should.equal 48
230
+ end
221
231
 
222
- it "should turn off network indicator" do
223
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
232
+ end
224
233
 
225
- @query.connection(nil, didFailWithError:@fake_error)
226
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
227
- end
228
234
 
229
- it "should set request_done to true" do
230
- @query.request.done_loading.should == false
231
235
 
232
- @query.connection(nil, didFailWithError:@fake_error)
233
- @query.request.done_loading.should == true
234
- end
236
+ describe "when requestDidFailWithError:" do
237
+ before do
238
+ @fake_error = NSError.errorWithDomain('testing', code:7768, userInfo:nil)
239
+ end
235
240
 
236
- it "should set the error message to response object" do
237
- @query.response.error_message.should.equal nil
241
+ it "should turn off network indicator" do
242
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
238
243
 
239
- @query.connection(nil, didFailWithError:@fake_error)
240
- @query.response.error_message.should.equal @fake_error.localizedDescription
241
- end
244
+ @query.connection(nil, didFailWithError:@fake_error)
245
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
246
+ end
242
247
 
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 }
248
+ it "should set request_done to true" do
249
+ @query.request.done_loading.should == false
247
250
 
248
- query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
249
- query.instance_variable_set(:@response, expected_response)
251
+ @query.connection(nil, didFailWithError:@fake_error)
252
+ @query.request.done_loading.should == true
253
+ end
250
254
 
251
- query.connection(nil, didFailWithError:@fake_error)
252
- real_response.should.equal expected_response
253
- end
255
+ it "should set the error message to response object" do
256
+ @query.response.error_message.should.equal nil
254
257
 
258
+ @query.connection(nil, didFailWithError:@fake_error)
259
+ @query.response.error_message.should.equal @fake_error.localizedDescription
255
260
  end
256
261
 
257
- describe "when connectionDidFinishLoading:" do
262
+ it "should check if there's a callback block and pass the response in" do
263
+ expected_response = BubbleWrap::HTTP::Response.new
264
+ real_response = nil
265
+ block = lambda{ |response, query| real_response = response }
258
266
 
259
- it "should turn off the network indicator" do
260
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
267
+ query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
268
+ query.instance_variable_set(:@response, expected_response)
261
269
 
262
- @query.connectionDidFinishLoading(nil)
263
- UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
264
- end
270
+ query.connection(nil, didFailWithError:@fake_error)
271
+ real_response.should.equal expected_response
272
+ end
265
273
 
266
- it "should set request_done to true" do
267
- @query.request.done_loading.should == false
274
+ end
268
275
 
269
- @query.connectionDidFinishLoading(nil)
270
- @query.request.done_loading.should == true
271
- end
276
+ describe "when connectionDidFinishLoading:" do
272
277
 
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)
278
+ it "should turn off the network indicator" do
279
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
278
280
 
279
- @query.connection(nil, didReceiveResponse:response)
280
- @query.connection(nil, didReceiveData:data)
281
- @query.connectionDidFinishLoading(nil)
281
+ @query.connectionDidFinishLoading(nil)
282
+ UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
283
+ end
282
284
 
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
285
+ it "should set request_done to true" do
286
+ @query.request.done_loading.should == false
288
287
 
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 }
288
+ @query.connectionDidFinishLoading(nil)
289
+ @query.request.done_loading.should == true
290
+ end
293
291
 
294
- query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
295
- query.instance_variable_set(:@response, expected_response)
292
+ it "should set response_body to @received data if not nil" do
293
+ data = NSData.dataWithBytesNoCopy(Pointer.new(:char, 'abc'), length:24)
294
+ headers = { foo: 'bar' }
295
+ status_code = 234
296
+ response = FakeURLResponse.new(status_code, headers, 65456)
296
297
 
297
- query.connectionDidFinishLoading(nil)
298
- real_response.should.equal expected_response
299
- end
298
+ @query.connection(nil, didReceiveResponse:response)
299
+ @query.connection(nil, didReceiveData:data)
300
+ @query.connectionDidFinishLoading(nil)
300
301
 
302
+ @query.response.body.should.equal data
303
+ @query.response.status_code.should.equal status_code
304
+ @query.response.headers.should.equal headers
305
+ @query.response.url.should.equal @query.instance_variable_get(:@url)
301
306
  end
302
307
 
303
- describe "when connection:willSendRequest:redirectResponse:" do
304
- before do
305
- @request = NSURLRequest.requestWithURL NSURL.URLWithString('http://fakehost.local/')
306
- end
308
+ it "should check if there's a callback block and pass the response in" do
309
+ expected_response = BubbleWrap::HTTP::Response.new
310
+ real_response = nil
311
+ block = lambda{ |response, query| real_response = response }
312
+
313
+ query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
314
+ query.instance_variable_set(:@response, expected_response)
307
315
 
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)
316
+ query.connectionDidFinishLoading(nil)
317
+ real_response.should.equal expected_response
318
+ end
311
319
 
312
- new_request = @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
320
+ end
313
321
 
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
322
+ describe "when connection:willSendRequest:redirectResponse:" do
323
+ before do
324
+ @request = NSURLRequest.requestWithURL NSURL.URLWithString('http://fakehost.local/')
325
+ end
318
326
 
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)
327
+ it "should make a mutableCopy of passed in request and set headers from @headers" do
328
+ expected_headers = { new_header: 'should_be_here' }
329
+ @query.instance_variable_set(:@headers, expected_headers)
322
330
 
323
- old_connection.should.not.equal @query.connection
324
- end
331
+ new_request = @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
325
332
 
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
333
+ @query.request.should.not.be.equal @request
334
+ new_request.URL.description.should.equal @request.URL.description
335
+ new_request.allHTTPHeaderFields.should.equal expected_headers
336
+ end
330
337
 
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
338
+ it "should create a new Connection with the request passed in" do
339
+ old_connection = @query.connection
340
+ @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
335
341
 
342
+ old_connection.should.not.equal @query.connection
336
343
  end
337
344
 
338
- class BubbleWrap::HTTP::Query
339
- def create_connection(request, delegate); FakeURLConnection.new(request, delegate); end
345
+ it "should set itself as a delegate of new NSURLConnection" do
346
+ @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
347
+ @query.connection.delegate.should.equal @query
340
348
  end
341
349
 
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
350
+ it "should pass the new request in the new connection" do
351
+ @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
352
+ @query.connection.request.URL.description.should.equal @request.URL.description
353
353
  end
354
354
 
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
355
+ end
356
+
357
+ class BubbleWrap::HTTP::Query
358
+ def create_connection(request, delegate); FakeURLConnection.new(request, delegate); end
359
+ end
360
+
361
+ class FakeURLConnection < NSURLConnection
362
+ attr_reader :delegate, :request, :was_started
363
+ def initialize(request, delegate)
364
+ @request = request
365
+ @delegate = delegate
366
+ self.class.connectionWithRequest(request, delegate:delegate)
367
+ end
368
+ def start
369
+ @was_started = true
370
+ super
362
371
  end
372
+ end
363
373
 
374
+ class FakeURLResponse
375
+ attr_reader :statusCode, :allHeaderFields, :expectedContentLength
376
+ def initialize(status_code, headers, length)
377
+ @statusCode = status_code
378
+ @allHeaderFields = headers
379
+ @expectedContentLength = length
380
+ end
364
381
  end
382
+
365
383
  end
384
+
385
+ end