vcr 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +156 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette1.yml +43 -0
- data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette2.yml +45 -0
- data/features/fixtures/vcr_cassettes/1.8.6/nested_replay_cassette.yml +23 -0
- data/features/fixtures/vcr_cassettes/1.8.6/not_the_real_response.yml +43 -0
- data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette1.yml +43 -0
- data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette2.yml +45 -0
- data/features/fixtures/vcr_cassettes/1.8.7/nested_replay_cassette.yml +23 -0
- data/features/fixtures/vcr_cassettes/1.8.7/not_the_real_response.yml +43 -0
- data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette1.yml +43 -0
- data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette2.yml +61 -0
- data/features/fixtures/vcr_cassettes/1.9.1/nested_replay_cassette.yml +31 -0
- data/features/fixtures/vcr_cassettes/1.9.1/not_the_real_response.yml +43 -0
- data/features/record_response.feature +55 -0
- data/features/replay_recorded_response.feature +53 -0
- data/features/step_definitions/vcr_steps.rb +88 -0
- data/features/support/env.rb +55 -0
- data/lib/vcr.rb +48 -0
- data/lib/vcr/cassette.rb +89 -0
- data/lib/vcr/config.rb +19 -0
- data/lib/vcr/cucumber_tags.rb +38 -0
- data/lib/vcr/fake_web_extensions.rb +18 -0
- data/lib/vcr/net_http_extensions.rb +39 -0
- data/lib/vcr/recorded_response.rb +4 -0
- data/spec/cassette_spec.rb +185 -0
- data/spec/config_spec.rb +27 -0
- data/spec/cucumber_tags_spec.rb +71 -0
- data/spec/fake_web_extensions_spec.rb +26 -0
- data/spec/fixtures/1.8.6/cassette_spec/example.yml +78 -0
- data/spec/fixtures/1.8.7/cassette_spec/example.yml +78 -0
- data/spec/fixtures/1.9.1/cassette_spec/example.yml +77 -0
- data/spec/net_http_extensions_spec.rb +40 -0
- data/spec/recorded_response_spec.rb +25 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/temp_cache_dir.rb +16 -0
- data/spec/vcr_spec.rb +95 -0
- metadata +154 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::RecordedResponse
|
3
|
+
method: :get
|
4
|
+
uri: http://example.com:80/before_nested
|
5
|
+
response: !ruby/object:Net::HTTPNotFound
|
6
|
+
body: The before_nested response
|
7
|
+
body_exist: true
|
8
|
+
code: "404"
|
9
|
+
header:
|
10
|
+
content-type:
|
11
|
+
- text/html; charset=iso-8859-1
|
12
|
+
connection:
|
13
|
+
- close
|
14
|
+
server:
|
15
|
+
- Apache/2.2.3 (CentOS)
|
16
|
+
date:
|
17
|
+
- Thu, 25 Feb 2010 15:23:39 GMT
|
18
|
+
content-length:
|
19
|
+
- "287"
|
20
|
+
http_version: "1.1"
|
21
|
+
message: Not Found
|
22
|
+
read: true
|
23
|
+
socket:
|
24
|
+
- !ruby/struct:VCR::RecordedResponse
|
25
|
+
method: :get
|
26
|
+
uri: http://example.com:80/after_nested
|
27
|
+
response: !ruby/object:Net::HTTPNotFound
|
28
|
+
body: The after_nested response
|
29
|
+
body_exist: true
|
30
|
+
code: "404"
|
31
|
+
header:
|
32
|
+
content-type:
|
33
|
+
- text/html; charset=iso-8859-1
|
34
|
+
connection:
|
35
|
+
- close
|
36
|
+
server:
|
37
|
+
- Apache/2.2.3 (CentOS)
|
38
|
+
date:
|
39
|
+
- Thu, 25 Feb 2010 15:23:39 GMT
|
40
|
+
content-length:
|
41
|
+
- "286"
|
42
|
+
http_version: "1.1"
|
43
|
+
message: Not Found
|
44
|
+
read: true
|
45
|
+
socket:
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::RecordedResponse
|
3
|
+
method: :get
|
4
|
+
uri: http://example.com:80/nested
|
5
|
+
response: !ruby/object:Net::HTTPNotFound
|
6
|
+
body: The nested response
|
7
|
+
body_exist: true
|
8
|
+
code: "404"
|
9
|
+
header:
|
10
|
+
content-type:
|
11
|
+
- text/html; charset=iso-8859-1
|
12
|
+
connection:
|
13
|
+
- close
|
14
|
+
server:
|
15
|
+
- Apache/2.2.3 (CentOS)
|
16
|
+
date:
|
17
|
+
- Thu, 25 Feb 2010 15:19:40 GMT
|
18
|
+
content-length:
|
19
|
+
- "280"
|
20
|
+
http_version: "1.1"
|
21
|
+
message: Not Found
|
22
|
+
read: true
|
23
|
+
socket:
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::RecordedResponse
|
3
|
+
method: :get
|
4
|
+
uri: http://example.com:80/
|
5
|
+
response: !ruby/object:Net::HTTPOK
|
6
|
+
body: |
|
7
|
+
<HTML>
|
8
|
+
<HEAD>
|
9
|
+
<TITLE>Example Web Page</TITLE>
|
10
|
+
</HEAD>
|
11
|
+
<body>
|
12
|
+
<p>
|
13
|
+
This is not the real response from example.com
|
14
|
+
</p>
|
15
|
+
</BODY>
|
16
|
+
</HTML>
|
17
|
+
|
18
|
+
|
19
|
+
body_exist: true
|
20
|
+
code: "200"
|
21
|
+
header:
|
22
|
+
etag:
|
23
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
24
|
+
last-modified:
|
25
|
+
- Tue, 15 Nov 2005 13:24:10 GMT
|
26
|
+
connection:
|
27
|
+
- Keep-Alive
|
28
|
+
content-type:
|
29
|
+
- text/html; charset=UTF-8
|
30
|
+
date:
|
31
|
+
- Thu, 25 Feb 2010 15:20:47 GMT
|
32
|
+
server:
|
33
|
+
- Apache/2.2.3 (CentOS)
|
34
|
+
content-length:
|
35
|
+
- "438"
|
36
|
+
age:
|
37
|
+
- "2546"
|
38
|
+
accept-ranges:
|
39
|
+
- bytes
|
40
|
+
http_version: "1.1"
|
41
|
+
message: OK
|
42
|
+
read: true
|
43
|
+
socket:
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::RecordedResponse
|
3
|
+
:method: :get
|
4
|
+
:uri: http://example.com:80/
|
5
|
+
:response: !ruby/object:Net::HTTPOK
|
6
|
+
body: |
|
7
|
+
<HTML>
|
8
|
+
<HEAD>
|
9
|
+
<TITLE>Example Web Page</TITLE>
|
10
|
+
</HEAD>
|
11
|
+
<body>
|
12
|
+
<p>
|
13
|
+
This is not the real response from example.com
|
14
|
+
</p>
|
15
|
+
</BODY>
|
16
|
+
</HTML>
|
17
|
+
|
18
|
+
|
19
|
+
body_exist: true
|
20
|
+
code: "200"
|
21
|
+
header:
|
22
|
+
server:
|
23
|
+
- Apache/2.2.3 (Red Hat)
|
24
|
+
last-modified:
|
25
|
+
- Tue, 15 Nov 2005 13:24:10 GMT
|
26
|
+
etag:
|
27
|
+
- "\"b300b4-1b6-4059a80bfd280\""
|
28
|
+
accept-ranges:
|
29
|
+
- bytes
|
30
|
+
content-type:
|
31
|
+
- text/html; charset=UTF-8
|
32
|
+
connection:
|
33
|
+
- Keep-Alive
|
34
|
+
date:
|
35
|
+
- Thu, 28 Jan 2010 07:14:48 GMT
|
36
|
+
age:
|
37
|
+
- "1696"
|
38
|
+
content-length:
|
39
|
+
- "438"
|
40
|
+
http_version: "1.1"
|
41
|
+
message: OK
|
42
|
+
read: true
|
43
|
+
socket:
|
@@ -0,0 +1,61 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::RecordedResponse
|
3
|
+
:method: :get
|
4
|
+
:uri: http://example.com:80/before_nested
|
5
|
+
:response: !ruby/object:Net::HTTPOK
|
6
|
+
body: The before_nested response
|
7
|
+
body_exist: true
|
8
|
+
code: "200"
|
9
|
+
header:
|
10
|
+
server:
|
11
|
+
- Apache/2.2.3 (Red Hat)
|
12
|
+
last-modified:
|
13
|
+
- Tue, 15 Nov 2005 13:24:10 GMT
|
14
|
+
etag:
|
15
|
+
- "\"b300b4-1b6-4059a80bfd280\""
|
16
|
+
accept-ranges:
|
17
|
+
- bytes
|
18
|
+
content-type:
|
19
|
+
- text/html; charset=UTF-8
|
20
|
+
connection:
|
21
|
+
- Keep-Alive
|
22
|
+
date:
|
23
|
+
- Thu, 28 Jan 2010 07:14:48 GMT
|
24
|
+
age:
|
25
|
+
- "1696"
|
26
|
+
content-length:
|
27
|
+
- "438"
|
28
|
+
http_version: "1.1"
|
29
|
+
message: OK
|
30
|
+
read: true
|
31
|
+
socket:
|
32
|
+
- !ruby/struct:VCR::RecordedResponse
|
33
|
+
:method: :get
|
34
|
+
:uri: http://example.com:80/after_nested
|
35
|
+
:response: !ruby/object:Net::HTTPOK
|
36
|
+
body: The after_nested response
|
37
|
+
body_exist: true
|
38
|
+
code: "200"
|
39
|
+
header:
|
40
|
+
server:
|
41
|
+
- Apache/2.2.3 (Red Hat)
|
42
|
+
last-modified:
|
43
|
+
- Tue, 15 Nov 2005 13:24:10 GMT
|
44
|
+
etag:
|
45
|
+
- "\"b300b4-1b6-4059a80bfd280\""
|
46
|
+
accept-ranges:
|
47
|
+
- bytes
|
48
|
+
content-type:
|
49
|
+
- text/html; charset=UTF-8
|
50
|
+
connection:
|
51
|
+
- Keep-Alive
|
52
|
+
date:
|
53
|
+
- Thu, 28 Jan 2010 07:14:48 GMT
|
54
|
+
age:
|
55
|
+
- "1696"
|
56
|
+
content-length:
|
57
|
+
- "438"
|
58
|
+
http_version: "1.1"
|
59
|
+
message: OK
|
60
|
+
read: true
|
61
|
+
socket:
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::RecordedResponse
|
3
|
+
:method: :get
|
4
|
+
:uri: http://example.com:80/nested
|
5
|
+
:response: !ruby/object:Net::HTTPOK
|
6
|
+
body: The nested response
|
7
|
+
body_exist: true
|
8
|
+
code: "200"
|
9
|
+
header:
|
10
|
+
server:
|
11
|
+
- Apache/2.2.3 (Red Hat)
|
12
|
+
last-modified:
|
13
|
+
- Tue, 15 Nov 2005 13:24:10 GMT
|
14
|
+
etag:
|
15
|
+
- "\"b300b4-1b6-4059a80bfd280\""
|
16
|
+
accept-ranges:
|
17
|
+
- bytes
|
18
|
+
content-type:
|
19
|
+
- text/html; charset=UTF-8
|
20
|
+
connection:
|
21
|
+
- Keep-Alive
|
22
|
+
date:
|
23
|
+
- Thu, 28 Jan 2010 07:14:48 GMT
|
24
|
+
age:
|
25
|
+
- "1696"
|
26
|
+
content-length:
|
27
|
+
- "438"
|
28
|
+
http_version: "1.1"
|
29
|
+
message: OK
|
30
|
+
read: true
|
31
|
+
socket:
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::RecordedResponse
|
3
|
+
:method: :get
|
4
|
+
:uri: http://example.com:80/
|
5
|
+
:response: !ruby/object:Net::HTTPOK
|
6
|
+
body: |
|
7
|
+
<HTML>
|
8
|
+
<HEAD>
|
9
|
+
<TITLE>Example Web Page</TITLE>
|
10
|
+
</HEAD>
|
11
|
+
<body>
|
12
|
+
<p>
|
13
|
+
This is not the real response from example.com
|
14
|
+
</p>
|
15
|
+
</BODY>
|
16
|
+
</HTML>
|
17
|
+
|
18
|
+
|
19
|
+
body_exist: true
|
20
|
+
code: "200"
|
21
|
+
header:
|
22
|
+
server:
|
23
|
+
- Apache/2.2.3 (Red Hat)
|
24
|
+
last-modified:
|
25
|
+
- Tue, 15 Nov 2005 13:24:10 GMT
|
26
|
+
etag:
|
27
|
+
- "\"b300b4-1b6-4059a80bfd280\""
|
28
|
+
accept-ranges:
|
29
|
+
- bytes
|
30
|
+
content-type:
|
31
|
+
- text/html; charset=UTF-8
|
32
|
+
connection:
|
33
|
+
- Keep-Alive
|
34
|
+
date:
|
35
|
+
- Thu, 28 Jan 2010 07:14:48 GMT
|
36
|
+
age:
|
37
|
+
- "1696"
|
38
|
+
content-length:
|
39
|
+
- "438"
|
40
|
+
http_version: "1.1"
|
41
|
+
message: OK
|
42
|
+
read: true
|
43
|
+
socket:
|
@@ -0,0 +1,55 @@
|
|
1
|
+
Feature: Record response
|
2
|
+
In order to have deterministic, fast tests that do not depend on an internet connection
|
3
|
+
As a TDD/BDD developer
|
4
|
+
I want to record responses for requests to URIs that are not registered with fakeweb so I can use them with fakeweb in the future
|
5
|
+
|
6
|
+
Scenario: Record a response using VCR.with_cassette
|
7
|
+
Given we do not have a "temp/cassette" cassette
|
8
|
+
When I make an HTTP get request to "http://example.com" within the "temp/cassette" cassette
|
9
|
+
Then the "temp/cassette" cache file should have a response for "http://example.com" that matches /You have reached this web page by typing.*example\.com/
|
10
|
+
|
11
|
+
@record_cassette1
|
12
|
+
Scenario: Record a response using a tagged scenario
|
13
|
+
Given we do not have a "cucumber_tags/record_cassette1" cassette
|
14
|
+
And this scenario is tagged with the vcr cassette tag: "@record_cassette1"
|
15
|
+
When I make an HTTP get request to "http://example.com"
|
16
|
+
Then I can test the scenario cassette's recorded responses in the next scenario, after the cassette has been destroyed
|
17
|
+
|
18
|
+
Scenario: Check the recorded response for the previous scenario
|
19
|
+
Given the previous scenario was tagged with the vcr cassette tag: "@record_cassette1"
|
20
|
+
Then the "cucumber_tags/record_cassette1" cache file should have a response for "http://example.com" that matches /You have reached this web page by typing.*example\.com/
|
21
|
+
|
22
|
+
@record_cassette2
|
23
|
+
Scenario: Use both a tagged scenario cassette and a nested cassette within a single step definition
|
24
|
+
Given we do not have a "cucumber_tags/record_cassette2" cassette
|
25
|
+
And we do not have a "temp/nested" cassette
|
26
|
+
And this scenario is tagged with the vcr cassette tag: "@record_cassette2"
|
27
|
+
When I make an HTTP get request to "http://example.com/before_nested"
|
28
|
+
And I make an HTTP get request to "http://example.com/nested" within the "temp/nested" cassette
|
29
|
+
And I make an HTTP get request to "http://example.com/after_nested"
|
30
|
+
Then I can test the scenario cassette's recorded responses in the next scenario, after the cassette has been destroyed
|
31
|
+
And the "temp/nested" cache file should have a response for "http://example.com/nested" that matches /The requested URL \/nested was not found/
|
32
|
+
|
33
|
+
Scenario: Check the recorded response for the previous scenario
|
34
|
+
Given the previous scenario was tagged with the vcr cassette tag: "@record_cassette2"
|
35
|
+
Then the "cucumber_tags/record_cassette2" cache file should have a response for "http://example.com/before_nested" that matches /The requested URL \/before_nested was not found/
|
36
|
+
And the "cucumber_tags/record_cassette2" cache file should have a response for "http://example.com/after_nested" that matches /The requested URL \/after_nested was not found/
|
37
|
+
|
38
|
+
Scenario: Make an HTTP request in a cassette with record mode set to :all
|
39
|
+
Given we do not have a "temp/record_all_cassette" cassette
|
40
|
+
When I make an HTTP get request to "http://example.com" within the "temp/record_all_cassette" all cassette
|
41
|
+
Then the "temp/record_all_cassette" cache file should have a response for "http://example.com" that matches /You have reached this web page by typing.*example\.com/
|
42
|
+
|
43
|
+
Scenario: Make an HTTP request in a cassette with record mode set to :none
|
44
|
+
Given we do not have a "temp/record_none_cassette" cassette
|
45
|
+
When I make an HTTP get request to "http://example.com" within the "temp/record_none_cassette" none cassette
|
46
|
+
Then the HTTP get request to "http://example.com" should result in a fakeweb error
|
47
|
+
And there should not be a "temp/record_none_cassette" cache file
|
48
|
+
|
49
|
+
@copy_not_the_real_response_to_temp
|
50
|
+
Scenario: Make an HTTP request in a cassette with record mode set to :unregistered
|
51
|
+
Given we have a "temp/not_the_real_response" file with a previously recorded response for "http://example.com"
|
52
|
+
And we have a "temp/not_the_real_response" file with no previously recorded response for "http://example.com/foo"
|
53
|
+
When I make HTTP get requests to "http://example.com" and "http://example.com/foo" within the "temp/not_the_real_response" unregistered cassette
|
54
|
+
Then the "temp/not_the_real_response" cache file should have a response for "http://example.com" that matches /This is not the real response from example\.com/
|
55
|
+
And the "temp/not_the_real_response" cache file should have a response for "http://example.com/foo" that matches /The requested URL \/foo was not found/
|
@@ -0,0 +1,53 @@
|
|
1
|
+
Feature: Replay recorded response
|
2
|
+
In order to have deterministic, fast tests that do not depend on an internet connection
|
3
|
+
As a TDD/BDD developer
|
4
|
+
I want to replay responses for requests I have previously recorded
|
5
|
+
|
6
|
+
Scenario: Replay recorded response for a request in a VCR.with_cassette block
|
7
|
+
Given the "not_the_real_response" cache file has a response for "http://example.com" that matches /This is not the real response from example\.com/
|
8
|
+
When I make an HTTP get request to "http://example.com" within the "not_the_real_response" cassette
|
9
|
+
Then the response for "http://example.com" should match /This is not the real response from example\.com/
|
10
|
+
|
11
|
+
@replay_cassette1
|
12
|
+
Scenario: Replay recorded response for a request within a tagged scenario
|
13
|
+
Given this scenario is tagged with the vcr cassette tag: "@replay_cassette1"
|
14
|
+
And the "cucumber_tags/replay_cassette1" cache file has a response for "http://example.com" that matches /This is not the real response from example\.com/
|
15
|
+
When I make an HTTP get request to "http://example.com"
|
16
|
+
Then the response for "http://example.com" should match /This is not the real response from example\.com/
|
17
|
+
|
18
|
+
@replay_cassette2
|
19
|
+
Scenario: Use both a tagged scenario cassette and a nested cassette within a single step definition
|
20
|
+
Given this scenario is tagged with the vcr cassette tag: "@replay_cassette2"
|
21
|
+
And the "cucumber_tags/replay_cassette2" cache file has a response for "http://example.com/before_nested" that matches /The before_nested response/
|
22
|
+
And the "nested_replay_cassette" cache file has a response for "http://example.com/nested" that matches /The nested response/
|
23
|
+
And the "cucumber_tags/replay_cassette2" cache file has a response for "http://example.com/after_nested" that matches /The after_nested response/
|
24
|
+
When I make an HTTP get request to "http://example.com/before_nested"
|
25
|
+
And I make an HTTP get request to "http://example.com/nested" within the "nested_replay_cassette" cassette
|
26
|
+
And I make an HTTP get request to "http://example.com/after_nested"
|
27
|
+
Then the response for "http://example.com/before_nested" should match /The before_nested response/
|
28
|
+
And the response for "http://example.com/nested" should match /The nested response/
|
29
|
+
And the response for "http://example.com/after_nested" should match /The after_nested response/
|
30
|
+
|
31
|
+
@copy_not_the_real_response_to_temp
|
32
|
+
Scenario: Make an HTTP request in a cassette with record mode set to :all
|
33
|
+
Given we have a "temp/not_the_real_response" file with a previously recorded response for "http://example.com"
|
34
|
+
And we have a "temp/not_the_real_response" file with no previously recorded response for "http://example.com/foo"
|
35
|
+
When I make HTTP get requests to "http://example.com" and "http://example.com/foo" within the "temp/not_the_real_response" all cassette
|
36
|
+
Then the response for "http://example.com" should match /You have reached this web page by typing.*example\.com/
|
37
|
+
And the response for "http://example.com/foo" should match /The requested URL \/foo was not found/
|
38
|
+
|
39
|
+
@copy_not_the_real_response_to_temp
|
40
|
+
Scenario: Make an HTTP request in a cassette with record mode set to :none
|
41
|
+
Given we have a "temp/not_the_real_response" file with a previously recorded response for "http://example.com"
|
42
|
+
And we have a "temp/not_the_real_response" file with no previously recorded response for "http://example.com/foo"
|
43
|
+
When I make HTTP get requests to "http://example.com" and "http://example.com/foo" within the "temp/not_the_real_response" none cassette
|
44
|
+
Then the response for "http://example.com" should match /This is not the real response from example\.com/
|
45
|
+
And the HTTP get request to "http://example.com/foo" should result in a fakeweb error
|
46
|
+
|
47
|
+
@copy_not_the_real_response_to_temp
|
48
|
+
Scenario: Make an HTTP request in a cassette with record mode set to :unregistered
|
49
|
+
Given we have a "temp/not_the_real_response" file with a previously recorded response for "http://example.com"
|
50
|
+
And we have a "temp/not_the_real_response" file with no previously recorded response for "http://example.com/foo"
|
51
|
+
When I make HTTP get requests to "http://example.com" and "http://example.com/foo" within the "temp/not_the_real_response" unregistered cassette
|
52
|
+
Then the response for "http://example.com" should match /This is not the real response from example\.com/
|
53
|
+
And the response for "http://example.com/foo" should match /The requested URL \/foo was not found/
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
|
3
|
+
module VCRHelpers
|
4
|
+
def have_expected_response(url, regex_str)
|
5
|
+
simple_matcher("a response from #{url} that matches /#{regex_str}/") do |responses|
|
6
|
+
regex = /#{regex_str}/i
|
7
|
+
response = responses.detect { |r| URI.parse(r.uri) == URI.parse(url) }
|
8
|
+
response.should_not be_nil
|
9
|
+
response.response.body.should =~ regex
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
World(VCRHelpers)
|
14
|
+
|
15
|
+
Given /^we do not have a "([^\"]*)" cassette$/ do |cassette_name|
|
16
|
+
fixture_file = File.join(VCR::Config.cache_dir, "#{cassette_name}.yml")
|
17
|
+
File.exist?(fixture_file).should be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
Given /^we have a "([^\"]*)" file with (a|no) previously recorded response for "([^\"]*)"$/ do |file_name, a_or_no, url|
|
21
|
+
fixture_file = File.join(VCR::Config.cache_dir, "#{file_name}.yml")
|
22
|
+
File.exist?(fixture_file).should be_true
|
23
|
+
responses = File.open(fixture_file, 'r') { |f| YAML.load(f.read) }
|
24
|
+
should_method = a_or_no == 'a' ? :should : :should_not
|
25
|
+
responses.map{ |r| URI.parse(r.uri) }.send(should_method, include(URI.parse(url)))
|
26
|
+
end
|
27
|
+
|
28
|
+
Given /^the "([^\"]*)" cache file has a response for "([^\"]*)" that matches \/(.+)\/$/ do |cassette_name, url, regex_str|
|
29
|
+
Given %{we have a "#{cassette_name}" file with a previously recorded response for "#{url}"}
|
30
|
+
Then %{the "#{cassette_name}" cache file should have a response for "#{url}" that matches /#{regex_str}/}
|
31
|
+
end
|
32
|
+
|
33
|
+
Given /^this scenario is tagged with the vcr cassette tag: "([^\"]+)"$/ do |tag|
|
34
|
+
VCR.current_cucumber_scenario.should be_tagged_with(tag)
|
35
|
+
VCR::CucumberTags.tags.should include(tag)
|
36
|
+
end
|
37
|
+
|
38
|
+
Given /^the previous scenario was tagged with the vcr cassette tag: "([^\"]*)"$/ do |tag|
|
39
|
+
last_scenario = VCR.completed_cucumber_scenarios.last
|
40
|
+
last_scenario.should_not be_nil
|
41
|
+
last_scenario.should be_tagged_with(tag)
|
42
|
+
VCR::CucumberTags.tags.should include(tag)
|
43
|
+
end
|
44
|
+
|
45
|
+
When /^I make an HTTP get request to "([^\"]*)"$/ do |url|
|
46
|
+
@http_requests ||= {}
|
47
|
+
begin
|
48
|
+
result = Net::HTTP.get_response(URI.parse(url))
|
49
|
+
rescue => e
|
50
|
+
result = e
|
51
|
+
end
|
52
|
+
@http_requests[url] = result
|
53
|
+
end
|
54
|
+
|
55
|
+
When /^I make (?:an )?HTTP get requests? to "([^\"]*)"(?: and "([^\"]*)")? within the "([^\"]*)" ?(#{VCR::Cassette::VALID_RECORD_MODES.join('|')})? cassette$/ do |url1, url2, cassette_name, record_mode|
|
56
|
+
record_mode ||= :unregistered
|
57
|
+
record_mode = record_mode.to_sym
|
58
|
+
urls = [url1, url2].select { |u| u.to_s.size > 0 }
|
59
|
+
VCR.with_cassette(cassette_name, :record => record_mode) do
|
60
|
+
urls.each do |url|
|
61
|
+
When %{I make an HTTP get request to "#{url}"}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
Then /^the "([^\"]*)" cache file should have a response for "([^\"]*)" that matches \/(.+)\/$/ do |cassette_name, url, regex_str|
|
67
|
+
yaml_file = File.join(VCR::Config.cache_dir, "#{cassette_name}.yml")
|
68
|
+
responses = File.open(yaml_file, 'r') { |f| YAML.load(f.read) }
|
69
|
+
responses.should have_expected_response(url, regex_str)
|
70
|
+
end
|
71
|
+
|
72
|
+
Then /^I can test the scenario cassette's recorded responses in the next scenario, after the cassette has been destroyed$/ do
|
73
|
+
# do nothing...
|
74
|
+
end
|
75
|
+
|
76
|
+
Then /^the HTTP get request to "([^\"]*)" should result in a fakeweb error$/ do |url|
|
77
|
+
@http_requests[url].should be_instance_of(FakeWeb::NetConnectNotAllowedError)
|
78
|
+
end
|
79
|
+
|
80
|
+
Then /^the response for "([^\"]*)" should match \/(.+)\/$/ do |url, regex_str|
|
81
|
+
regex = /#{regex_str}/i
|
82
|
+
@http_requests[url].body.should =~ regex
|
83
|
+
end
|
84
|
+
|
85
|
+
Then /^there should not be a "([^\"]*)" cache file$/ do |cassette_name|
|
86
|
+
yaml_file = File.join(VCR::Config.cache_dir, "#{cassette_name}.yml")
|
87
|
+
File.exist?(yaml_file).should be_false
|
88
|
+
end
|