forked from vcr/vcr
/
persistence.feature
63 lines (50 loc) · 1.9 KB
/
persistence.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Feature: Cassette Persistence
By default, cassettes will be persisted to the file system. However, you
can easily configure VCR to persist the cassettes to a database, a key-value
store, or anywhere you like.
To use something besides the file system, you must provide an object
that provides a hash-like interface:
* `persister[name]` should return the content previously persisted for the
given cassette name.
* `persister[name] = content` should persist the content for the
given cassette name.
Register this object with VCR, and then you can configure all cassettes
to use it (using the `default_cassette_options`) or just some cassettes
to use it (by passing it as an option to individual cassettes).
Scenario: Persist cassettes in Redis
Given the redis DB has no data
And a file named "use_redis.rb" with:
"""ruby
if ARGV.include?('--with-server')
start_sinatra_app(:port => 7777) do
get('/') { "Hello" }
end
end
require 'redis'
class RedisCassettePersister
def initialize(redis)
@redis = redis
end
def [](name)
@redis.get(name)
end
def []=(name, content)
@redis.set(name, content)
end
end
require 'vcr'
VCR.configure do |c|
c.hook_into :fakeweb
c.cassette_persisters[:redis] = RedisCassettePersister.new(Redis.connect)
c.default_cassette_options = { :persist_with => :redis }
end
VCR.use_cassette("redis_example") do
response = Net::HTTP.get_response('localhost', '/', 7777)
puts "Response: #{response.body}"
end
"""
When I run `ruby use_redis.rb --with-server`
Then it should pass with "Hello"
And the value stored at the redis key "redis_example.yml" should include "Hello"
When I run `ruby use_redis.rb`
Then it should pass with "Hello"