vcr 2.9.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/features/about_these_examples.md +1 -1
- data/features/cassettes/automatic_re_recording.feature +4 -4
- data/features/cassettes/decompress.feature +3 -3
- data/features/cassettes/exclusive.feature +11 -8
- data/features/cassettes/format.feature +135 -32
- data/features/cassettes/naming.feature +2 -2
- data/features/cassettes/no_cassette.feature +4 -4
- data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -3
- data/features/configuration/cassette_library_dir.feature +2 -2
- data/features/configuration/debug_logging.feature +15 -8
- data/features/configuration/filter_sensitive_data.feature +8 -7
- data/features/configuration/hook_into.feature +8 -8
- data/features/configuration/ignore_request.feature +13 -14
- data/features/configuration/preserve_exact_body_bytes.feature +5 -5
- data/features/configuration/uri_parser.feature +15 -11
- data/features/hooks/after_http_request.feature +5 -4
- data/features/hooks/around_http_request.feature +3 -3
- data/features/hooks/before_http_request.feature +4 -2
- data/features/hooks/before_playback.feature +14 -15
- data/features/hooks/before_record.feature +10 -10
- data/features/http_libraries/em_http_request.feature +6 -3
- data/features/http_libraries/net_http.feature +15 -5
- data/features/middleware/faraday.feature +2 -2
- data/features/middleware/rack.feature +4 -4
- data/features/record_modes/all.feature +5 -5
- data/features/record_modes/new_episodes.feature +2 -2
- data/features/record_modes/once.feature +3 -3
- data/features/step_definitions/cli_steps.rb +37 -39
- data/features/support/env.rb +29 -26
- data/features/support/http_lib_filters.rb +0 -7
- data/features/test_frameworks/cucumber.feature +11 -10
- data/features/test_frameworks/rspec_macro.feature +5 -30
- data/features/test_frameworks/rspec_metadata.feature +9 -8
- data/features/test_frameworks/test_unit.feature +5 -2
- data/lib/vcr.rb +86 -14
- data/lib/vcr/cassette.rb +4 -2
- data/lib/vcr/cassette/serializers.rb +10 -8
- data/lib/vcr/cassette/serializers/compressed.rb +45 -0
- data/lib/vcr/configuration.rb +38 -17
- data/lib/vcr/library_hooks/fakeweb.rb +1 -0
- data/lib/vcr/library_hooks/faraday.rb +5 -1
- data/lib/vcr/middleware/faraday.rb +13 -9
- data/lib/vcr/test_frameworks/cucumber.rb +39 -5
- data/lib/vcr/version.rb +1 -1
- data/spec/acceptance/concurrency_spec.rb +51 -0
- data/spec/{vcr → lib/vcr}/cassette/erb_renderer_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/cassette/http_interaction_list_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/cassette/migrator_spec.rb +10 -9
- data/spec/{vcr → lib/vcr}/cassette/persisters/file_system_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/cassette/persisters_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/cassette/serializers_spec.rb +8 -2
- data/spec/{vcr → lib/vcr}/cassette_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/configuration_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/deprecations_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/errors_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/extensions/net_http_response_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/excon_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/fakeweb_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/faraday_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/typhoeus_0.4_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/typhoeus_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/webmock_spec.rb +2 -2
- data/spec/{vcr → lib/vcr}/library_hooks_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/middleware/faraday_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/middleware/rack_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/request_ignorer_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/request_matcher_registry_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/structs_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/test_frameworks/cucumber_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/test_frameworks/rspec_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/util/hooks_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/util/internet_connection_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/util/version_checker_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/version_spec.rb +0 -0
- data/spec/{vcr_spec.rb → lib/vcr_spec.rb} +2 -2
- data/spec/spec_helper.rb +21 -50
- data/spec/support/cucumber_helpers.rb +39 -0
- data/spec/support/limited_uri.rb +1 -11
- data/spec/support/shared_example_groups/hook_into_http_library.rb +2 -1
- data/spec/support/vcr_localhost_server.rb +2 -3
- metadata +475 -123
- data/.gemtest +0 -0
- data/.gitignore +0 -52
- data/.gitmodules +0 -3
- data/.rspec +0 -2
- data/.travis.yml +0 -27
- data/.yardopts +0 -9
- data/Appraisals +0 -5
- data/CHANGELOG.md +0 -987
- data/CONTRIBUTING.md +0 -26
- data/Gemfile +0 -54
- data/Gemfile.lock +0 -159
- data/LICENSE +0 -20
- data/README.md +0 -243
- data/Rakefile +0 -197
- data/Upgrade.md +0 -289
- data/benchmarks/http_stubbing_libraries.rb +0 -59
- data/benchmarks/null_logging.rb +0 -62
- data/cucumber.yml +0 -16
- data/features/.nav +0 -62
- data/features/cassettes/persistence.feature +0 -63
- data/features/support/vcr_cucumber_helpers.rb +0 -46
- data/gemfiles/typhoeus_old.gemfile +0 -34
- data/gemfiles/typhoeus_old.gemfile.lock +0 -133
- data/script/ci.sh +0 -27
- data/spec/capture_warnings.rb +0 -73
- data/spec/quality_spec.rb +0 -51
- data/vcr.gemspec +0 -23
|
@@ -26,7 +26,7 @@ Feature: before_record hook
|
|
|
26
26
|
Scenario: Modify recorded response
|
|
27
27
|
Given a file named "before_record_example.rb" with:
|
|
28
28
|
"""ruby
|
|
29
|
-
|
|
29
|
+
$server = start_sinatra_app do
|
|
30
30
|
get('/') { "Hello Earth" }
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -42,7 +42,7 @@ Feature: before_record hook
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
VCR.use_cassette('recording_example') do
|
|
45
|
-
Net::HTTP.get_response('localhost', '/',
|
|
45
|
+
Net::HTTP.get_response('localhost', '/', $server.port)
|
|
46
46
|
end
|
|
47
47
|
"""
|
|
48
48
|
When I run `ruby before_record_example.rb`
|
|
@@ -52,7 +52,7 @@ Feature: before_record hook
|
|
|
52
52
|
Scenario: Modify recorded response based on the cassette
|
|
53
53
|
Given a file named "before_record_example.rb" with:
|
|
54
54
|
"""ruby
|
|
55
|
-
|
|
55
|
+
$server = start_sinatra_app do
|
|
56
56
|
get('/') { "Hello Earth" }
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -68,7 +68,7 @@ Feature: before_record hook
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
VCR.use_cassette('recording_example') do
|
|
71
|
-
Net::HTTP.get_response('localhost', '/',
|
|
71
|
+
Net::HTTP.get_response('localhost', '/', $server.port)
|
|
72
72
|
end
|
|
73
73
|
"""
|
|
74
74
|
When I run `ruby before_record_example.rb`
|
|
@@ -77,7 +77,7 @@ Feature: before_record hook
|
|
|
77
77
|
Scenario: Prevent recording by ignoring interaction in before_record hook
|
|
78
78
|
Given a file named "before_record_ignore.rb" with:
|
|
79
79
|
"""ruby
|
|
80
|
-
|
|
80
|
+
$server = start_sinatra_app do
|
|
81
81
|
get('/') { "Hello World" }
|
|
82
82
|
end
|
|
83
83
|
|
|
@@ -90,7 +90,7 @@ Feature: before_record hook
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
VCR.use_cassette('recording_example') do
|
|
93
|
-
response = Net::HTTP.get_response('localhost', '/',
|
|
93
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
|
94
94
|
puts "Response: #{response.body}"
|
|
95
95
|
end
|
|
96
96
|
"""
|
|
@@ -101,7 +101,7 @@ Feature: before_record hook
|
|
|
101
101
|
Scenario: Multiple hooks are run in order
|
|
102
102
|
Given a file named "multiple_hooks.rb" with:
|
|
103
103
|
"""ruby
|
|
104
|
-
|
|
104
|
+
$server = start_sinatra_app do
|
|
105
105
|
get('/') { "Hello World" }
|
|
106
106
|
end
|
|
107
107
|
|
|
@@ -116,7 +116,7 @@ Feature: before_record hook
|
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
VCR.use_cassette('example', :record => :new_episodes) do
|
|
119
|
-
response = Net::HTTP.get_response('localhost', '/',
|
|
119
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
|
120
120
|
puts "Response: #{response.body}"
|
|
121
121
|
end
|
|
122
122
|
"""
|
|
@@ -131,7 +131,7 @@ Feature: before_record hook
|
|
|
131
131
|
Scenario: Use tagging to apply hook to only certain cassettes
|
|
132
132
|
Given a file named "tagged_hooks.rb" with:
|
|
133
133
|
"""ruby
|
|
134
|
-
|
|
134
|
+
$server = start_sinatra_app do
|
|
135
135
|
get('/') { "Hello World" }
|
|
136
136
|
end
|
|
137
137
|
|
|
@@ -151,7 +151,7 @@ Feature: before_record hook
|
|
|
151
151
|
puts "Using tag: #{tag.inspect}"
|
|
152
152
|
|
|
153
153
|
VCR.use_cassette('example', :record => :new_episodes, :tag => tag) do
|
|
154
|
-
response = Net::HTTP.get_response('localhost', '/',
|
|
154
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
|
155
155
|
puts "Response: #{response.body}"
|
|
156
156
|
end
|
|
157
157
|
end
|
|
@@ -10,7 +10,7 @@ Feature: EM HTTP Request
|
|
|
10
10
|
"""ruby
|
|
11
11
|
require 'em-http-request'
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
$server = start_sinatra_app do
|
|
14
14
|
%w[ foo bar bazz ].each_with_index do |path, index|
|
|
15
15
|
get "/#{path}" do
|
|
16
16
|
sleep index * 0.1 # ensure the async callbacks are invoked in order
|
|
@@ -24,6 +24,9 @@ Feature: EM HTTP Request
|
|
|
24
24
|
VCR.configure do |c|
|
|
25
25
|
c.hook_into :webmock
|
|
26
26
|
c.cassette_library_dir = 'cassettes'
|
|
27
|
+
c.before_record do |i|
|
|
28
|
+
i.request.uri.sub!(/:\d+/, ':7777')
|
|
29
|
+
end
|
|
27
30
|
end
|
|
28
31
|
"""
|
|
29
32
|
|
|
@@ -35,7 +38,7 @@ Feature: EM HTTP Request
|
|
|
35
38
|
VCR.use_cassette('em_http') do
|
|
36
39
|
EventMachine.run do
|
|
37
40
|
http_array = %w[ foo bar bazz ].map do |p|
|
|
38
|
-
EventMachine::HttpRequest.new("http://localhost
|
|
41
|
+
EventMachine::HttpRequest.new("http://localhost:#{$server.port}/#{p}").get
|
|
39
42
|
end
|
|
40
43
|
|
|
41
44
|
http_array.each do |http|
|
|
@@ -145,7 +148,7 @@ Feature: EM HTTP Request
|
|
|
145
148
|
multi = EventMachine::MultiRequest.new
|
|
146
149
|
|
|
147
150
|
%w[ foo bar bazz ].each do |path|
|
|
148
|
-
multi.add(path, EventMachine::HttpRequest.new("http://localhost
|
|
151
|
+
multi.add(path, EventMachine::HttpRequest.new("http://localhost:#{$server.port}/#{path}").get)
|
|
149
152
|
end
|
|
150
153
|
|
|
151
154
|
multi.callback do
|
|
@@ -7,14 +7,24 @@ Feature: Net::HTTP
|
|
|
7
7
|
Background:
|
|
8
8
|
Given a file named "vcr_setup.rb" with:
|
|
9
9
|
"""ruby
|
|
10
|
+
require 'ostruct'
|
|
11
|
+
|
|
10
12
|
if ARGV[0] == '--with-server'
|
|
11
|
-
|
|
13
|
+
$server = start_sinatra_app do
|
|
12
14
|
get('/') { 'VCR works with Net::HTTP gets!' }
|
|
13
15
|
post('/') { 'VCR works with Net::HTTP posts!' }
|
|
14
16
|
end
|
|
17
|
+
else
|
|
18
|
+
$server = OpenStruct(:port => 0)
|
|
15
19
|
end
|
|
16
20
|
|
|
17
21
|
require 'vcr'
|
|
22
|
+
|
|
23
|
+
VCR.configure do |c|
|
|
24
|
+
c.default_cassette_options = {
|
|
25
|
+
:match_requests_on => [:method, :host, :path]
|
|
26
|
+
}
|
|
27
|
+
end
|
|
18
28
|
"""
|
|
19
29
|
|
|
20
30
|
Scenario Outline: Calling #post on new Net::HTTP instance
|
|
@@ -28,7 +38,7 @@ Feature: Net::HTTP
|
|
|
28
38
|
end
|
|
29
39
|
|
|
30
40
|
VCR.use_cassette('net_http') do
|
|
31
|
-
puts Net::HTTP.new('localhost',
|
|
41
|
+
puts Net::HTTP.new('localhost', $server.port).post('/', '').body
|
|
32
42
|
end
|
|
33
43
|
"""
|
|
34
44
|
When I run `ruby vcr_net_http.rb --with-server`
|
|
@@ -54,7 +64,7 @@ Feature: Net::HTTP
|
|
|
54
64
|
end
|
|
55
65
|
|
|
56
66
|
def perform_request
|
|
57
|
-
Net::HTTP.new('localhost',
|
|
67
|
+
Net::HTTP.new('localhost', $server.port).request(Net::HTTP::Get.new('/', {})) do |response|
|
|
58
68
|
return response
|
|
59
69
|
end
|
|
60
70
|
end
|
|
@@ -88,7 +98,7 @@ Feature: Net::HTTP
|
|
|
88
98
|
VCR.use_cassette('net_http') do
|
|
89
99
|
body = ''
|
|
90
100
|
|
|
91
|
-
Net::HTTP.new('localhost',
|
|
101
|
+
Net::HTTP.new('localhost', $server.port).request_get('/') do |response|
|
|
92
102
|
response.read_body { |frag| body << frag }
|
|
93
103
|
end
|
|
94
104
|
|
|
@@ -119,7 +129,7 @@ Feature: Net::HTTP
|
|
|
119
129
|
end
|
|
120
130
|
|
|
121
131
|
VCR.use_cassette('net_http') do
|
|
122
|
-
puts open(
|
|
132
|
+
puts open("http://localhost:#{$server.port}/").read
|
|
123
133
|
end
|
|
124
134
|
"""
|
|
125
135
|
When I run `ruby vcr_net_http.rb --with-server`
|
|
@@ -15,7 +15,7 @@ Feature: Faraday middleware
|
|
|
15
15
|
Given a file named "faraday_example.rb" with:
|
|
16
16
|
"""ruby
|
|
17
17
|
request_count = 0
|
|
18
|
-
|
|
18
|
+
$server = start_sinatra_app do
|
|
19
19
|
get('/:path') { "Hello #{params[:path]} #{request_count += 1}" }
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -28,7 +28,7 @@ Feature: Faraday middleware
|
|
|
28
28
|
c.cassette_library_dir = 'cassettes'
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
conn = Faraday::Connection.new(:url =>
|
|
31
|
+
conn = Faraday::Connection.new(:url => "http://localhost:#{$server.port}") do |builder|
|
|
32
32
|
builder.use VCR::Middleware::Faraday
|
|
33
33
|
builder.adapter :<adapter>
|
|
34
34
|
end
|
|
@@ -18,7 +18,7 @@ Feature: Rack
|
|
|
18
18
|
Given a file named "remote_server.rb" with:
|
|
19
19
|
"""ruby
|
|
20
20
|
request_count = 0
|
|
21
|
-
|
|
21
|
+
$server = start_sinatra_app do
|
|
22
22
|
get('/:path') { "Hello #{params[:path]} #{request_count += 1}" }
|
|
23
23
|
end
|
|
24
24
|
"""
|
|
@@ -28,7 +28,7 @@ Feature: Rack
|
|
|
28
28
|
require 'proxy_server'
|
|
29
29
|
require 'cgi'
|
|
30
30
|
|
|
31
|
-
url = URI.parse("http://localhost
|
|
31
|
+
url = URI.parse("http://localhost:#{$proxy.port}?url=#{CGI.escape("http://localhost:#{$server.port}/foo")}")
|
|
32
32
|
|
|
33
33
|
puts "Response 1: #{Net::HTTP.get_response(url).body}"
|
|
34
34
|
puts "Response 2: #{Net::HTTP.get_response(url).body}"
|
|
@@ -40,7 +40,7 @@ Feature: Rack
|
|
|
40
40
|
"""ruby
|
|
41
41
|
require 'vcr'
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
$proxy = start_sinatra_app do
|
|
44
44
|
use VCR::Middleware::Rack do |cassette|
|
|
45
45
|
cassette.name 'proxied'
|
|
46
46
|
cassette.options :record => :new_episodes
|
|
@@ -68,7 +68,7 @@ Feature: Rack
|
|
|
68
68
|
"""ruby
|
|
69
69
|
require 'vcr'
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
$proxy = start_sinatra_app do
|
|
72
72
|
use VCR::Middleware::Rack do |cassette, env|
|
|
73
73
|
cassette.name env['SERVER_NAME']
|
|
74
74
|
end
|
|
@@ -12,7 +12,7 @@ Feature: :all
|
|
|
12
12
|
Background:
|
|
13
13
|
Given a file named "setup.rb" with:
|
|
14
14
|
"""ruby
|
|
15
|
-
|
|
15
|
+
$server = start_sinatra_app do
|
|
16
16
|
get('/') { 'Hello' }
|
|
17
17
|
get('/foo') { 'Goodbye' }
|
|
18
18
|
end
|
|
@@ -30,7 +30,7 @@ Feature: :all
|
|
|
30
30
|
http_interactions:
|
|
31
31
|
- request:
|
|
32
32
|
method: get
|
|
33
|
-
uri: http://localhost
|
|
33
|
+
uri: http://localhost/
|
|
34
34
|
body:
|
|
35
35
|
encoding: UTF-8
|
|
36
36
|
string: ""
|
|
@@ -55,8 +55,8 @@ Feature: :all
|
|
|
55
55
|
"""ruby
|
|
56
56
|
require 'setup'
|
|
57
57
|
|
|
58
|
-
VCR.use_cassette('example', :record => :all) do
|
|
59
|
-
response = Net::HTTP.get_response('localhost', '/',
|
|
58
|
+
VCR.use_cassette('example', :record => :all, :match_requests_on => [:method, :host, :path]) do
|
|
59
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
|
60
60
|
puts "Response: #{response.body}"
|
|
61
61
|
end
|
|
62
62
|
"""
|
|
@@ -71,7 +71,7 @@ Feature: :all
|
|
|
71
71
|
require 'setup'
|
|
72
72
|
|
|
73
73
|
VCR.use_cassette('example', :record => :all) do
|
|
74
|
-
response = Net::HTTP.get_response('localhost', '/foo',
|
|
74
|
+
response = Net::HTTP.get_response('localhost', '/foo', $server.port)
|
|
75
75
|
puts "Response: #{response.body}"
|
|
76
76
|
end
|
|
77
77
|
"""
|
|
@@ -12,7 +12,7 @@ Feature: :new_episodes
|
|
|
12
12
|
Background:
|
|
13
13
|
Given a file named "setup.rb" with:
|
|
14
14
|
"""ruby
|
|
15
|
-
|
|
15
|
+
$server = start_sinatra_app do
|
|
16
16
|
get('/') { 'Hello' }
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -68,7 +68,7 @@ Feature: :new_episodes
|
|
|
68
68
|
require 'setup'
|
|
69
69
|
|
|
70
70
|
VCR.use_cassette('example', :record => :new_episodes) do
|
|
71
|
-
response = Net::HTTP.get_response('localhost', '/',
|
|
71
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
|
72
72
|
puts "Response: #{response.body}"
|
|
73
73
|
end
|
|
74
74
|
"""
|
|
@@ -15,7 +15,7 @@ Feature: :once
|
|
|
15
15
|
Background:
|
|
16
16
|
Given a file named "setup.rb" with:
|
|
17
17
|
"""ruby
|
|
18
|
-
|
|
18
|
+
$server = start_sinatra_app do
|
|
19
19
|
get('/') { 'Hello' }
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -72,7 +72,7 @@ Feature: :once
|
|
|
72
72
|
require 'setup'
|
|
73
73
|
|
|
74
74
|
VCR.use_cassette('example', :record => :once) do
|
|
75
|
-
response = Net::HTTP.get_response('localhost', '/',
|
|
75
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
|
76
76
|
puts "Response: #{response.body}"
|
|
77
77
|
end
|
|
78
78
|
"""
|
|
@@ -85,7 +85,7 @@ Feature: :once
|
|
|
85
85
|
require 'setup'
|
|
86
86
|
|
|
87
87
|
VCR.use_cassette('example', :record => :once) do
|
|
88
|
-
response = Net::HTTP.get_response('localhost', '/',
|
|
88
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
|
89
89
|
puts "Response: #{response.body}"
|
|
90
90
|
end
|
|
91
91
|
"""
|
|
@@ -68,63 +68,60 @@ module VCRHelpers
|
|
|
68
68
|
in_current_dir do
|
|
69
69
|
file = File.read(file_name)
|
|
70
70
|
regex = /#{Regexp.escape(orig_text)}/
|
|
71
|
-
file.
|
|
71
|
+
expect(file).to match(regex)
|
|
72
72
|
|
|
73
73
|
file = file.gsub(regex, new_text)
|
|
74
74
|
File.open(file_name, 'w') { |f| f.write(file) }
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
|
-
|
|
78
|
-
def redis
|
|
79
|
-
@redis ||= begin
|
|
80
|
-
require 'redis'
|
|
81
|
-
Redis.connect
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
77
|
end
|
|
85
78
|
World(VCRHelpers)
|
|
86
79
|
|
|
87
|
-
Given
|
|
80
|
+
Given(/the following files do not exist:/) do |files|
|
|
88
81
|
check_file_presence(files.raw.map{|file_row| file_row[0]}, false)
|
|
89
82
|
end
|
|
90
83
|
|
|
91
|
-
Given
|
|
84
|
+
Given(/^the directory "([^"]*)" does not exist$/) do |dir|
|
|
92
85
|
check_directory_presence([dir], false)
|
|
93
86
|
end
|
|
94
87
|
|
|
95
|
-
Given
|
|
88
|
+
Given(/^a previously recorded cassette file "([^"]*)" with:$/) do |file_name, content|
|
|
96
89
|
write_file(file_name, normalize_cassette_content(content))
|
|
97
90
|
end
|
|
98
91
|
|
|
99
|
-
Given
|
|
92
|
+
Given(/^it is (.*)$/) do |date_string|
|
|
100
93
|
set_env('DATE_STRING', date_string)
|
|
101
94
|
end
|
|
102
95
|
|
|
103
|
-
Given
|
|
104
|
-
|
|
96
|
+
Given(/^that port numbers in "([^"]*)" are normalized to "([^"]*)"$/) do |file_name, port|
|
|
97
|
+
in_current_dir do
|
|
98
|
+
contents = File.read(file_name)
|
|
99
|
+
contents = contents.gsub(/:\d{2,}\//, ":#{port}/")
|
|
100
|
+
File.open(file_name, 'w') { |f| f.write(contents) }
|
|
101
|
+
end
|
|
105
102
|
end
|
|
106
103
|
|
|
107
|
-
When
|
|
104
|
+
When(/^I modify the file "([^"]*)" to replace "([^"]*)" with "([^"]*)"$/) do |file_name, orig_text, new_text|
|
|
108
105
|
modify_file(file_name, orig_text, new_text)
|
|
109
106
|
end
|
|
110
107
|
|
|
111
|
-
When
|
|
108
|
+
When(/^I append to file "([^"]*)":$/) do |file_name, content|
|
|
112
109
|
append_to_file(file_name, "\n" + content)
|
|
113
110
|
end
|
|
114
111
|
|
|
115
|
-
When
|
|
112
|
+
When(/^I set the "([^"]*)" environment variable to "([^"]*)"$/) do |var, value|
|
|
116
113
|
set_env(var, value)
|
|
117
114
|
end
|
|
118
115
|
|
|
119
|
-
Then
|
|
116
|
+
Then(/^the file "([^"]*)" should exist$/) do |file_name|
|
|
120
117
|
check_file_presence([file_name], true)
|
|
121
118
|
end
|
|
122
119
|
|
|
123
|
-
Then
|
|
120
|
+
Then(/^it should (pass|fail) with "([^"]*)"$/) do |pass_fail, partial_output|
|
|
124
121
|
assert_exit_status_and_partial_output(pass_fail == 'pass', partial_output)
|
|
125
122
|
end
|
|
126
123
|
|
|
127
|
-
Then
|
|
124
|
+
Then(/^it should (pass|fail) with an error like:$/) do |pass_fail, partial_output|
|
|
128
125
|
assert_success(pass_fail == 'pass')
|
|
129
126
|
|
|
130
127
|
# different implementations place the exception class at different
|
|
@@ -138,38 +135,44 @@ Then /^it should (pass|fail) with an error like:$/ do |pass_fail, partial_output
|
|
|
138
135
|
assert_partial_output(partial_output, process_output)
|
|
139
136
|
end
|
|
140
137
|
|
|
141
|
-
Then
|
|
138
|
+
Then(/^the output should contain each of the following:$/) do |table|
|
|
142
139
|
table.raw.flatten.each do |string|
|
|
143
140
|
assert_partial_output(string, all_output)
|
|
144
141
|
end
|
|
145
142
|
end
|
|
146
143
|
|
|
147
|
-
Then
|
|
144
|
+
Then(/^the file "([^"]*)" should contain YAML like:$/) do |file_name, expected_content|
|
|
148
145
|
actual_content = in_current_dir { File.read(file_name) }
|
|
149
|
-
normalize_cassette_hash(YAML.load(actual_content)).
|
|
146
|
+
expect(normalize_cassette_hash(YAML.load(actual_content))).to eq(normalize_cassette_hash(YAML.load(expected_content)))
|
|
150
147
|
end
|
|
151
148
|
|
|
152
|
-
Then
|
|
149
|
+
Then(/^the file "([^"]*)" should contain JSON like:$/) do |file_name, expected_content|
|
|
153
150
|
actual_content = in_current_dir { File.read(file_name) }
|
|
154
151
|
actual = MultiJson.decode(actual_content)
|
|
155
|
-
expected = MultiJson.decode(expected_content)
|
|
156
|
-
normalize_cassette_hash(actual).
|
|
152
|
+
expected = MultiJson.decode(expected_content.to_s)
|
|
153
|
+
expect(normalize_cassette_hash(actual)).to eq(normalize_cassette_hash(expected))
|
|
157
154
|
end
|
|
158
155
|
|
|
159
|
-
Then
|
|
156
|
+
Then(/^the file "([^"]*)" should contain compressed YAML like:$/) do |file_name, expected_content|
|
|
157
|
+
actual_content = in_current_dir { File.read(file_name) }
|
|
158
|
+
unzipped_content = Zlib.inflate(actual_content)
|
|
159
|
+
expect(normalize_cassette_hash(YAML.load(unzipped_content))).to eq(normalize_cassette_hash(YAML.load(expected_content)))
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
Then(/^the file "([^"]*)" should contain ruby like:$/) do |file_name, expected_content|
|
|
160
163
|
actual_content = in_current_dir { File.read(file_name) }
|
|
161
164
|
actual = eval(actual_content)
|
|
162
165
|
expected = eval(expected_content)
|
|
163
|
-
normalize_cassette_hash(actual).
|
|
166
|
+
expect(normalize_cassette_hash(actual)).to eq(normalize_cassette_hash(expected))
|
|
164
167
|
end
|
|
165
168
|
|
|
166
|
-
Then
|
|
169
|
+
Then(/^the file "([^"]*)" should contain each of these:$/) do |file_name, table|
|
|
167
170
|
table.raw.flatten.each do |string|
|
|
168
171
|
check_file_content(file_name, string, true)
|
|
169
172
|
end
|
|
170
173
|
end
|
|
171
174
|
|
|
172
|
-
Then
|
|
175
|
+
Then(/^the file "([^"]*)" should contain a YAML fragment like:$/) do |file_name, fragment|
|
|
173
176
|
in_current_dir do
|
|
174
177
|
file_content = File.read(file_name)
|
|
175
178
|
|
|
@@ -180,22 +183,17 @@ Then /^the file "([^"]*)" should contain a YAML fragment like:$/ do |file_name,
|
|
|
180
183
|
line.strip.gsub('"', "'").gsub("'", '')
|
|
181
184
|
end.join("\n")
|
|
182
185
|
|
|
183
|
-
file_content.
|
|
186
|
+
expect(file_content).to include(fragment.gsub("'", ''))
|
|
184
187
|
end
|
|
185
188
|
end
|
|
186
189
|
|
|
187
|
-
Then
|
|
190
|
+
Then(/^the cassette "([^"]*)" should have the following response bodies:$/) do |file, table|
|
|
188
191
|
interactions = in_current_dir { YAML.load_file(file) }['http_interactions'].map { |h| VCR::HTTPInteraction.from_hash(h) }
|
|
189
192
|
actual_response_bodies = interactions.map { |i| i.response.body }
|
|
190
193
|
expected_response_bodies = table.raw.flatten
|
|
191
|
-
actual_response_bodies.
|
|
194
|
+
expect(actual_response_bodies).to match(expected_response_bodies)
|
|
192
195
|
end
|
|
193
196
|
|
|
194
|
-
Then
|
|
195
|
-
redis.get(key).should include(value_fragment)
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
Then /^it should (pass|fail)$/ do |pass_fail|
|
|
197
|
+
Then(/^it should (pass|fail)$/) do |pass_fail|
|
|
199
198
|
assert_success(pass_fail == 'pass')
|
|
200
199
|
end
|
|
201
|
-
|