Sha256: 77e71e3739a0775b2b3faae4358c95b1a4caf5a8982e0616a2ac0366db87787d

Contents?: true

Size: 1.9 KB

Versions: 10

Compression:

Stored size: 1.9 KB

Contents

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 :webmock
        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"

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/vcr-2.9.3/features/cassettes/persistence.feature
vcr-2.9.3 features/cassettes/persistence.feature
vcr-2.9.2 features/cassettes/persistence.feature
vcr-2.9.1 features/cassettes/persistence.feature
vcr-2.9.0 features/cassettes/persistence.feature
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/vcr-2.8.0/features/cassettes/persistence.feature
vcr-2.8.0 features/cassettes/persistence.feature
vcr-2.7.0 features/cassettes/persistence.feature
vcr-2.6.0 features/cassettes/persistence.feature
vcr-2.5.0 features/cassettes/persistence.feature