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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3825c1470087671fef46cf5a1109efd7471b371b
4
- data.tar.gz: 21302ea609c296cf2e727550183ddccc9c2032b2
3
+ metadata.gz: b6eaa58258aa9c40597d031ac0d03e66802213d7
4
+ data.tar.gz: 552949bbaae571fefe1585362e9f37c512de92f1
5
5
  SHA512:
6
- metadata.gz: 45d499d8e3558ae702bc7caeb004a2c59369666f61a5c1b73430fb8882fa782c91ab755683b126f198cb2bf3344673b6dc72af120b62d29278e1cc37ab8c6c59
7
- data.tar.gz: df1645554a7dd7dbeb84fa96788901cd80483a071d22cda77b2518a9945f6341229769ef7287ac9f74f3e241e7d3f1a4cd2329a2d66b08f9b4e6dfe28caa1bd3
6
+ metadata.gz: 3a74839ff79299c0ff6534eb941494d6020fb165150128e068bf0c020f5c1d5f6443ecec46fe3272460604a43bc55208536bbb255e0cb2a32671e26db851f482
7
+ data.tar.gz: 15378c43828be779772e2dfcd0deec5b062d4c7e0a8b80f23bcf3a6de7f968e3c1faaecd648786211836bc1cbef47e050fe96972ef461bd560aeb569a220cdbb
@@ -1,3 +1,6 @@
1
+ ## 0.1.3 (2015/06/18)
2
+ - Document replay/cassette option and add tests for them
3
+
1
4
  ## 0.1.2 (2015/06/17)
2
5
  - Add experimental `replay: true` option to replay VCR cassette on the Rack layer
3
6
 
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
 
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class VCR
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
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.2
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-18 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vcr