forked from vcr/vcr
/
format.feature
92 lines (84 loc) · 2.6 KB
/
format.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Feature: Cassette format
VCR Cassettes are YAML files that contain all of the information
about the requests and corresponding responses in a
human-readable/editable format. A cassette contains an array
of HTTP interactions, each of which has the following:
- request
- method
- uri
- body
- headers
- response
- status
- code
- message
- headers
- body
- http version
Scenario Outline: Request/Response data is saved to disk as YAML
Given a file named "cassette_format.rb" with:
"""
require 'vcr_cucumber_helpers'
include_http_adapter_for("<http_lib>")
start_sinatra_app(:port => 7777) do
get('/:path') { ARGV[0] + ' ' + params[:path] }
end
require 'vcr'
VCR.config do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
VCR.use_cassette('example', :record => :new_episodes) do
make_http_request(:get, "http://localhost:7777/foo")
make_http_request(:get, "http://localhost:7777/bar")
end
"""
When I run "ruby cassette_format.rb 'Hello'"
Then the file "cassettes/example.yml" should contain YAML like:
"""
---
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :get
uri: http://localhost:7777/foo
body:
headers:
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
headers:
content-type:
- text/html;charset=utf-8
content-length:
- "9"
body: Hello foo
http_version: "1.1"
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :get
uri: http://localhost:7777/bar
body:
headers:
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
headers:
content-type:
- text/html;charset=utf-8
content-length:
- "9"
body: Hello bar
http_version: "1.1"
"""
Examples:
| stub_with | http_lib |
| :fakeweb | net/http |
| :webmock | net/http |
| :webmock | httpclient |
| :webmock | patron |
| :webmock | curb |
| :webmock | em-http-request |
| :typhoeus | typhoeus |
| :excon | excon |