rack-vcr 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rack/vcr.rb +19 -0
- data/lib/rack/vcr/transaction.rb +59 -0
- data/lib/rack/vcr/version.rb +5 -0
- data/rack-vcr.gemspec +31 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b52f5eecaf0bb0a9faca2dc3dd5c7bd548a1685c
|
4
|
+
data.tar.gz: e5aa7389b370b3d6a432deed7aaae7773319645a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8196ada048868ee8ae3307b2ffd09dd8a36406b43be2ce9768f0e04fa66111476e911ab024b22bdf11ce9fbb70e9a5169bdea36f1d8ca5331b39a6b47b7beba7
|
7
|
+
data.tar.gz: fdcadc1e66695e5c683292f2f2193de6d8f4dfc35e375c675ed9bde6badf3084c43604930e81237e3b36a526324cd1e6762a9be91ea1e9e77fbc086e0302afdf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Tatsuhiko Miyagawa
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Rack::VCR
|
2
|
+
|
3
|
+
Rack::VCR captures incoming HTTP requests and responses on your Rack application (Rails, Sinatra) and saves them as a VCR fixture in cassettes.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rack-vcr'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rack-vcr
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Rails
|
24
|
+
|
25
|
+
TBD
|
26
|
+
|
27
|
+
### Sinatra/Rack
|
28
|
+
|
29
|
+
To capture HTTP interactions, enable VCR configuration in addition to this middleware, in the spec:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'rack/test'
|
33
|
+
|
34
|
+
VCR.configure do |config|
|
35
|
+
config.cassette_library_dir = "vcr_cassettes"
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'My Web App' do
|
39
|
+
include Rack::Test::Methods
|
40
|
+
|
41
|
+
let(:app) {
|
42
|
+
Rack::Builder.new do
|
43
|
+
use Rack::VCR
|
44
|
+
run Sinatra::Application
|
45
|
+
end
|
46
|
+
}
|
47
|
+
|
48
|
+
it 'runs the request' do
|
49
|
+
VCR.use_cassette('hello', record: :all) do
|
50
|
+
get "/hello"
|
51
|
+
end
|
52
|
+
# Now you get vcr_cassettes/hello.yml saved
|
53
|
+
end
|
54
|
+
end
|
55
|
+
````
|
56
|
+
|
57
|
+
## Notes
|
58
|
+
|
59
|
+
There's a few similar gems available on Rubygems and GitHub:
|
60
|
+
|
61
|
+
* [VCR::Middleware::Rack](https://www.relishapp.com/vcr/vcr/v/1-6-0/docs/middleware/rack) - Records *outgoing* HTTP requests inside a Rack application. Quite opposite to what Rack::VCR gem does.
|
62
|
+
* [rack-recorder](https://github.com/kodev/rack-recorder) - Essentially the same with Rack::VCR, but is very limited in what it does. It doesn't export the captured transaction in VCR compatible format.
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/miyagawa/rack-vcr.
|
67
|
+
|
68
|
+
## Author
|
69
|
+
|
70
|
+
Tatsuhiko Miyagawa
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
75
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack/vcr"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/rack/vcr.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "rack/vcr/version"
|
2
|
+
require "rack/vcr/transaction"
|
3
|
+
require "vcr"
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
class VCR
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
req = Rack::Request.new(env)
|
13
|
+
status, headers, body = @app.call(env)
|
14
|
+
res = Rack::Response.new(body, status, headers)
|
15
|
+
Transaction.capture(req, res)
|
16
|
+
[status, headers, body]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Rack
|
2
|
+
class VCR
|
3
|
+
class Transaction
|
4
|
+
def self.capture(*args)
|
5
|
+
new(*args).record
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(req, res)
|
9
|
+
@req, @res = req, res
|
10
|
+
end
|
11
|
+
|
12
|
+
def record
|
13
|
+
::VCR.record_http_interaction(::VCR::HTTPInteraction.new(vcr_request, vcr_response))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def vcr_request
|
19
|
+
::VCR::Request.new(@req.request_method, @req.url, try_read(@req.body), request_headers)
|
20
|
+
end
|
21
|
+
|
22
|
+
def vcr_response
|
23
|
+
::VCR::Response.new(
|
24
|
+
::VCR::ResponseStatus.new(@res.status, nil),
|
25
|
+
@res.headers,
|
26
|
+
@res.body.join(''),
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def request_headers
|
31
|
+
headers_hash_from_env.merge(content_field_hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
def headers_hash_from_env
|
35
|
+
fields = @req.env.select {|k, v| k.start_with? 'HTTP_' }
|
36
|
+
.collect { |k, v| [normalize_header_field(k), v] }
|
37
|
+
Hash[fields]
|
38
|
+
end
|
39
|
+
|
40
|
+
def content_field_hash
|
41
|
+
{ "Content-Type" => @req.env["CONTENT_TYPE"],
|
42
|
+
"Content-Length" => @req.env["CONTENT_LENGTH"] }.reject {|k, v| v.nil? or v == "0" }
|
43
|
+
end
|
44
|
+
|
45
|
+
def normalize_header_field(k)
|
46
|
+
k.sub(/^HTTP_/, '')
|
47
|
+
.split('_').map(&:capitalize).join('-')
|
48
|
+
end
|
49
|
+
|
50
|
+
def try_read(body)
|
51
|
+
if body
|
52
|
+
b = body.read
|
53
|
+
body.rewind
|
54
|
+
b
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/rack-vcr.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/vcr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-vcr"
|
8
|
+
spec.version = Rack::VCR::VERSION
|
9
|
+
spec.authors = ["Tatsuhiko Miyagawa"]
|
10
|
+
spec.email = ["miyagawa@bulknews.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{Record incoming Rack request as VCR cassettes}
|
13
|
+
spec.description = %q{This Rack middleware records incoming Rack request and responses in a VCR compatible format.}
|
14
|
+
spec.homepage = "https://github.com/miyagawa/rack-vcr"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "vcr", "~> 2.9"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
|
28
|
+
spec.add_development_dependency "sinatra", "~> 1.4"
|
29
|
+
spec.add_development_dependency "rack-test", "~> 0.6"
|
30
|
+
spec.add_development_dependency "webmock", "~> 1.21"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-vcr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tatsuhiko Miyagawa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: vcr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack-test
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.21'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.21'
|
111
|
+
description: This Rack middleware records incoming Rack request and responses in a
|
112
|
+
VCR compatible format.
|
113
|
+
email:
|
114
|
+
- miyagawa@bulknews.net
|
115
|
+
executables:
|
116
|
+
- console
|
117
|
+
- setup
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- ".gitignore"
|
122
|
+
- ".rspec"
|
123
|
+
- ".travis.yml"
|
124
|
+
- CHANGELOG.md
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- lib/rack/vcr.rb
|
132
|
+
- lib/rack/vcr/transaction.rb
|
133
|
+
- lib/rack/vcr/version.rb
|
134
|
+
- rack-vcr.gemspec
|
135
|
+
homepage: https://github.com/miyagawa/rack-vcr
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.4.6
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: Record incoming Rack request as VCR cassettes
|
159
|
+
test_files: []
|