webmock-rspec-helper 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzFlOWQ2MWUyMGNlMjY1ZDliOTgyZGU2OTk4OGQwYWE2N2Y5Yzk1Yg==
5
+ data.tar.gz: !binary |-
6
+ YWM1YzEwNzE3NGI2MzljN2MwZWQ3YzRmMzdhMTdhMmY5YzBhZTc2MA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NjYyNjgzNmIwNzE5NGI5YzVmZjA3NWQ5YWE4Y2U0NDBlYzA0ZWJhMTc2NmZl
10
+ YTNhZDQ5MmFlMmExMjAxMWEwYWM0NTlhNWQ5OTk3ODg3OTM5OTBkNGQ5NTA5
11
+ MTVkY2QyMDY1MmZkZGJmM2MwMDRkZmNkN2ViY2I5NmU5M2M1NTU=
12
+ data.tar.gz: !binary |-
13
+ OGUyOTBlM2Y0NjY0Njc5OTE0YWY0YjgyMGUyNTQzMzA2ZWE1YTkyODBkNTY4
14
+ NjA2NjBjNjEzODI5NmE1NmE1M2E5ZDE5ZWNlZTlkYjQ1OWMxMTE3M2I1OGU2
15
+ ZDhkMmYwZmJkMGM1N2NjODc3MzJhNjY5MjEwZDQ4OTBhMWMzODI=
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.0
6
+ deploy:
7
+ provider: rubygems
8
+ gem:
9
+ release: webmock-rspec-helper
10
+ on:
11
+ repo: lserman/webmock-rspec-helper
12
+ branch: master
13
+ api_key:
14
+ secure: Cqfq5ez+4+CqpPEjDhUF3Nmbd2GgYHlD2GBmK1aVtXPh0DqR24WnkJuT7ug/PJT9qlYMlP6Bp8QM7LViBmh5UcPDK2nUxnbtBBoMahV7/Y1UMPzTMPtUKuCLqd4vgGlYcK6rDc/fXVwGjgbDJUtvmeXd0eG961+4jb6BNfOmnEA=
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in webmock-rspec-helper.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Logan Serman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # WebMock RSpec Helper
2
+
3
+ This gem provides a helper method `webmock` which makes it easier to stub requests.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile and `bundle`:
8
+
9
+ ```ruby
10
+ gem 'webmock-rspec-helper'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Use the `webmock` method to map regular expressions to a filename. Files should be `spec/support/stubs`. The
16
+ `webmock` method will parse any digits between periods out of the filename to infer the status code (defaulting to 200).
17
+
18
+ Given the directory tree:
19
+
20
+ ```
21
+ spec/
22
+ support/
23
+ stubs/
24
+ GET_google.json
25
+ GET_google.401.json
26
+ webmock_spec.rb
27
+ ```
28
+
29
+ You can use `webmock` within webmock_spec.rb like this:
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'`
36
+
37
+ Will stub requests to Google to return the contents of GET_google.401.json. Requests will return a 401 status code.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/[my-github-username]/webmock-rspec-helper/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
6
+
@@ -0,0 +1,21 @@
1
+ module WebMock
2
+ module RSpec
3
+ module Helper
4
+
5
+ VERSION = '0.0.1'
6
+
7
+ def webmock(method, mocks = {})
8
+ mocks.each do |regex, filename|
9
+ status = filename[/\.(\d+)\./)] || 200
10
+ body = File.read Rails.root.join('spec', 'support', filename)
11
+ WebMock.stub_request(method, regex).to_return status: status, body: body
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+
19
+ RSpec.configure do |config|
20
+ config.include WebMock::RSpec::Helper
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'webmock'
2
+ require 'rspec'
3
+
4
+ module WebMock
5
+ module RSpec
6
+ module Helper
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)
12
+ WebMock.stub_request(method, regex).to_return status: status.to_i, body: body
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+
20
+ RSpec.configure do |config|
21
+ config.include WebMock::RSpec::Helper
22
+ end
@@ -0,0 +1,7 @@
1
+ module WebMock
2
+ module RSpec
3
+ module Helper
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require "webmock/rspec/helper/version"
2
+
3
+ module Webmock
4
+ module Rspec
5
+ module Helper
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Webmock
2
+ module Rspec
3
+ module Helper
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ { "google": true }
@@ -0,0 +1 @@
1
+ { "google": true }
@@ -0,0 +1,35 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ require 'webmock-rspec-helper'
6
+ require 'webmock/rspec'
7
+
8
+ WebMock.disable_net_connect!
9
+
10
+ class WebMock::RSpec::Helper::Rails
11
+ def self.root
12
+ Pathname.new File.expand_path('../..', __FILE__)
13
+ end
14
+ end
15
+
16
+ describe '#webmock' do
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')
20
+ expect(response.status).to eq 200
21
+ expect(response.body['google']).to eq true
22
+ end
23
+
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')
27
+ expect(response.status).to eq 999
28
+ expect(response.body['google']).to eq true
29
+ end
30
+ end
31
+
32
+ def GET(url)
33
+ response = Net::HTTP.get_response URI.parse('http://google.com')
34
+ OpenStruct.new status: response.code.to_i, body: JSON.parse(response.body)
35
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'webmock-rspec-helper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'webmock-rspec-helper'
8
+ spec.version = WebMock::RSpec::Helper::VERSION
9
+ spec.authors = ['Logan Serman']
10
+ spec.email = ['logan.serman@metova.com']
11
+ spec.summary = 'Easily define WebMock stubs that point to JSON files'
12
+ spec.description = spec.summary
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+
24
+ spec.add_dependency 'rspec'
25
+ spec.add_dependency 'webmock'
26
+ spec.add_dependency 'rails', '>= 3.0.0'
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webmock-rspec-helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Logan Serman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ description: Easily define WebMock stubs that point to JSON files
84
+ email:
85
+ - logan.serman@metova.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - helper.rb
97
+ - lib/webmock-rspec-helper.rb
98
+ - lib/webmock-rspec-helper/version.rb
99
+ - lib/webmock/rspec/helper.rb
100
+ - lib/webmock/rspec/helper/version.rb
101
+ - spec/support/stubs/GET_google.999.json
102
+ - spec/support/stubs/GET_google.json
103
+ - spec/webmock-rspec-helper_spec.rb
104
+ - webmock-rspec-helper.gemspec
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.5
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Easily define WebMock stubs that point to JSON files
129
+ test_files:
130
+ - spec/support/stubs/GET_google.999.json
131
+ - spec/support/stubs/GET_google.json
132
+ - spec/webmock-rspec-helper_spec.rb