webmock-rspec-helper 0.0.4 → 0.0.5

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
- MjM4MjI5YzY3ODZiYzBkZmZmMGUxYjZmOTcxOGMwZDA5ZWUyZWRiMw==
4
+ MjNjMzc5ZWQ0OTZkOWU4NzkzYmUxNzE4NGFhMjMyM2NhZjQwNzRlMQ==
5
5
  data.tar.gz: !binary |-
6
- NGVhYjU2M2Q1MWZiZDliYjc5MTZhNjU4NzQ4ZDc4YjFmMTEzNjJiYg==
6
+ ZjQyNWE0NzMzYWYyMjg3NjQ5Njg3N2RjYjZlMmQ0NTc0ZTI5NWE0YQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmNlOThlZmM1NmM0YmZiYTYzZTMyMzhhNzFhMzI1ODI3MWYyODljOGZjYjE4
10
- MmYxYzhmNmRjMDVjNjQ0YTFjNzkwZjQ2ODhmNGE3ZDRjMDEyNWM0MDM2NWJi
11
- YTg2MGI3MmJiN2MwNGQ2ZWI1YTMwYTFkZDA5ODkzYjlhNDk0ZWU=
9
+ NzI4MTI0MjY5NTcxYzk1MGRjN2E5MjM3OTg5ZWUyYTUwYTQ1ZGNhZjUzM2Y3
10
+ NWFhZGYwMjE4NDc2NDE3ZjYyMTVlYWI1ODkyNTljYTM4ZTAwN2NlNTdkZTI0
11
+ MzgyMDg4Y2UyNjkzZGM4ZmU2NTlkZTg2ZjRlZGJjZmY2ODY0MTQ=
12
12
  data.tar.gz: !binary |-
13
- ZjUzMDc1ZWYzYWQzYzVhODg4NmM1NWFhZWVhMTkyYzQ3YTNmOGQ2MGFkOTdj
14
- YTc2NjdhY2JkOWY3NTJhOWNkYmY2Yzk5N2ZlOGY4NWMzMGM4Y2I4N2MwNzBk
15
- NWM1Y2E4NDAzZTUyZGM3YTZhN2JkMjQzNjFhZjViYjBmM2IzNmY=
13
+ ZWY4YWYzNzc1MjFiMGU1NDBmN2E1NDNmNzNmYjg3MjIxZmQ3ZmI3MjQ3NjUw
14
+ MjJiYjA4OWQxNzdiOGVlNzI2NzcyOWM0MDczYzlkMTQ2MjJjNmI5MTM5NmVk
15
+ MjBlYWVhMDA5NDQ3MjUxYzdhMTkxMjcxMWViNTY5MzhiMmQwZWY=
data/README.md CHANGED
@@ -28,17 +28,19 @@ spec/
28
28
 
29
29
  You can use `webmock` within webmock_spec.rb like this:
30
30
 
31
- `webmock :get, %r[google.com] => 'GET_google.json'`
32
-
33
- Will stub requests to Google to return the contents of GET_google.json. Requests will return a 200 status code.
34
-
35
- `webmock :get, %r[google.com] => 'GET_google.401.json'`
31
+ ```ruby
32
+ # Will stub requests to Google to return the contents of GET_google.json. Requests will return a 200 status code.
33
+ webmock :get, %r[google.com] => 'GET_google.json'
36
34
 
37
- Will stub requests to Google to return the contents of GET_google.401.json. Requests will return a 401 status code.
35
+ # Stub requests to Google to return the contents of GET_google.401.json. Requests will return a 401 status code.
36
+ webmock :get, %r[google.com] => 'GET_google.401.json'
38
37
 
39
- Any options that need to go into `with` can be given as the return value of a block passed into `webmock`:
38
+ # Stub requests to Google to return a 204 status code and an empty body
39
+ webmock :get, %r[google.com] => 204
40
40
 
41
- `webmock(:get, %r[:google.com] => 'GET_google.json') { Hash[query: { test: '123' }] }`
41
+ # Stub requests to Google to return the contents of GET_google.json when the query parameters match { test: '123' }
42
+ webmock :get, %r[:google.com] => 'GET_google.json', with: Hash[query: { test: '123' }]
43
+ ```
42
44
 
43
45
  ## Contributing
44
46
 
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rspec-core", "rspec")
@@ -5,7 +5,7 @@ module WebMock
5
5
  module RSpec
6
6
  module Helper
7
7
 
8
- def webmock(method, mocks = {}, with: false)
8
+ def webmock(method, mocks = {}, with: false, headers: nil)
9
9
  mocks.each do |regex, result|
10
10
  if result.to_s =~ /\A\d+\z/
11
11
  status = result
@@ -17,7 +17,7 @@ module WebMock
17
17
 
18
18
  stub = WebMock.stub_request(method, regex)
19
19
  stub.with(with) if with
20
- stub.to_return status: status.to_i, body: body
20
+ stub.to_return status: status.to_i, body: body, headers: headers
21
21
  end
22
22
  end
23
23
 
@@ -1,7 +1,7 @@
1
1
  module WebMock
2
2
  module RSpec
3
3
  module Helper
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -15,36 +15,42 @@ end
15
15
 
16
16
  describe '#webmock' do
17
17
  it 'mocks GET google using default response 200' do
18
- webmock :get, %r[google.com] => 'GET_google.json'
19
- response = GET('http://google.com')
18
+ webmock :get, %r{google.com} => 'GET_google.json'
19
+ response = GET 'http://google.com'
20
20
  expect(response.status).to eq 200
21
21
  expect(response.body['google']).to eq true
22
22
  end
23
23
 
24
24
  it 'mocks GET google with custom response code' do
25
- webmock :get, %r[google.com] => 'GET_google.999.json'
26
- response = GET('http://google.com')
25
+ webmock :get, %r{google.com} => 'GET_google.999.json'
26
+ response = GET 'http://google.com'
27
27
  expect(response.status).to eq 999
28
28
  expect(response.body['google']).to eq true
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', with: Hash[query: { test: '123' }]
33
- expect { GET('http://google.com') }.to raise_error(WebMock::NetConnectNotAllowedError) rescue nil
34
- response = GET('http://google.com?test=123')
32
+ webmock :get, %r{google.com} => 'GET_google.json', with: Hash[query: { test: '123' }]
33
+ expect { GET 'http://google.com' }.to raise_error WebMock::NetConnectNotAllowedError
34
+ response = GET 'http://google.com?test=123'
35
35
  expect(response.status).to eq 200
36
36
  end
37
37
 
38
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')
39
+ webmock :get, %r{google.com} => 204
40
+ response = GET 'http://google.com'
41
41
  expect(response.body).to eq ''
42
42
  expect(response.status).to eq 204
43
43
  end
44
+
45
+ it 'mocks GET google with response headers' do
46
+ webmock :get, %r{google.com} => 'GET_google.json', headers: { 'Content-Type' => 'text/html' }
47
+ response = GET 'http://google.com'
48
+ expect(response.content_type).to eq 'text/html'
49
+ end
44
50
  end
45
51
 
46
52
  def GET(url)
47
53
  response = Net::HTTP.get_response URI.parse(url)
48
54
  body = response.body ? JSON.parse(response.body) : ''
49
- OpenStruct.new status: response.code.to_i, body: body
55
+ OpenStruct.new status: response.code.to_i, body: body, content_type: response['Content-Type']
50
56
  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
4
+ version: 0.0.5
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-08-20 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,7 +83,8 @@ dependencies:
83
83
  description: Easily define WebMock stubs that point to JSON files
84
84
  email:
85
85
  - logan.serman@metova.com
86
- executables: []
86
+ executables:
87
+ - rspec
87
88
  extensions: []
88
89
  extra_rdoc_files: []
89
90
  files:
@@ -93,6 +94,7 @@ files:
93
94
  - LICENSE.txt
94
95
  - README.md
95
96
  - Rakefile
97
+ - bin/rspec
96
98
  - helper.rb
97
99
  - lib/webmock-rspec-helper.rb
98
100
  - lib/webmock-rspec-helper/version.rb