webstub 0.3.2 → 0.3.3

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/README.md CHANGED
@@ -46,10 +46,10 @@ Example Spec
46
46
  describe "Example" do
47
47
  extend WebStub::SpecHelpers
48
48
 
49
- describe "Stubbing a GET request to return a simple response" do
49
+ describe "Stubbing a GET request to return a simple response after a delay" do
50
50
  it "retrieves the front page" do
51
51
  stub_request(:get, "http://example.com/").
52
- to_return(body: "Hello!", content_type: "text/plain")
52
+ to_return(body: "Hello!", content_type: "text/plain", delay: 0.3)
53
53
 
54
54
  @body = nil
55
55
  @api.get_index do |body, error|
@@ -48,9 +48,11 @@ module WebStub
48
48
  HTTPVersion:"HTTP/1.1",
49
49
  headerFields:stub.response_headers)
50
50
 
51
- client.URLProtocol(self, didReceiveResponse:response, cacheStoragePolicy:NSURLCacheStorageNotAllowed)
52
- client.URLProtocol(self, didLoadData:stub.response_body.dataUsingEncoding(NSUTF8StringEncoding))
53
- client.URLProtocolDidFinishLoading(self)
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
54
56
  end
55
57
 
56
58
  def stopLoading
data/lib/webstub/stub.rb CHANGED
@@ -11,6 +11,7 @@ module WebStub
11
11
  @request_body = nil
12
12
 
13
13
  @response_body = ""
14
+ @response_delay = 0.0
14
15
  @response_headers = {}
15
16
  end
16
17
 
@@ -33,6 +34,7 @@ module WebStub
33
34
  end
34
35
 
35
36
  attr_reader :response_body
37
+ attr_reader :response_delay
36
38
  attr_reader :response_headers
37
39
  attr_reader :response_status_code
38
40
 
@@ -55,6 +57,10 @@ module WebStub
55
57
  end
56
58
  end
57
59
 
60
+ if delay = options[:delay]
61
+ @response_delay = delay
62
+ end
63
+
58
64
  self
59
65
  end
60
66
 
@@ -1,3 +1,3 @@
1
1
  module WebStub
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
data/spec/api_spec.rb CHANGED
@@ -98,18 +98,33 @@ describe WebStub::API do
98
98
  end
99
99
  end
100
100
  end
101
- end
102
101
 
103
- describe "when a stub sets a specified status code" do
104
- before do
105
- WebStub::API.stub_request(:get, @url).
106
- to_return(json: {error: "Not Found"}, status_code: 400)
107
-
108
- @response = get @url
102
+ describe "when a stub sets a specified status code" do
103
+ before do
104
+ WebStub::API.stub_request(:get, @url).
105
+ to_return(json: {error: "Not Found"}, status_code: 400)
106
+
107
+ @response = get @url
108
+ end
109
+
110
+ it "the status code of the response should match" do
111
+ @response.status_code.should.be == 400
112
+ end
109
113
  end
110
114
 
111
- it "the status code of the response should match" do
112
- @response.status_code.should.be == 400
115
+ describe "when a stub sets a delay" do
116
+ before do
117
+ WebStub::API.stub_request(:get, @url).
118
+ to_return(json: {}, delay: 1.0)
119
+ end
120
+
121
+ it "returns a response after the specified amount of time" do
122
+ start = Time.now
123
+ get @url
124
+ finish = Time.now
125
+
126
+ (finish - start).should.be >= 1.0
127
+ end
113
128
  end
114
129
  end
115
130
 
data/spec/stub_spec.rb CHANGED
@@ -97,6 +97,11 @@ describe WebStub::Stub do
97
97
  @stub.response_body.should == '[{"value":42}]'
98
98
  end
99
99
 
100
+ it "sets a delay time" do
101
+ @stub.to_return(body: "{}", delay: 0.5)
102
+ @stub.response_delay.should == 0.5
103
+ end
104
+
100
105
  it "sets response headers" do
101
106
  @stub.to_return(body: "{}", headers: { "Content-Type" => "application/json" })
102
107
  @stub.response_headers.should.be == { "Content-Type" => "application/json" }
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.2
4
+ version: 0.3.3
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-03 00:00:00.000000000 Z
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Easily stub out HTTP responses in RubyMotion specs
15
15
  email: