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.
- data/CHANGELOG.md +5 -0
- data/README.md +183 -66
- data/Rakefile +6 -6
- data/bubble-wrap.gemspec +10 -5
- data/lib/bubble-wrap.rb +4 -39
- data/lib/bubble-wrap/core.rb +7 -0
- data/lib/bubble-wrap/ext.rb +2 -0
- data/lib/bubble-wrap/ext/motion_project_app.rb +26 -0
- data/lib/bubble-wrap/ext/motion_project_config.rb +21 -0
- data/lib/bubble-wrap/http.rb +2 -249
- data/lib/bubble-wrap/loader.rb +23 -0
- data/lib/bubble-wrap/requirement.rb +88 -0
- data/lib/bubble-wrap/requirement/path_manipulation.rb +40 -0
- data/lib/bubble-wrap/version.rb +1 -1
- data/lib_spec/bubble-wrap/requirement/path_manipulation_spec.rb +51 -0
- data/lib_spec/bubble-wrap/requirement_spec.rb +72 -0
- data/lib_spec/bubble-wrap_spec.rb +17 -0
- data/lib_spec/motion_stub.rb +12 -0
- data/{lib/bubble-wrap/module.rb → motion/core.rb} +0 -0
- data/{lib/bubble-wrap → motion/core}/app.rb +0 -0
- data/{lib/bubble-wrap → motion/core}/device.rb +0 -16
- data/{lib/bubble-wrap → motion/core}/device/screen.rb +0 -0
- data/{lib/bubble-wrap → motion/core}/gestures.rb +0 -0
- data/{lib/bubble-wrap → motion/core}/json.rb +0 -0
- data/{lib/bubble-wrap → motion/core}/ns_index_path.rb +0 -0
- data/{lib/bubble-wrap → motion/core}/ns_notification_center.rb +0 -0
- data/{lib/bubble-wrap → motion/core}/ns_user_defaults.rb +0 -0
- data/{lib/bubble-wrap → motion/core}/persistence.rb +0 -0
- data/{lib → motion/core}/pollute.rb +1 -1
- data/motion/core/string.rb +38 -0
- data/{lib/bubble-wrap → motion/core}/time.rb +0 -0
- data/{lib/bubble-wrap → motion/core}/ui_control.rb +0 -0
- data/{lib/bubble-wrap → motion/core}/ui_view_controller.rb +0 -0
- data/motion/http.rb +249 -0
- data/spec/{app_spec.rb → core/app_spec.rb} +2 -2
- data/spec/{device → core/device}/screen_spec.rb +0 -0
- data/spec/{device_spec.rb → core/device_spec.rb} +0 -0
- data/spec/{gestures_spec.rb → core/gestures_spec.rb} +0 -0
- data/spec/{json_spec.rb → core/json_spec.rb} +0 -0
- data/spec/{ns_index_path_spec.rb → core/ns_index_path_spec.rb} +0 -0
- data/spec/{ns_notification_center_spec.rb → core/ns_notification_center_spec.rb} +0 -0
- data/spec/{persistence_spec.rb → core/persistence_spec.rb} +0 -0
- data/spec/core/string_spec.rb +69 -0
- data/spec/{time_spec.rb → core/time_spec.rb} +0 -0
- data/spec/{ui_control_spec.rb → core/ui_control_spec.rb} +0 -0
- data/spec/{module_spec.rb → core_spec.rb} +0 -0
- data/spec/http_spec.rb +300 -280
- 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 "/
|
10
|
-
BW::App.resources_path
|
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
|
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
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
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
|
-
|
127
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
136
|
-
|
137
|
-
|
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
|
-
|
140
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
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
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
-
|
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
|
-
|
179
|
-
|
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
|
-
|
184
|
-
|
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
|
-
|
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
|
-
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "when didReceiveResponse:" do
|
194
196
|
|
195
|
-
|
196
|
-
|
197
|
-
|
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
|
-
|
200
|
-
|
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
|
-
|
204
|
-
|
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
|
-
|
207
|
-
query_received_data.length.should.equal 24
|
210
|
+
end
|
208
211
|
|
209
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
end
|
228
|
+
@query.connection(nil, didReceiveData:data)
|
229
|
+
query_received_data.length.should.equal 48
|
230
|
+
end
|
221
231
|
|
222
|
-
|
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
|
-
|
233
|
-
|
234
|
-
|
236
|
+
describe "when requestDidFailWithError:" do
|
237
|
+
before do
|
238
|
+
@fake_error = NSError.errorWithDomain('testing', code:7768, userInfo:nil)
|
239
|
+
end
|
235
240
|
|
236
|
-
|
237
|
-
|
241
|
+
it "should turn off network indicator" do
|
242
|
+
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
|
238
243
|
|
239
|
-
|
240
|
-
|
241
|
-
|
244
|
+
@query.connection(nil, didFailWithError:@fake_error)
|
245
|
+
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
|
246
|
+
end
|
242
247
|
|
243
|
-
|
244
|
-
|
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
|
-
|
249
|
-
|
251
|
+
@query.connection(nil, didFailWithError:@fake_error)
|
252
|
+
@query.request.done_loading.should == true
|
253
|
+
end
|
250
254
|
|
251
|
-
|
252
|
-
|
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
|
-
|
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
|
-
|
260
|
-
|
267
|
+
query = BubbleWrap::HTTP::Query.new( 'http://localhost', :get, { :action => block })
|
268
|
+
query.instance_variable_set(:@response, expected_response)
|
261
269
|
|
262
|
-
|
263
|
-
|
264
|
-
|
270
|
+
query.connection(nil, didFailWithError:@fake_error)
|
271
|
+
real_response.should.equal expected_response
|
272
|
+
end
|
265
273
|
|
266
|
-
|
267
|
-
@query.request.done_loading.should == false
|
274
|
+
end
|
268
275
|
|
269
|
-
|
270
|
-
@query.request.done_loading.should == true
|
271
|
-
end
|
276
|
+
describe "when connectionDidFinishLoading:" do
|
272
277
|
|
273
|
-
|
274
|
-
|
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
|
-
|
280
|
-
|
281
|
-
|
281
|
+
@query.connectionDidFinishLoading(nil)
|
282
|
+
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
|
283
|
+
end
|
282
284
|
|
283
|
-
|
284
|
-
|
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
|
-
|
290
|
-
|
291
|
-
|
292
|
-
block = lambda{ |response, query| real_response = response }
|
288
|
+
@query.connectionDidFinishLoading(nil)
|
289
|
+
@query.request.done_loading.should == true
|
290
|
+
end
|
293
291
|
|
294
|
-
|
295
|
-
|
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
|
-
|
298
|
-
|
299
|
-
|
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
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
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
|
-
|
309
|
-
|
310
|
-
|
316
|
+
query.connectionDidFinishLoading(nil)
|
317
|
+
real_response.should.equal expected_response
|
318
|
+
end
|
311
319
|
|
312
|
-
|
320
|
+
end
|
313
321
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
322
|
+
describe "when connection:willSendRequest:redirectResponse:" do
|
323
|
+
before do
|
324
|
+
@request = NSURLRequest.requestWithURL NSURL.URLWithString('http://fakehost.local/')
|
325
|
+
end
|
318
326
|
|
319
|
-
|
320
|
-
|
321
|
-
|
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
|
-
|
324
|
-
end
|
331
|
+
new_request = @query.connection(nil, willSendRequest:@request, redirectResponse:nil)
|
325
332
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
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
|
-
|
332
|
-
|
333
|
-
|
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
|
-
|
339
|
-
|
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
|
-
|
343
|
-
|
344
|
-
|
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
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
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
|