webstub 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/webstub/protocol.rb +25 -11
- data/lib/webstub/version.rb +1 -1
- metadata +2 -2
data/lib/webstub/protocol.rb
CHANGED
@@ -32,30 +32,44 @@ module WebStub
|
|
32
32
|
registry.reset
|
33
33
|
end
|
34
34
|
|
35
|
+
def initWithRequest(request, cachedResponse:response, client: client)
|
36
|
+
if super
|
37
|
+
@stub = nil
|
38
|
+
@timer = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def completeLoading
|
45
|
+
response = NSHTTPURLResponse.alloc.initWithURL(request.URL,
|
46
|
+
statusCode:@stub.response_status_code,
|
47
|
+
HTTPVersion:"HTTP/1.1",
|
48
|
+
headerFields:@stub.response_headers)
|
49
|
+
|
50
|
+
client.URLProtocol(self, didReceiveResponse:response, cacheStoragePolicy:NSURLCacheStorageNotAllowed)
|
51
|
+
client.URLProtocol(self, didLoadData:@stub.response_body.dataUsingEncoding(NSUTF8StringEncoding))
|
52
|
+
client.URLProtocolDidFinishLoading(self)
|
53
|
+
end
|
54
|
+
|
35
55
|
def startLoading
|
36
56
|
request = self.request
|
37
57
|
client = self.client
|
38
58
|
|
39
|
-
unless stub = self.class.stub_for(request)
|
59
|
+
unless @stub = self.class.stub_for(self.request)
|
40
60
|
error = NSError.errorWithDomain("WebStub", code:0, userInfo:{ NSLocalizedDescriptionKey: "network access is not permitted!"})
|
41
61
|
client.URLProtocol(self, didFailWithError:error)
|
42
62
|
|
43
63
|
return
|
44
64
|
end
|
45
65
|
|
46
|
-
|
47
|
-
statusCode:stub.response_status_code,
|
48
|
-
HTTPVersion:"HTTP/1.1",
|
49
|
-
headerFields:stub.response_headers)
|
50
|
-
|
51
|
-
Dispatch::Queue.concurrent("webstub.response").after(stub.response_delay) do
|
52
|
-
client.URLProtocol(self, didReceiveResponse:response, cacheStoragePolicy:NSURLCacheStorageNotAllowed)
|
53
|
-
client.URLProtocol(self, didLoadData:stub.response_body.dataUsingEncoding(NSUTF8StringEncoding))
|
54
|
-
client.URLProtocolDidFinishLoading(self)
|
55
|
-
end
|
66
|
+
@timer = NSTimer.scheduledTimerWithTimeInterval(@stub.response_delay, target:self, selector: :completeLoading, userInfo:nil, repeats:false)
|
56
67
|
end
|
57
68
|
|
58
69
|
def stopLoading
|
70
|
+
if @timer
|
71
|
+
@timer.invalidate
|
72
|
+
end
|
59
73
|
end
|
60
74
|
|
61
75
|
private
|
data/lib/webstub/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webstub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Easily stub out HTTP responses in RubyMotion specs
|
15
15
|
email:
|