mustwin-vcr 2.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/features/about_these_examples.md +18 -0
- data/features/cassettes/allow_unused_http_interactions.feature +100 -0
- data/features/cassettes/automatic_re_recording.feature +72 -0
- data/features/cassettes/decompress.feature +74 -0
- data/features/cassettes/dynamic_erb.feature +100 -0
- data/features/cassettes/exclusive.feature +126 -0
- data/features/cassettes/format.feature +323 -0
- data/features/cassettes/freezing_time.feature +68 -0
- data/features/cassettes/naming.feature +28 -0
- data/features/cassettes/no_cassette.feature +152 -0
- data/features/cassettes/update_content_length_header.feature +112 -0
- data/features/configuration/allow_http_connections_when_no_cassette.feature +55 -0
- data/features/configuration/cassette_library_dir.feature +31 -0
- data/features/configuration/debug_logging.feature +59 -0
- data/features/configuration/default_cassette_options.feature +100 -0
- data/features/configuration/filter_sensitive_data.feature +153 -0
- data/features/configuration/hook_into.feature +172 -0
- data/features/configuration/ignore_request.feature +192 -0
- data/features/configuration/preserve_exact_body_bytes.feature +108 -0
- data/features/configuration/query_parser.feature +84 -0
- data/features/configuration/uri_parser.feature +89 -0
- data/features/getting_started.md +82 -0
- data/features/hooks/after_http_request.feature +58 -0
- data/features/hooks/around_http_request.feature +57 -0
- data/features/hooks/before_http_request.feature +63 -0
- data/features/hooks/before_playback.feature +184 -0
- data/features/hooks/before_record.feature +172 -0
- data/features/http_libraries/em_http_request.feature +250 -0
- data/features/http_libraries/net_http.feature +179 -0
- data/features/middleware/faraday.feature +56 -0
- data/features/middleware/rack.feature +92 -0
- data/features/record_modes/all.feature +82 -0
- data/features/record_modes/new_episodes.feature +79 -0
- data/features/record_modes/none.feature +72 -0
- data/features/record_modes/once.feature +95 -0
- data/features/request_matching/README.md +30 -0
- data/features/request_matching/body.feature +91 -0
- data/features/request_matching/body_as_json.feature +90 -0
- data/features/request_matching/custom_matcher.feature +135 -0
- data/features/request_matching/headers.feature +85 -0
- data/features/request_matching/host.feature +95 -0
- data/features/request_matching/identical_request_sequence.feature +89 -0
- data/features/request_matching/method.feature +96 -0
- data/features/request_matching/path.feature +96 -0
- data/features/request_matching/playback_repeats.feature +98 -0
- data/features/request_matching/query.feature +97 -0
- data/features/request_matching/uri.feature +94 -0
- data/features/request_matching/uri_without_param.feature +101 -0
- data/features/step_definitions/cli_steps.rb +193 -0
- data/features/support/env.rb +44 -0
- data/features/support/http_lib_filters.rb +53 -0
- data/features/test_frameworks/cucumber.feature +211 -0
- data/features/test_frameworks/rspec_macro.feature +81 -0
- data/features/test_frameworks/rspec_metadata.feature +150 -0
- data/features/test_frameworks/test_unit.feature +49 -0
- data/lib/vcr.rb +347 -0
- data/lib/vcr/cassette.rb +291 -0
- data/lib/vcr/cassette/erb_renderer.rb +55 -0
- data/lib/vcr/cassette/http_interaction_list.rb +108 -0
- data/lib/vcr/cassette/migrator.rb +118 -0
- data/lib/vcr/cassette/persisters.rb +42 -0
- data/lib/vcr/cassette/persisters/file_system.rb +64 -0
- data/lib/vcr/cassette/serializers.rb +57 -0
- data/lib/vcr/cassette/serializers/json.rb +48 -0
- data/lib/vcr/cassette/serializers/psych.rb +48 -0
- data/lib/vcr/cassette/serializers/syck.rb +61 -0
- data/lib/vcr/cassette/serializers/yaml.rb +50 -0
- data/lib/vcr/configuration.rb +555 -0
- data/lib/vcr/deprecations.rb +109 -0
- data/lib/vcr/errors.rb +266 -0
- data/lib/vcr/extensions/net_http_response.rb +36 -0
- data/lib/vcr/library_hooks.rb +18 -0
- data/lib/vcr/library_hooks/excon.rb +27 -0
- data/lib/vcr/library_hooks/fakeweb.rb +196 -0
- data/lib/vcr/library_hooks/faraday.rb +51 -0
- data/lib/vcr/library_hooks/typhoeus.rb +120 -0
- data/lib/vcr/library_hooks/typhoeus_0.4.rb +103 -0
- data/lib/vcr/library_hooks/webmock.rb +164 -0
- data/lib/vcr/middleware/excon.rb +221 -0
- data/lib/vcr/middleware/excon/legacy_methods.rb +33 -0
- data/lib/vcr/middleware/faraday.rb +118 -0
- data/lib/vcr/middleware/rack.rb +79 -0
- data/lib/vcr/request_handler.rb +114 -0
- data/lib/vcr/request_ignorer.rb +43 -0
- data/lib/vcr/request_matcher_registry.rb +149 -0
- data/lib/vcr/structs.rb +578 -0
- data/lib/vcr/tasks/vcr.rake +9 -0
- data/lib/vcr/test_frameworks/cucumber.rb +64 -0
- data/lib/vcr/test_frameworks/rspec.rb +47 -0
- data/lib/vcr/util/hooks.rb +61 -0
- data/lib/vcr/util/internet_connection.rb +43 -0
- data/lib/vcr/util/logger.rb +59 -0
- data/lib/vcr/util/variable_args_block_caller.rb +13 -0
- data/lib/vcr/util/version_checker.rb +48 -0
- data/lib/vcr/version.rb +34 -0
- data/spec/acceptance/threading_spec.rb +34 -0
- data/spec/fixtures/cassette_spec/1_x_cassette.yml +110 -0
- data/spec/fixtures/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/cassette_spec/example.yml +111 -0
- data/spec/fixtures/cassette_spec/with_localhost_requests.yml +111 -0
- data/spec/fixtures/fake_example_responses.yml +110 -0
- data/spec/fixtures/match_requests_on.yml +187 -0
- data/spec/lib/vcr/cassette/erb_renderer_spec.rb +53 -0
- data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +295 -0
- data/spec/lib/vcr/cassette/migrator_spec.rb +195 -0
- data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +69 -0
- data/spec/lib/vcr/cassette/persisters_spec.rb +39 -0
- data/spec/lib/vcr/cassette/serializers_spec.rb +176 -0
- data/spec/lib/vcr/cassette_spec.rb +618 -0
- data/spec/lib/vcr/configuration_spec.rb +326 -0
- data/spec/lib/vcr/deprecations_spec.rb +85 -0
- data/spec/lib/vcr/errors_spec.rb +162 -0
- data/spec/lib/vcr/extensions/net_http_response_spec.rb +86 -0
- data/spec/lib/vcr/library_hooks/excon_spec.rb +104 -0
- data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +169 -0
- data/spec/lib/vcr/library_hooks/faraday_spec.rb +68 -0
- data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +36 -0
- data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +162 -0
- data/spec/lib/vcr/library_hooks/webmock_spec.rb +118 -0
- data/spec/lib/vcr/library_hooks_spec.rb +51 -0
- data/spec/lib/vcr/middleware/faraday_spec.rb +182 -0
- data/spec/lib/vcr/middleware/rack_spec.rb +115 -0
- data/spec/lib/vcr/request_ignorer_spec.rb +70 -0
- data/spec/lib/vcr/request_matcher_registry_spec.rb +345 -0
- data/spec/lib/vcr/structs_spec.rb +732 -0
- data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +107 -0
- data/spec/lib/vcr/test_frameworks/rspec_spec.rb +83 -0
- data/spec/lib/vcr/util/hooks_spec.rb +158 -0
- data/spec/lib/vcr/util/internet_connection_spec.rb +37 -0
- data/spec/lib/vcr/util/version_checker_spec.rb +31 -0
- data/spec/lib/vcr/version_spec.rb +27 -0
- data/spec/lib/vcr_spec.rb +349 -0
- data/spec/monkey_patches.rb +182 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/support/configuration_stubbing.rb +8 -0
- data/spec/support/cucumber_helpers.rb +35 -0
- data/spec/support/fixnum_extension.rb +10 -0
- data/spec/support/http_library_adapters.rb +289 -0
- data/spec/support/limited_uri.rb +21 -0
- data/spec/support/ruby_interpreter.rb +7 -0
- data/spec/support/shared_example_groups/excon.rb +63 -0
- data/spec/support/shared_example_groups/hook_into_http_library.rb +594 -0
- data/spec/support/shared_example_groups/request_hooks.rb +59 -0
- data/spec/support/sinatra_app.rb +86 -0
- data/spec/support/vcr_localhost_server.rb +76 -0
- data/spec/support/vcr_stub_helpers.rb +17 -0
- metadata +677 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
Feature: Matching on URI
|
2
|
+
|
3
|
+
Use the `:uri` request matcher to match requests on the request URI.
|
4
|
+
|
5
|
+
The `:uri` matcher is used (along with the `:method` matcher) by default
|
6
|
+
if you do not specify how requests should match.
|
7
|
+
|
8
|
+
Background:
|
9
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
10
|
+
"""
|
11
|
+
---
|
12
|
+
http_interactions:
|
13
|
+
- request:
|
14
|
+
method: post
|
15
|
+
uri: http://example.com/foo
|
16
|
+
body:
|
17
|
+
encoding: UTF-8
|
18
|
+
string: ""
|
19
|
+
headers: {}
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Content-Length:
|
26
|
+
- "12"
|
27
|
+
body:
|
28
|
+
encoding: UTF-8
|
29
|
+
string: foo response
|
30
|
+
http_version: "1.1"
|
31
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
32
|
+
- request:
|
33
|
+
method: post
|
34
|
+
uri: http://example.com/bar
|
35
|
+
body:
|
36
|
+
encoding: UTF-8
|
37
|
+
string: ""
|
38
|
+
headers: {}
|
39
|
+
response:
|
40
|
+
status:
|
41
|
+
code: 200
|
42
|
+
message: OK
|
43
|
+
headers:
|
44
|
+
Content-Length:
|
45
|
+
- "12"
|
46
|
+
body:
|
47
|
+
encoding: UTF-8
|
48
|
+
string: bar response
|
49
|
+
http_version: "1.1"
|
50
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
51
|
+
recorded_with: VCR 2.0.0
|
52
|
+
"""
|
53
|
+
|
54
|
+
Scenario Outline: Replay interaction that matches the request URI
|
55
|
+
And a file named "uri_matching.rb" with:
|
56
|
+
"""ruby
|
57
|
+
include_http_adapter_for("<http_lib>")
|
58
|
+
|
59
|
+
require 'vcr'
|
60
|
+
|
61
|
+
VCR.configure do |c|
|
62
|
+
<configuration>
|
63
|
+
c.cassette_library_dir = 'cassettes'
|
64
|
+
end
|
65
|
+
|
66
|
+
VCR.use_cassette('example', :match_requests_on => [:uri]) do
|
67
|
+
puts "Response for /bar: " + response_body_for(:get, "http://example.com/bar")
|
68
|
+
end
|
69
|
+
|
70
|
+
VCR.use_cassette('example', :match_requests_on => [:uri]) do
|
71
|
+
puts "Response for /foo: " + response_body_for(:get, "http://example.com/foo")
|
72
|
+
end
|
73
|
+
"""
|
74
|
+
When I run `ruby uri_matching.rb`
|
75
|
+
Then it should pass with:
|
76
|
+
"""
|
77
|
+
Response for /bar: bar response
|
78
|
+
Response for /foo: foo response
|
79
|
+
"""
|
80
|
+
|
81
|
+
Examples:
|
82
|
+
| configuration | http_lib |
|
83
|
+
| c.hook_into :fakeweb | net/http |
|
84
|
+
| c.hook_into :webmock | net/http |
|
85
|
+
| c.hook_into :webmock | httpclient |
|
86
|
+
| c.hook_into :webmock | curb |
|
87
|
+
| c.hook_into :webmock | patron |
|
88
|
+
| c.hook_into :webmock | em-http-request |
|
89
|
+
| c.hook_into :webmock | typhoeus |
|
90
|
+
| c.hook_into :typhoeus | typhoeus |
|
91
|
+
| c.hook_into :excon | excon |
|
92
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
93
|
+
| c.hook_into :faraday | faraday (w/ typhoeus) |
|
94
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
Feature: URI without param(s)
|
2
|
+
|
3
|
+
A common source of difficulty when using VCR with the default matchers
|
4
|
+
are non-deterministic URIs. If the URI changes on every test run (because
|
5
|
+
it includes a timestamp parameter, or whatever), the default URI matcher
|
6
|
+
will not work well for you.
|
7
|
+
|
8
|
+
You can write a custom matcher to match URIs however you want, but for the
|
9
|
+
common need to match on a URI and ignore particular query parameters, VCR
|
10
|
+
provides an easier way:
|
11
|
+
|
12
|
+
:match_requests_on => [
|
13
|
+
:method,
|
14
|
+
VCR.request_matchers.uri_without_param(:timestamp)
|
15
|
+
]
|
16
|
+
|
17
|
+
`uri_without_param` also has a plural alias (i.e. `uri_without_params(:timestamp, :session)`)
|
18
|
+
|
19
|
+
Background:
|
20
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
21
|
+
"""
|
22
|
+
---
|
23
|
+
http_interactions:
|
24
|
+
- request:
|
25
|
+
method: get
|
26
|
+
uri: http://example.com/search?q=foo×tamp=1316920490
|
27
|
+
body:
|
28
|
+
encoding: UTF-8
|
29
|
+
string: ""
|
30
|
+
headers: {}
|
31
|
+
response:
|
32
|
+
status:
|
33
|
+
code: 200
|
34
|
+
message: OK
|
35
|
+
headers:
|
36
|
+
Content-Length:
|
37
|
+
- "12"
|
38
|
+
body:
|
39
|
+
encoding: UTF-8
|
40
|
+
string: foo response
|
41
|
+
http_version: "1.1"
|
42
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
43
|
+
- request:
|
44
|
+
method: get
|
45
|
+
uri: http://example.com/search?q=bar×tamp=1296723437
|
46
|
+
body:
|
47
|
+
encoding: UTF-8
|
48
|
+
string: ""
|
49
|
+
headers: {}
|
50
|
+
response:
|
51
|
+
status:
|
52
|
+
code: 200
|
53
|
+
message: OK
|
54
|
+
headers:
|
55
|
+
Content-Length:
|
56
|
+
- "12"
|
57
|
+
body:
|
58
|
+
encoding: UTF-8
|
59
|
+
string: bar response
|
60
|
+
http_version: "1.1"
|
61
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
62
|
+
recorded_with: VCR 2.0.0
|
63
|
+
"""
|
64
|
+
|
65
|
+
Scenario: Match the URI on all but the timestamp query parameter
|
66
|
+
And a file named "uri_without_param_matcher.rb" with:
|
67
|
+
"""ruby
|
68
|
+
include_http_adapter_for("net/http")
|
69
|
+
|
70
|
+
require 'vcr'
|
71
|
+
|
72
|
+
VCR.configure do |c|
|
73
|
+
c.hook_into :webmock
|
74
|
+
c.cassette_library_dir = 'cassettes'
|
75
|
+
c.default_cassette_options = {
|
76
|
+
:match_requests_on => [:method,
|
77
|
+
VCR.request_matchers.uri_without_param(:timestamp)]
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def search_uri(q)
|
82
|
+
"http://example.com/search?q=#{q}×tamp=#{Time.now.to_i}"
|
83
|
+
end
|
84
|
+
|
85
|
+
VCR.use_cassette('example') do
|
86
|
+
puts "Response for bar: " +
|
87
|
+
response_body_for(:get, search_uri("bar"))
|
88
|
+
end
|
89
|
+
|
90
|
+
VCR.use_cassette('example') do
|
91
|
+
puts "Response for foo: " +
|
92
|
+
response_body_for(:get, search_uri("foo"))
|
93
|
+
end
|
94
|
+
"""
|
95
|
+
When I run `ruby uri_without_param_matcher.rb`
|
96
|
+
Then it should pass with:
|
97
|
+
"""
|
98
|
+
Response for bar: bar response
|
99
|
+
Response for foo: foo response
|
100
|
+
"""
|
101
|
+
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module VCRHelpers
|
5
|
+
|
6
|
+
def normalize_cassette_hash(cassette_hash)
|
7
|
+
cassette_hash['recorded_with'] = "VCR #{VCR.version}"
|
8
|
+
cassette_hash['http_interactions'].map! { |h| normalize_http_interaction(h) }
|
9
|
+
cassette_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
def normalize_headers(object)
|
13
|
+
object.headers = {} and return if object.headers.nil?
|
14
|
+
object.headers = {}.tap do |hash|
|
15
|
+
object.headers.each do |key, value|
|
16
|
+
hash[key.downcase] = value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def static_timestamp
|
22
|
+
@static_timestamp ||= Time.now
|
23
|
+
end
|
24
|
+
|
25
|
+
def normalize_http_interaction(hash)
|
26
|
+
VCR::HTTPInteraction.from_hash(hash).tap do |i|
|
27
|
+
normalize_headers(i.request)
|
28
|
+
normalize_headers(i.response)
|
29
|
+
|
30
|
+
i.recorded_at &&= static_timestamp
|
31
|
+
i.request.body ||= ''
|
32
|
+
i.response.body ||= ''
|
33
|
+
i.response.status.message ||= ''
|
34
|
+
i.response.adapter_metadata.clear
|
35
|
+
|
36
|
+
# Remove non-deterministic headers and headers
|
37
|
+
# that get added by a particular HTTP library (but not by others)
|
38
|
+
i.response.headers.reject! { |k, v| %w[ server date connection ].include?(k) }
|
39
|
+
i.request.headers.reject! { |k, v| %w[ accept user-agent connection expect date ].include?(k) }
|
40
|
+
|
41
|
+
# Some HTTP libraries include an extra space ("OK " instead of "OK")
|
42
|
+
i.response.status.message = i.response.status.message.strip
|
43
|
+
|
44
|
+
if @scenario_parameters.to_s =~ /excon|faraday/
|
45
|
+
# Excon/Faraday do not expose the status message or http version,
|
46
|
+
# so we have no way to record these attributes.
|
47
|
+
i.response.status.message = nil
|
48
|
+
i.response.http_version = nil
|
49
|
+
elsif @scenario_parameters.to_s.include?('webmock')
|
50
|
+
# WebMock does not expose the HTTP version so we have no way to record it
|
51
|
+
i.response.http_version = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def normalize_cassette_content(content)
|
57
|
+
return content unless @scenario_parameters.to_s.include?('patron')
|
58
|
+
cassette_hash = YAML.load(content)
|
59
|
+
cassette_hash['http_interactions'].map! do |hash|
|
60
|
+
VCR::HTTPInteraction.from_hash(hash).tap do |i|
|
61
|
+
i.request.headers = (i.request.headers || {}).merge!('Expect' => [''])
|
62
|
+
end.to_hash
|
63
|
+
end
|
64
|
+
YAML.dump(cassette_hash)
|
65
|
+
end
|
66
|
+
|
67
|
+
def modify_file(file_name, orig_text, new_text)
|
68
|
+
in_current_dir do
|
69
|
+
file = File.read(file_name)
|
70
|
+
regex = /#{Regexp.escape(orig_text)}/
|
71
|
+
file.should =~ regex
|
72
|
+
|
73
|
+
file = file.gsub(regex, new_text)
|
74
|
+
File.open(file_name, 'w') { |f| f.write(file) }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
World(VCRHelpers)
|
79
|
+
|
80
|
+
Given(/the following files do not exist:/) do |files|
|
81
|
+
check_file_presence(files.raw.map{|file_row| file_row[0]}, false)
|
82
|
+
end
|
83
|
+
|
84
|
+
Given(/^the directory "([^"]*)" does not exist$/) do |dir|
|
85
|
+
check_directory_presence([dir], false)
|
86
|
+
end
|
87
|
+
|
88
|
+
Given(/^a previously recorded cassette file "([^"]*)" with:$/) do |file_name, content|
|
89
|
+
write_file(file_name, normalize_cassette_content(content))
|
90
|
+
end
|
91
|
+
|
92
|
+
Given(/^it is (.*)$/) do |date_string|
|
93
|
+
set_env('DATE_STRING', date_string)
|
94
|
+
end
|
95
|
+
|
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
|
102
|
+
end
|
103
|
+
|
104
|
+
When(/^I modify the file "([^"]*)" to replace "([^"]*)" with "([^"]*)"$/) do |file_name, orig_text, new_text|
|
105
|
+
modify_file(file_name, orig_text, new_text)
|
106
|
+
end
|
107
|
+
|
108
|
+
When(/^I append to file "([^"]*)":$/) do |file_name, content|
|
109
|
+
append_to_file(file_name, "\n" + content)
|
110
|
+
end
|
111
|
+
|
112
|
+
When(/^I set the "([^"]*)" environment variable to "([^"]*)"$/) do |var, value|
|
113
|
+
set_env(var, value)
|
114
|
+
end
|
115
|
+
|
116
|
+
Then(/^the file "([^"]*)" should exist$/) do |file_name|
|
117
|
+
check_file_presence([file_name], true)
|
118
|
+
end
|
119
|
+
|
120
|
+
Then(/^it should (pass|fail) with "([^"]*)"$/) do |pass_fail, partial_output|
|
121
|
+
assert_exit_status_and_partial_output(pass_fail == 'pass', partial_output)
|
122
|
+
end
|
123
|
+
|
124
|
+
Then(/^it should (pass|fail) with an error like:$/) do |pass_fail, partial_output|
|
125
|
+
assert_success(pass_fail == 'pass')
|
126
|
+
|
127
|
+
# different implementations place the exception class at different
|
128
|
+
# places relative to the message (i.e. with a multiline error message)
|
129
|
+
process_output = all_output.gsub(/\s*\(VCR::Errors::\w+\)/, '')
|
130
|
+
|
131
|
+
# Some implementations include extra leading spaces, for some reason...
|
132
|
+
process_output.gsub!(/^\s*/, '')
|
133
|
+
partial_output.gsub!(/^\s*/, '')
|
134
|
+
|
135
|
+
assert_partial_output(partial_output, process_output)
|
136
|
+
end
|
137
|
+
|
138
|
+
Then(/^the output should contain each of the following:$/) do |table|
|
139
|
+
table.raw.flatten.each do |string|
|
140
|
+
assert_partial_output(string, all_output)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
Then(/^the file "([^"]*)" should contain YAML like:$/) do |file_name, expected_content|
|
145
|
+
actual_content = in_current_dir { File.read(file_name) }
|
146
|
+
normalize_cassette_hash(YAML.load(actual_content)).should == normalize_cassette_hash(YAML.load(expected_content))
|
147
|
+
end
|
148
|
+
|
149
|
+
Then(/^the file "([^"]*)" should contain JSON like:$/) do |file_name, expected_content|
|
150
|
+
actual_content = in_current_dir { File.read(file_name) }
|
151
|
+
actual = MultiJson.decode(actual_content)
|
152
|
+
expected = MultiJson.decode(expected_content)
|
153
|
+
normalize_cassette_hash(actual).should == normalize_cassette_hash(expected)
|
154
|
+
end
|
155
|
+
|
156
|
+
Then(/^the file "([^"]*)" should contain ruby like:$/) do |file_name, expected_content|
|
157
|
+
actual_content = in_current_dir { File.read(file_name) }
|
158
|
+
actual = eval(actual_content)
|
159
|
+
expected = eval(expected_content)
|
160
|
+
normalize_cassette_hash(actual).should == normalize_cassette_hash(expected)
|
161
|
+
end
|
162
|
+
|
163
|
+
Then(/^the file "([^"]*)" should contain each of these:$/) do |file_name, table|
|
164
|
+
table.raw.flatten.each do |string|
|
165
|
+
check_file_content(file_name, string, true)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
Then(/^the file "([^"]*)" should contain a YAML fragment like:$/) do |file_name, fragment|
|
170
|
+
in_current_dir do
|
171
|
+
file_content = File.read(file_name)
|
172
|
+
|
173
|
+
# Normalize by removing leading and trailing whitespace...
|
174
|
+
file_content = file_content.split("\n").map do |line|
|
175
|
+
# Different versions of psych use single vs. double quotes
|
176
|
+
# And then 2.1 sometimes adds quotes...
|
177
|
+
line.strip.gsub('"', "'").gsub("'", '')
|
178
|
+
end.join("\n")
|
179
|
+
|
180
|
+
file_content.should include(fragment.gsub("'", ''))
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
Then(/^the cassette "([^"]*)" should have the following response bodies:$/) do |file, table|
|
185
|
+
interactions = in_current_dir { YAML.load_file(file) }['http_interactions'].map { |h| VCR::HTTPInteraction.from_hash(h) }
|
186
|
+
actual_response_bodies = interactions.map { |i| i.response.body }
|
187
|
+
expected_response_bodies = table.raw.flatten
|
188
|
+
actual_response_bodies.should =~ expected_response_bodies
|
189
|
+
end
|
190
|
+
|
191
|
+
Then(/^it should (pass|fail)$/) do |pass_fail|
|
192
|
+
assert_success(pass_fail == 'pass')
|
193
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
|
5
|
+
|
6
|
+
require 'aruba/cucumber'
|
7
|
+
require 'aruba/jruby' if RUBY_PLATFORM == 'java'
|
8
|
+
|
9
|
+
gem_specs = Bundler.load.specs
|
10
|
+
load_paths = Dir.glob(gem_specs.map { |spec|
|
11
|
+
if spec.respond_to?(:lib_dirs_glob)
|
12
|
+
spec.lib_dirs_glob
|
13
|
+
else
|
14
|
+
spec.load_paths
|
15
|
+
end
|
16
|
+
}.flatten)
|
17
|
+
|
18
|
+
load_paths << File.expand_path("../../../spec", __FILE__)
|
19
|
+
rubyopt = "-rsupport/cucumber_helpers"
|
20
|
+
|
21
|
+
if RUBY_VERSION > '1.9'
|
22
|
+
load_paths.unshift(".")
|
23
|
+
rubyopt = "--disable-gems #{rubyopt}" if "ruby" == ruby_engine
|
24
|
+
end
|
25
|
+
|
26
|
+
Before do
|
27
|
+
@aruba_timeout_seconds = 30
|
28
|
+
if "jruby" == ruby_engine
|
29
|
+
@aruba_io_wait_seconds = 0.1
|
30
|
+
else
|
31
|
+
@aruba_io_wait_seconds = 0.02
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Before("~@with-bundler") do
|
36
|
+
set_env("RUBYLIB", load_paths.join(":"))
|
37
|
+
set_env("RUBYOPT", rubyopt)
|
38
|
+
end
|
39
|
+
|
40
|
+
Before("@with-bundler") do
|
41
|
+
set_env("RUBYLIB", ".:#{ENV["RUBYLIB"]}:#{load_paths.last}")
|
42
|
+
set_env("RUBYOPT", "#{ENV["RUBYOPT"]} -rsupport/cucumber_helpers")
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# make the values of the example row cells available as an array...
|
2
|
+
Cucumber::Ast::OutlineTable::ExampleRow.class_eval do
|
3
|
+
def cell_values
|
4
|
+
@cells.map { |c| c.value }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
if RUBY_VERSION == '1.8.7'
|
9
|
+
# We get timeouts on 1.8.7 w/ Patron for some reason.
|
10
|
+
UNSUPPORTED_HTTP_LIBS = %w[ patron ]
|
11
|
+
elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
12
|
+
# Patron is freezing up the cukes (as it does on 1.9.2)
|
13
|
+
|
14
|
+
# I'm not sure why em-http-request isn't working on rbx,
|
15
|
+
# but considering the fact that VCR works with all the other
|
16
|
+
# libs just fine and doesn't do anything for em-http-request,
|
17
|
+
# it's probably a bug in it or rbx...so ignore it, for now.
|
18
|
+
|
19
|
+
# I'm getting errors in the curb C extension in rbx.
|
20
|
+
|
21
|
+
# Faraday and Typhoeus should be buildable on rbx, but the travis build times out,
|
22
|
+
# so we skip them to speed up the build on travis.
|
23
|
+
UNSUPPORTED_HTTP_LIBS = %w[ patron em-http-request curb faraday typhoeus ]
|
24
|
+
elsif RUBY_PLATFORM == 'java'
|
25
|
+
# These gems have C extensions and can't install on JRuby.
|
26
|
+
c_dependent_libs = %w[ typhoeus patron curb em-http-request ]
|
27
|
+
|
28
|
+
# The latest version of httpclient seems to freeze up the cukes
|
29
|
+
# on JRuby. I'm not sure why, and there's little benefit to running
|
30
|
+
# them on JRuby...so we just skip them. Excon seems to have the same issue :(.
|
31
|
+
UNSUPPORTED_HTTP_LIBS = c_dependent_libs + %w[ httpclient excon ]
|
32
|
+
end
|
33
|
+
|
34
|
+
if defined?(UNSUPPORTED_HTTP_LIBS)
|
35
|
+
UNSUPPORTED_HTTP_LIB_REGEX = Regexp.union(*UNSUPPORTED_HTTP_LIBS)
|
36
|
+
|
37
|
+
# Filter out example rows that use libraries that are not supported on the current ruby interpreter
|
38
|
+
Around do |scenario, block|
|
39
|
+
unless scenario.respond_to?(:cell_values) && scenario.cell_values.any? { |v| v =~ UNSUPPORTED_HTTP_LIB_REGEX }
|
40
|
+
block.call
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Set a global based on the current stubbing lib so we can put special-case
|
46
|
+
# logic in our step definitions based on the http stubbing library.
|
47
|
+
Before do |scenario|
|
48
|
+
if scenario.respond_to?(:cell_values)
|
49
|
+
@scenario_parameters = scenario.cell_values
|
50
|
+
else
|
51
|
+
@scenario_parameters = nil
|
52
|
+
end
|
53
|
+
end
|