webstub 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +14 -2
- data/lib/webstub/protocol.rb +6 -3
- data/lib/webstub/stub.rb +4 -1
- data/lib/webstub/version.rb +1 -1
- data/spec/api_spec.rb +27 -0
- data/spec/helpers/request_helper.rb +7 -2
- metadata +7 -9
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a8c0c009af8edd522251e559b40ae11e0e6fb9a3
|
4
|
+
data.tar.gz: 2ac7163346730732434b3ccc5db48b1e07d5dd11
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 112358da3a63a4c8ad11637db9b92d0d3167d0a8982fc09fe49afb47db5085423071441321fe50b401eec3f2bdd5ef537ca9a4975eb7bdedf964f0092f813369
|
7
|
+
data.tar.gz: 9fd9484b655dad804d5ba59eb4815372989c7d1e3070820954a29bc0adf9e8c751b92fe7f31fb48096dee1af6c74943def9869085b939c3cd460c70ce7f9ab5d
|
data/Rakefile
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
$:.unshift("/Library/RubyMotion/lib")
|
2
|
-
require 'motion/project'
|
3
2
|
|
4
|
-
|
3
|
+
begin
|
4
|
+
if ENV['osx']
|
5
|
+
require 'motion/project/template/osx'
|
6
|
+
else
|
7
|
+
require 'motion/project/template/ios'
|
8
|
+
end
|
9
|
+
|
10
|
+
rescue LoadError
|
11
|
+
require 'motion/project'
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'bundler/setup'
|
15
|
+
require 'bundler/gem_tasks'
|
16
|
+
|
5
17
|
Bundler.setup
|
6
18
|
Bundler.require
|
7
19
|
|
data/lib/webstub/protocol.rb
CHANGED
@@ -82,15 +82,17 @@ module WebStub
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def self.stub_for(request)
|
85
|
-
options = {}
|
86
|
-
if request
|
87
|
-
options[:body] =
|
85
|
+
options = { headers: request.allHTTPHeaderFields }
|
86
|
+
if body = parse_body(request)
|
87
|
+
options[:body] = body
|
88
88
|
end
|
89
89
|
|
90
90
|
registry.stub_matching(request.HTTPMethod, request.URL.absoluteString, options)
|
91
91
|
end
|
92
92
|
|
93
93
|
def self.parse_body(request)
|
94
|
+
return nil unless request.HTTPBody
|
95
|
+
|
94
96
|
content_type = nil
|
95
97
|
|
96
98
|
request.allHTTPHeaderFields.each do |key, value|
|
@@ -101,6 +103,7 @@ module WebStub
|
|
101
103
|
end
|
102
104
|
|
103
105
|
body = NSString.alloc.initWithData(request.HTTPBody, encoding:NSUTF8StringEncoding)
|
106
|
+
return nil unless body
|
104
107
|
|
105
108
|
case content_type
|
106
109
|
when /application\/x-www-form-urlencoded/
|
data/lib/webstub/stub.rb
CHANGED
@@ -13,6 +13,7 @@ module WebStub
|
|
13
13
|
@response_body = ""
|
14
14
|
@response_delay = 0.0
|
15
15
|
@response_headers = {}
|
16
|
+
@response_status_code = 200
|
16
17
|
end
|
17
18
|
|
18
19
|
def matches?(method, url, options={})
|
@@ -49,7 +50,9 @@ module WebStub
|
|
49
50
|
attr_reader :response_status_code
|
50
51
|
|
51
52
|
def to_return(options)
|
52
|
-
|
53
|
+
if status_code = options[:status_code]
|
54
|
+
@response_status_code = status_code
|
55
|
+
end
|
53
56
|
|
54
57
|
if json = options[:json]
|
55
58
|
@response_body = json
|
data/lib/webstub/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -41,6 +41,19 @@ describe WebStub::API do
|
|
41
41
|
@response.body.should.be.nil
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
describe "when a header is set" do
|
46
|
+
before do
|
47
|
+
WebStub::API.stub_request(:get, @url).
|
48
|
+
with(headers: { "Header" => "Value" })
|
49
|
+
|
50
|
+
@response = get(@url)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "requires the header to be present" do
|
54
|
+
@response.error.should.not.be.nil
|
55
|
+
end
|
56
|
+
end
|
44
57
|
end
|
45
58
|
|
46
59
|
describe "when a request matches a stub" do
|
@@ -126,6 +139,20 @@ describe WebStub::API do
|
|
126
139
|
(finish - start).should.be >= 1.0
|
127
140
|
end
|
128
141
|
end
|
142
|
+
|
143
|
+
describe "when a stub requires a header" do
|
144
|
+
before do
|
145
|
+
WebStub::API.stub_request(:get, @url).
|
146
|
+
with(headers: { "My-Header" => "123" }).
|
147
|
+
to_return(json: {})
|
148
|
+
end
|
149
|
+
|
150
|
+
it "returns the correct body" do
|
151
|
+
response = get(@url, { "My-Header" => "123" })
|
152
|
+
|
153
|
+
response.body.should == '{}'
|
154
|
+
end
|
155
|
+
end
|
129
156
|
end
|
130
157
|
|
131
158
|
describe ".reset_stubs" do
|
@@ -12,8 +12,13 @@ class Response
|
|
12
12
|
attr_reader :status_code
|
13
13
|
end
|
14
14
|
|
15
|
-
def get(url)
|
16
|
-
request =
|
15
|
+
def get(url, headers={})
|
16
|
+
request = NSMutableURLRequest.alloc.init
|
17
|
+
request.URL = NSURL.URLWithString(url)
|
18
|
+
|
19
|
+
headers.each do |key, value|
|
20
|
+
request.setValue(value, forHTTPHeaderField: key.to_s)
|
21
|
+
end
|
17
22
|
|
18
23
|
response = Pointer.new(:object)
|
19
24
|
error = Pointer.new(:object)
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webstub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.8
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matt Green
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-11 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Easily stub out HTTP responses in RubyMotion specs
|
15
14
|
email:
|
@@ -46,27 +45,26 @@ files:
|
|
46
45
|
- webstub.gemspec
|
47
46
|
homepage: https://github.com/mattgreen/webstub
|
48
47
|
licenses: []
|
48
|
+
metadata: {}
|
49
49
|
post_install_message:
|
50
50
|
rdoc_options: []
|
51
51
|
require_paths:
|
52
52
|
- lib
|
53
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
54
|
requirements:
|
56
|
-
- -
|
55
|
+
- - '>='
|
57
56
|
- !ruby/object:Gem::Version
|
58
57
|
version: '0'
|
59
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
59
|
requirements:
|
62
|
-
- -
|
60
|
+
- - '>='
|
63
61
|
- !ruby/object:Gem::Version
|
64
62
|
version: '0'
|
65
63
|
requirements: []
|
66
64
|
rubyforge_project:
|
67
|
-
rubygems_version:
|
65
|
+
rubygems_version: 2.0.2
|
68
66
|
signing_key:
|
69
|
-
specification_version:
|
67
|
+
specification_version: 4
|
70
68
|
summary: Easily stub out HTTP responses in RubyMotion specs
|
71
69
|
test_files:
|
72
70
|
- spec/api_spec.rb
|