webmock-rspec-helper 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/webmock-rspec-helper.rb +11 -6
- data/lib/webmock-rspec-helper/version.rb +2 -2
- data/spec/webmock-rspec-helper_spec.rb +10 -2
- data/webmock-rspec-helper.gemspec +2 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjM4MjI5YzY3ODZiYzBkZmZmMGUxYjZmOTcxOGMwZDA5ZWUyZWRiMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGVhYjU2M2Q1MWZiZDliYjc5MTZhNjU4NzQ4ZDc4YjFmMTEzNjJiYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmNlOThlZmM1NmM0YmZiYTYzZTMyMzhhNzFhMzI1ODI3MWYyODljOGZjYjE4
|
10
|
+
MmYxYzhmNmRjMDVjNjQ0YTFjNzkwZjQ2ODhmNGE3ZDRjMDEyNWM0MDM2NWJi
|
11
|
+
YTg2MGI3MmJiN2MwNGQ2ZWI1YTMwYTFkZDA5ODkzYjlhNDk0ZWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjUzMDc1ZWYzYWQzYzVhODg4NmM1NWFhZWVhMTkyYzQ3YTNmOGQ2MGFkOTdj
|
14
|
+
YTc2NjdhY2JkOWY3NTJhOWNkYmY2Yzk5N2ZlOGY4NWMzMGM4Y2I4N2MwNzBk
|
15
|
+
NWM1Y2E4NDAzZTUyZGM3YTZhN2JkMjQzNjFhZjViYjBmM2IzNmY=
|
data/lib/webmock-rspec-helper.rb
CHANGED
@@ -5,13 +5,18 @@ module WebMock
|
|
5
5
|
module RSpec
|
6
6
|
module Helper
|
7
7
|
|
8
|
-
def webmock(method, mocks = {})
|
9
|
-
mocks.each do |regex,
|
10
|
-
|
11
|
-
|
8
|
+
def webmock(method, mocks = {}, with: false)
|
9
|
+
mocks.each do |regex, result|
|
10
|
+
if result.to_s =~ /\A\d+\z/
|
11
|
+
status = result
|
12
|
+
body = ''
|
13
|
+
else
|
14
|
+
status = result[/\.(\d+)\./, 1] || 200
|
15
|
+
body = File.read Rails.root.join('spec', 'support', 'stubs', result)
|
16
|
+
end
|
12
17
|
|
13
18
|
stub = WebMock.stub_request(method, regex)
|
14
|
-
stub.with(
|
19
|
+
stub.with(with) if with
|
15
20
|
stub.to_return status: status.to_i, body: body
|
16
21
|
end
|
17
22
|
end
|
@@ -22,4 +27,4 @@ end
|
|
22
27
|
|
23
28
|
RSpec.configure do |config|
|
24
29
|
config.include WebMock::RSpec::Helper
|
25
|
-
end
|
30
|
+
end
|
@@ -29,14 +29,22 @@ describe '#webmock' do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'accepts a block that returns the with options' do
|
32
|
-
webmock
|
32
|
+
webmock :get, %r[google.com] => 'GET_google.json', with: Hash[query: { test: '123' }]
|
33
33
|
expect { GET('http://google.com') }.to raise_error(WebMock::NetConnectNotAllowedError) rescue nil
|
34
34
|
response = GET('http://google.com?test=123')
|
35
35
|
expect(response.status).to eq 200
|
36
36
|
end
|
37
|
+
|
38
|
+
it 'mocks GET google with an empty body and given status code' do
|
39
|
+
webmock :get, %r[google.com] => 204
|
40
|
+
response = GET('http://google.com')
|
41
|
+
expect(response.body).to eq ''
|
42
|
+
expect(response.status).to eq 204
|
43
|
+
end
|
37
44
|
end
|
38
45
|
|
39
46
|
def GET(url)
|
40
47
|
response = Net::HTTP.get_response URI.parse(url)
|
41
|
-
|
48
|
+
body = response.body ? JSON.parse(response.body) : ''
|
49
|
+
OpenStruct.new status: response.code.to_i, body: body
|
42
50
|
end
|
@@ -18,11 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.required_ruby_version = '~> 2'
|
22
|
+
|
21
23
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
25
|
|
24
26
|
spec.add_dependency 'rspec'
|
25
27
|
spec.add_dependency 'webmock'
|
26
28
|
spec.add_dependency 'rails', '>= 3.0.0'
|
27
|
-
|
28
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock-rspec-helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Logan Serman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,9 +110,9 @@ require_paths:
|
|
110
110
|
- lib
|
111
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
|
-
- -
|
113
|
+
- - ~>
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version: '
|
115
|
+
version: '2'
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|