rack-vcr 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +48 -4
- data/lib/rack/vcr.rb +11 -0
- data/lib/rack/vcr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6eaa58258aa9c40597d031ac0d03e66802213d7
|
4
|
+
data.tar.gz: 552949bbaae571fefe1585362e9f37c512de92f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a74839ff79299c0ff6534eb941494d6020fb165150128e068bf0c020f5c1d5f6443ecec46fe3272460604a43bc55208536bbb255e0cb2a32671e26db851f482
|
7
|
+
data.tar.gz: 15378c43828be779772e2dfcd0deec5b062d4c7e0a8b80f23bcf3a6de7f968e3c1faaecd648786211836bc1cbef47e050fe96972ef461bd560aeb569a220cdbb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
### Rails
|
23
|
+
### Capturing in Rails
|
24
24
|
|
25
25
|
In `config/initializer/rack_vcr.rb`:
|
26
26
|
|
@@ -48,9 +48,10 @@ RSpec.configure do |config|
|
|
48
48
|
end
|
49
49
|
```
|
50
50
|
|
51
|
-
### Sinatra/Rack
|
51
|
+
### Capturing in Sinatra/Rack
|
52
|
+
|
53
|
+
In `spec/spec_helper.rb`:
|
52
54
|
|
53
|
-
To capture HTTP interactions, enable VCR configuration in addition to this middleware, in the spec:
|
54
55
|
|
55
56
|
```ruby
|
56
57
|
require 'rack/test'
|
@@ -76,7 +77,50 @@ describe 'My Web App' do
|
|
76
77
|
# Now you get vcr_cassettes/hello.yml saved
|
77
78
|
end
|
78
79
|
end
|
79
|
-
|
80
|
+
```
|
81
|
+
|
82
|
+
### Replaying
|
83
|
+
|
84
|
+
Rack::VCR also supports *replaying* recorded VCR cassettes. It means you can record the HTTP interactions with the real app (on CI), then use the cassette to run a fake/mock API server using Rack::VCR!
|
85
|
+
|
86
|
+
To replay cassettes, enable Rack::VCR with `:replay` option in `config.ru` or its equivalent.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
VCR.configure do |config|
|
90
|
+
config.cassette_library_dir = "/path/to/cassettes"
|
91
|
+
end
|
92
|
+
|
93
|
+
Rack::Builder.new do
|
94
|
+
use Rack::VCR, replay: true, cassette: "test"
|
95
|
+
run MyApp
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
With the above setting, Rack::VCR will try to locate the cassette named "test" to replay if the request matches with what's recorded, and fall through to the original application if it's not there.
|
100
|
+
|
101
|
+
To customize the cassette name in runtime, you can write a custom piece of Rack middleware around Rack::VCR to wrap the application in `VCR.use_cassette` with its own `:record` option.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
class CassetteLocator
|
105
|
+
def initialize(app)
|
106
|
+
@app = app
|
107
|
+
end
|
108
|
+
|
109
|
+
def call(env)
|
110
|
+
cassette = ... # determine cassette from env
|
111
|
+
VCR.use_cassette(casssette, record: :none) do
|
112
|
+
@app.call(env)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
Rack::Builder.new do
|
118
|
+
use CassetteLocator
|
119
|
+
use Rack::VCR, replay: true
|
120
|
+
run MyApp
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
80
124
|
|
81
125
|
## Notes
|
82
126
|
|
data/lib/rack/vcr.rb
CHANGED
@@ -7,9 +7,20 @@ module Rack
|
|
7
7
|
def initialize(app, options = {})
|
8
8
|
@app = app
|
9
9
|
@replay = options[:replay]
|
10
|
+
@cassette = options[:cassette]
|
10
11
|
end
|
11
12
|
|
12
13
|
def call(env)
|
14
|
+
if @cassette
|
15
|
+
::VCR.use_cassette(@cassette, record: :new_episodes) do
|
16
|
+
run_request(env)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
run_request(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_request(env)
|
13
24
|
req = Rack::Request.new(env)
|
14
25
|
transaction = Transaction.new(req)
|
15
26
|
|
data/lib/rack/vcr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-vcr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuhiko Miyagawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vcr
|