webstub 0.3.4 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ build
4
4
  resources/*.nib
5
5
  resources/*.momd
6
6
  resources/*.storyboardc
7
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ language: objective-c
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rake'
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- WebStub [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/mattgreen/webstub)
1
+ WebStub [![Code Climate](https://codeclimate.com/github/mattgreen/webstub.png)](https://codeclimate.com/github/mattgreen/webstub) [![Travis](https://api.travis-ci.org/mattgreen/webstub.png)](https://travis-ci.org/mattgreen/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?
@@ -5,6 +5,9 @@ module WebStub
5
5
  end
6
6
 
7
7
  def self.canInitWithRequest(request)
8
+ return false unless spec_mode?
9
+ return false unless supported?(request)
10
+
8
11
  if stub_for(request)
9
12
  return true
10
13
  end
@@ -106,6 +109,17 @@ module WebStub
106
109
  body
107
110
  end
108
111
  end
112
+
113
+ def self.spec_mode?
114
+ RUBYMOTION_ENV == 'test'
115
+ end
116
+
117
+ def self.supported?(request)
118
+ return false unless request.URL
119
+ return false unless request.URL.scheme.start_with?("http")
120
+
121
+ true
122
+ end
109
123
  end
110
124
  end
111
125
 
data/lib/webstub/stub.rb CHANGED
@@ -24,6 +24,16 @@ module WebStub
24
24
  return false
25
25
  end
26
26
 
27
+ if @request_headers
28
+ headers = options[:headers] || {}
29
+
30
+ @request_headers.each do |key, value|
31
+ if headers[key] != value
32
+ return false
33
+ end
34
+ end
35
+ end
36
+
27
37
  if @request_body
28
38
  if @request_body != options[:body]
29
39
  return false
@@ -73,6 +83,10 @@ module WebStub
73
83
  end
74
84
  end
75
85
 
86
+ if headers = options[:headers]
87
+ @request_headers = headers
88
+ end
89
+
76
90
  self
77
91
  end
78
92
 
@@ -1,3 +1,3 @@
1
1
  module WebStub
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.7"
3
3
  end
data/spec/stub_spec.rb CHANGED
@@ -65,6 +65,23 @@ describe WebStub::Stub do
65
65
  end
66
66
  end
67
67
  end
68
+
69
+ describe "headers" do
70
+ before do
71
+ @stub = WebStub::Stub.new(:get, "http://www.yahoo.com/search").
72
+ with(headers: { "Authorization" => "secret" })
73
+ end
74
+
75
+ it "returns true when the headers are included" do
76
+ @stub.matches?(:get, "http://www.yahoo.com/search",
77
+ headers: { "X-Extra" => "42", "Authorization" => "secret" }).should.be.true
78
+ end
79
+
80
+ it "returns false when any of the headers are absent" do
81
+ @stub.matches?(:get, "http://www.yahoo.com/search",
82
+ headers: { "X-Extra" => "42" }).should.be.false
83
+ end
84
+ end
68
85
  end
69
86
 
70
87
  describe "#response_body" do
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
4
+ version: 0.3.7
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-05 00:00:00.000000000 Z
12
+ date: 2013-04-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Easily stub out HTTP responses in RubyMotion specs
15
15
  email:
@@ -19,8 +19,8 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
+ - .travis.yml
22
23
  - Gemfile
23
- - Gemfile.lock
24
24
  - Guardfile
25
25
  - LICENSE
26
26
  - README.md
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 1.8.24
67
+ rubygems_version: 1.8.23
68
68
  signing_key:
69
69
  specification_version: 3
70
70
  summary: Easily stub out HTTP responses in RubyMotion specs
@@ -77,4 +77,3 @@ test_files:
77
77
  - spec/spec_helpers_spec.rb
78
78
  - spec/stub_spec.rb
79
79
  - spec/uri_spec.rb
80
- has_rdoc:
data/Gemfile.lock DELETED
@@ -1,37 +0,0 @@
1
- GIT
2
- remote: git://github.com/guard/guard.git
3
- revision: 863fa1247e07a0659edebfede61cf16096496c36
4
- specs:
5
- guard (1.3.2)
6
- listen (>= 0.4.2)
7
- thor (>= 0.14.6)
8
-
9
- GIT
10
- remote: git://github.com/guard/listen.git
11
- revision: edff3eb1dfca5e7864460ece2322e85097fb0209
12
- specs:
13
- listen (0.5.0)
14
-
15
- GEM
16
- remote: http://rubygems.org/
17
- specs:
18
- coolline (0.3.0)
19
- guard-motion (0.1.0)
20
- guard (>= 1.1.0)
21
- rake (>= 0.9)
22
- rake (0.9.2.2)
23
- rb-fsevent (0.9.1)
24
- terminal-notifier-guard (1.5.3)
25
- thor (0.16.0)
26
-
27
- PLATFORMS
28
- ruby
29
-
30
- DEPENDENCIES
31
- coolline
32
- guard!
33
- guard-motion
34
- listen!
35
- rake
36
- rb-fsevent (~> 0.9.1)
37
- terminal-notifier-guard