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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTYxMjlhOWZlYjY5ZjU0ODgwYTM1YTFmMDBiMmJjODhkYmNiNGZmYw==
4
+ MjM4MjI5YzY3ODZiYzBkZmZmMGUxYjZmOTcxOGMwZDA5ZWUyZWRiMw==
5
5
  data.tar.gz: !binary |-
6
- ZWUxZGNhMzc5MjRlNWU0YzdkNWMyMGNmODFjNmUzZDU3ODc0MzcyMg==
6
+ NGVhYjU2M2Q1MWZiZDliYjc5MTZhNjU4NzQ4ZDc4YjFmMTEzNjJiYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTlhZDczY2ZjODhiMWU1Y2EwMWIzZDI5YmYxYzI4OTc4NDk3MDRjYjA0OWRh
10
- MmJmY2I5NmRkYjI0N2M1YTU1ZTM2YzA5NzAyOTcyYzQ1ZTA1ZjllYWM3YzM4
11
- OTJmMWU2MGQzOTc4ZmNhYTAxYmIxZjRjZTEwYWZjYzRjY2Y3YTU=
9
+ MmNlOThlZmM1NmM0YmZiYTYzZTMyMzhhNzFhMzI1ODI3MWYyODljOGZjYjE4
10
+ MmYxYzhmNmRjMDVjNjQ0YTFjNzkwZjQ2ODhmNGE3ZDRjMDEyNWM0MDM2NWJi
11
+ YTg2MGI3MmJiN2MwNGQ2ZWI1YTMwYTFkZDA5ODkzYjlhNDk0ZWU=
12
12
  data.tar.gz: !binary |-
13
- Zjc0YTc3Y2E5ZDk4NTE2MWUwZDJmOTU3N2JmNDAyZTFlYzIzNzMxMTcwYzVi
14
- MTYyMzkzODc1NDAzNzcyMTMyODFlZWUyYWZmZGRjYzZiYjFjYjE3MzBiYmQ5
15
- MThkNDkxZGRkZThjODZhODIyZWRjYjY1YmExNDBiNzA4MGNhYjY=
13
+ ZjUzMDc1ZWYzYWQzYzVhODg4NmM1NWFhZWVhMTkyYzQ3YTNmOGQ2MGFkOTdj
14
+ YTc2NjdhY2JkOWY3NTJhOWNkYmY2Yzk5N2ZlOGY4NWMzMGM4Y2I4N2MwNzBk
15
+ NWM1Y2E4NDAzZTUyZGM3YTZhN2JkMjQzNjFhZjViYjBmM2IzNmY=
@@ -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, filename|
10
- status = filename[/\.(\d+)\./, 1] || 200
11
- body = File.read Rails.root.join('spec', 'support', 'stubs', filename)
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(yield) if block_given?
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
@@ -1,7 +1,7 @@
1
1
  module WebMock
2
2
  module RSpec
3
3
  module Helper
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
6
6
  end
7
- end
7
+ 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(:get, %r[google.com] => 'GET_google.json') { Hash[query: { test: '123' }] }
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
- OpenStruct.new status: response.code.to_i, body: JSON.parse(response.body)
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.3
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-02-10 00:00:00.000000000 Z
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: '0'
115
+ version: '2'
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - ! '>='