File: decompress.feature

package info (click to toggle)
ruby-vcr 6.0.0%2Breally5.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,320 kB
  • sloc: ruby: 8,456; sh: 177; makefile: 7
file content (74 lines) | stat: -rw-r--r-- 2,188 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
Feature: Decode compressed response

  When the `:decode_compressed_response` option is set to a truthy value, VCR
  will decompress "gzip" and "deflate" response bodies before recording.  This
  ensures that these interactions become readable and editable after being
  serialized.

  This option should be avoided if the actual decompression of response bodies
  is part of the functionality of the library or app being tested.

  Background:
    Given a file named "decompress.rb" with:
      """ruby
      require 'zlib'
      require 'stringio'

      $server = start_sinatra_app do
        get('/') {
          content = 'The quick brown fox jumps over the lazy dog'
          io = StringIO.new

          writer = Zlib::GzipWriter.new(io)
          writer << content
          writer.close

          headers['Content-Encoding'] = 'gzip'
          io.string
        }
      end

      require 'vcr'

      VCR.configure do |c|
        c.cassette_library_dir = 'cassettes'
        c.hook_into :webmock
        c.default_cassette_options = { :serialize_with => :syck }
      end
      """

  Scenario: The option is not set by default
    When I append to file "decompress.rb":
      """ruby
      VCR.use_cassette(:decompress) do
        Net::HTTP.start('localhost', $server.port) do |http|
          http.get('/', 'accept-encoding' => 'identity')
        end
      end
      """
    And I run `ruby decompress.rb`
    Then the file "cassettes/decompress.yml" should contain a YAML fragment like:
      """
      Content-Encoding:
      - gzip
      """

  Scenario: The option is enabled
    When I append to file "decompress.rb":
      """ruby
      VCR.use_cassette(:decompress, :decode_compressed_response => true) do
        Net::HTTP.start('localhost', $server.port) do |http|
          http.get('/', 'accept-encoding' => 'identity')
        end
      end
      """
    And I run `ruby decompress.rb`
    Then the file "cassettes/decompress.yml" should contain a YAML fragment like:
      """
      Content-Length:
      - '43'
      """
    And the file "cassettes/decompress.yml" should contain:
      """
      string: The quick brown fox jumps over the lazy dog
      """