webstub 0.3.8 → 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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +22 -8
- data/Rakefile +3 -1
- data/lib/webstub/api.rb +12 -4
- data/lib/webstub/protocol.rb +2 -2
- data/lib/webstub/stub.rb +8 -0
- data/lib/webstub/version.rb +1 -1
- data/spec/api_spec.rb +5 -1
- data/spec/stub_spec.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b1fadc30394c28a2c70f47cdf1b3bb00fd53b25
|
4
|
+
data.tar.gz: 7a378b835765d1bc94256aac54c28ddb83692d9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c6e61d19d442611bf3ba6d94c20eff7aa50264073e6d5b4ca95f2f655b9e920dc87ddacdaea6f1a3f039c11a753dfd9f7cf8f1a3114028568c766d20ae282f5
|
7
|
+
data.tar.gz: 4b15563577dff7e90410f4709a30c098825425bbf21fe39bf2618cf8d6819d87bbcd228d76c1a61e9bbb417eb911ed99a4e12c596c03bc1a3f2628a0de888cf0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
WebStub [](https://codeclimate.com/github/mattgreen/webstub) [](https://travis-ci.org/mattgreen/webstub)
|
1
|
+
WebStub [](https://codeclimate.com/github/mattgreen/webstub) [](https://travis-ci.org/mattgreen/webstub) [](http://badge.fury.io/rb/webstub)
|
2
2
|
======
|
3
3
|
|
4
4
|
What if [WebMock](https://github.com/bblimke/webmock) and [NSURLProtocol](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLProtocol_Class/Reference/Reference.html) had a baby?
|
@@ -13,15 +13,9 @@ Features
|
|
13
13
|
|
14
14
|
Installation
|
15
15
|
------------
|
16
|
-
Please ensure you have the latest version of RubyMotion: (**WebStub requres version 1.24 or higher**)
|
17
|
-
|
18
|
-
$ sudo motion update
|
19
|
-
|
20
|
-
Also, if you haven't done so already, please [configure](http://thunderboltlabs.com/posts/using-bundler-with-rubymotion) your project to use Bundler.
|
21
|
-
|
22
16
|
Update your Gemfile:
|
23
17
|
|
24
|
-
gem "webstub", "~> 0.
|
18
|
+
gem "webstub", "~> 0.4.0"
|
25
19
|
|
26
20
|
Bundle:
|
27
21
|
|
@@ -112,6 +106,26 @@ Conventions
|
|
112
106
|
- `content_type`: sets the Content-Type when using the `body` parameter
|
113
107
|
- `status_code`: sets the integer Status Code of the response. Defaults to `200`.
|
114
108
|
|
109
|
+
Expectations
|
110
|
+
-----------------
|
111
|
+
Sometimes, you may just want to check that the request has been made to a given URL. In this case, you can use the `requested?` method of the stub returned by `stub_request`:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
describe Elevate::HTTP do
|
115
|
+
extend WebStub::SpecHelpers
|
116
|
+
|
117
|
+
describe ".get" do
|
118
|
+
it "synchronously issues a HTTP GET request" do
|
119
|
+
stub = stub_request(:get, "http://www.example.com/")
|
120
|
+
|
121
|
+
Elevate::HTTP.get("http://www.example.com/")
|
122
|
+
|
123
|
+
stub.should.be.requested
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
```
|
128
|
+
|
115
129
|
TODO
|
116
130
|
---------
|
117
131
|
* Handle query params similarly to form data
|
data/Rakefile
CHANGED
@@ -12,11 +12,13 @@ rescue LoadError
|
|
12
12
|
end
|
13
13
|
|
14
14
|
require 'bundler/setup'
|
15
|
-
require 'bundler/gem_tasks'
|
16
15
|
|
17
16
|
Bundler.setup
|
18
17
|
Bundler.require
|
19
18
|
|
19
|
+
require 'rubygems/tasks'
|
20
|
+
Gem::Tasks.new
|
21
|
+
|
20
22
|
Motion::Project::App.setup do |app|
|
21
23
|
gemspec = Dir.glob(File.join(File.dirname(__FILE__), "*.gemspec")).first
|
22
24
|
gem_name = File.basename(gemspec).gsub("\.gemspec", "")
|
data/lib/webstub/api.rb
CHANGED
@@ -3,19 +3,27 @@ module WebStub
|
|
3
3
|
extend self
|
4
4
|
|
5
5
|
def disable_network_access!
|
6
|
-
|
6
|
+
protocol.disable_network_access!
|
7
7
|
end
|
8
8
|
|
9
9
|
def enable_network_access!
|
10
|
-
|
10
|
+
protocol.enable_network_access!
|
11
11
|
end
|
12
12
|
|
13
13
|
def stub_request(method, path)
|
14
|
-
|
14
|
+
protocol.add_stub(method, path)
|
15
15
|
end
|
16
16
|
|
17
17
|
def reset_stubs
|
18
|
-
|
18
|
+
protocol.reset_stubs
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def protocol
|
24
|
+
Dispatch.once { NSURLProtocol.registerClass(WebStub::Protocol) }
|
25
|
+
|
26
|
+
Protocol
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
data/lib/webstub/protocol.rb
CHANGED
@@ -66,6 +66,8 @@ module WebStub
|
|
66
66
|
return
|
67
67
|
end
|
68
68
|
|
69
|
+
@stub.requests += 1
|
70
|
+
|
69
71
|
@timer = NSTimer.scheduledTimerWithTimeInterval(@stub.response_delay, target:self, selector: :completeLoading, userInfo:nil, repeats:false)
|
70
72
|
end
|
71
73
|
|
@@ -125,5 +127,3 @@ module WebStub
|
|
125
127
|
end
|
126
128
|
end
|
127
129
|
end
|
128
|
-
|
129
|
-
NSURLProtocol.registerClass(WebStub::Protocol)
|
data/lib/webstub/stub.rb
CHANGED
@@ -5,6 +5,8 @@ module WebStub
|
|
5
5
|
def initialize(method, url)
|
6
6
|
@request_method = canonicalize_method(method)
|
7
7
|
raise ArgumentError, "invalid method name" unless METHODS.include? @request_method
|
8
|
+
|
9
|
+
@requests = 0
|
8
10
|
|
9
11
|
@request_url = canonicalize_url(url)
|
10
12
|
@request_headers = nil
|
@@ -44,6 +46,12 @@ module WebStub
|
|
44
46
|
true
|
45
47
|
end
|
46
48
|
|
49
|
+
attr_accessor :requests
|
50
|
+
|
51
|
+
def requested?
|
52
|
+
@requests > 0
|
53
|
+
end
|
54
|
+
|
47
55
|
attr_reader :response_body
|
48
56
|
attr_reader :response_delay
|
49
57
|
attr_reader :response_headers
|
data/lib/webstub/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -59,7 +59,7 @@ describe WebStub::API do
|
|
59
59
|
describe "when a request matches a stub" do
|
60
60
|
describe "and the request does include a body" do
|
61
61
|
before do
|
62
|
-
WebStub::API.stub_request(:get, @url).to_return(body:"hello", headers: {"Content-Type" => "text/plain"})
|
62
|
+
@stub = WebStub::API.stub_request(:get, @url).to_return(body:"hello", headers: {"Content-Type" => "text/plain"})
|
63
63
|
|
64
64
|
@response = get @url
|
65
65
|
end
|
@@ -79,6 +79,10 @@ describe WebStub::API do
|
|
79
79
|
it "returns a 200 status code" do
|
80
80
|
@response.status_code.should.be == 200
|
81
81
|
end
|
82
|
+
|
83
|
+
it "marks the stub as requested" do
|
84
|
+
@stub.should.be.requested
|
85
|
+
end
|
82
86
|
end
|
83
87
|
|
84
88
|
describe "and the request includes a body" do
|
data/spec/stub_spec.rb
CHANGED
@@ -84,6 +84,24 @@ describe WebStub::Stub do
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
describe "#requested?" do
|
88
|
+
describe "by default" do
|
89
|
+
it "returns false" do
|
90
|
+
@stub.should.not.be.requested
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "after incrementing the request count" do
|
95
|
+
before do
|
96
|
+
@stub.requests += 1
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns true" do
|
100
|
+
@stub.should.be.requested
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
87
105
|
describe "#response_body" do
|
88
106
|
it "returns the response body" do
|
89
107
|
@stub.response_body.should == ""
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webstub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Green
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Easily stub out HTTP responses in RubyMotion specs
|
14
14
|
email:
|