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,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VCR::CucumberTags do
|
4
|
+
subject { described_class.new(self) }
|
5
|
+
let(:before_blocks_for_tags) { {} }
|
6
|
+
let(:after_blocks_for_tags) { {} }
|
7
|
+
|
8
|
+
def scenario(name)
|
9
|
+
double(:name => name, :feature => double(:name => "My feature name\nThe preamble text is not included"), :failed? => false)
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:current_scenario) { scenario "My scenario name\nThe preamble text is not included" }
|
13
|
+
|
14
|
+
# define our own Before/After so we can test this in isolation from cucumber's implementation.
|
15
|
+
def Before(tag, &block)
|
16
|
+
before_blocks_for_tags[tag.sub('@', '')] = block
|
17
|
+
end
|
18
|
+
|
19
|
+
def After(tag, &block)
|
20
|
+
after_blocks_for_tags[tag.sub('@', '')] = block
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_tag(cassette_attribute, tag, expected_value, scenario=current_scenario)
|
24
|
+
expect(VCR.current_cassette).to be_nil
|
25
|
+
|
26
|
+
before_blocks_for_tags[tag].call(scenario)
|
27
|
+
expect(VCR.current_cassette.send(cassette_attribute)).to eq(expected_value)
|
28
|
+
after_blocks_for_tags[tag].call(scenario)
|
29
|
+
|
30
|
+
expect(VCR.current_cassette).to be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
%w(tags tag).each do |tag_method|
|
34
|
+
describe "##{tag_method}" do
|
35
|
+
it "creates a cucumber Around hook for each given tag so that the scenario runs with the cassette inserted" do
|
36
|
+
subject.send(tag_method, 'tag1', 'tag2')
|
37
|
+
|
38
|
+
test_tag(:name, 'tag1', 'cucumber_tags/tag1')
|
39
|
+
test_tag(:name, 'tag2', 'cucumber_tags/tag2')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "works with tags that start with an @" do
|
43
|
+
subject.send(tag_method, '@tag1', '@tag2')
|
44
|
+
|
45
|
+
test_tag(:name, 'tag1', 'cucumber_tags/tag1')
|
46
|
+
test_tag(:name, 'tag2', 'cucumber_tags/tag2')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "passes along the given options to the cassette" do
|
50
|
+
subject.send(tag_method, 'tag1', :record => :none)
|
51
|
+
subject.send(tag_method, 'tag2', :record => :new_episodes)
|
52
|
+
|
53
|
+
test_tag(:record_mode, 'tag1', :none)
|
54
|
+
test_tag(:record_mode, 'tag2', :new_episodes)
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with :use_scenario_name as an option' do
|
58
|
+
it "uses the scenario's name as the cassette name" do
|
59
|
+
subject.send(tag_method, 'tag1', :use_scenario_name => true)
|
60
|
+
|
61
|
+
test_tag(:name, 'tag1', 'My feature name/My scenario name')
|
62
|
+
end
|
63
|
+
|
64
|
+
it "makes a unique name for each element of scenario outline" do
|
65
|
+
subject.send(tag_method, 'tag1', :use_scenario_name => true)
|
66
|
+
|
67
|
+
scenario_with_outline = double(:name => "My row name", :failed? => false,
|
68
|
+
:scenario_outline => double(:feature => double(:name => "My feature name\nThe preamble text is not included"),
|
69
|
+
:name => "My scenario outline name"))
|
70
|
+
test_tag(:name, 'tag1', 'My feature name/My scenario outline name/My row name', scenario_with_outline)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not pass :use_scenario_name along the given options to the cassette' do
|
74
|
+
subject.send(tag_method, 'tag1', :use_scenario_name => true)
|
75
|
+
|
76
|
+
expect(VCR::Cassette).to receive(:new).with(anything, hash_not_including(:use_scenario_name))
|
77
|
+
before_blocks_for_tags['tag1'].call(current_scenario)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'does not modify the options passed to the cassette' do
|
81
|
+
original_options = { :use_scenario_name => true, :record => :none }
|
82
|
+
subject.send(tag_method, 'tag1', original_options)
|
83
|
+
before_blocks_for_tags['tag1'].call(current_scenario)
|
84
|
+
|
85
|
+
expect(original_options.size).to eq(2)
|
86
|
+
expect(original_options[:use_scenario_name]).to eq(true)
|
87
|
+
expect(original_options[:record]).to eq(:none)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "works properly when multiple scenarios use the tag" do
|
91
|
+
subject.send(tag_method, 'tag1', :use_scenario_name => true)
|
92
|
+
|
93
|
+
test_tag(:name, 'tag1', 'My feature name/Foo', scenario("Foo"))
|
94
|
+
test_tag(:name, 'tag1', 'My feature name/Bar', scenario("Bar"))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '.tags' do
|
101
|
+
it 'returns the list of cucumber tags' do
|
102
|
+
subject.tags 'tag1', 'tag2'
|
103
|
+
subject.tags 'tag3', 'tag4'
|
104
|
+
expect(described_class.tags[-4, 4]).to eq(%w(@tag1 @tag2 @tag3 @tag4))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
VCR.configuration.configure_rspec_metadata!
|
4
|
+
|
5
|
+
describe VCR::RSpec::Metadata, :skip_vcr_reset do
|
6
|
+
before(:all) { VCR.reset! }
|
7
|
+
after(:each) { VCR.reset! }
|
8
|
+
|
9
|
+
context 'an example group', :vcr do
|
10
|
+
context 'with a nested example group' do
|
11
|
+
it 'uses a cassette for any examples' do
|
12
|
+
expect(VCR.current_cassette.name.split('/')).to eq([
|
13
|
+
'VCR::RSpec::Metadata',
|
14
|
+
'an example group',
|
15
|
+
'with a nested example group',
|
16
|
+
'uses a cassette for any examples'
|
17
|
+
])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with the cassette name overridden at the example group level', :vcr => { :cassette_name => 'foo' } do
|
23
|
+
it 'overrides the cassette name for an example' do
|
24
|
+
expect(VCR.current_cassette.name).to eq('foo')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'overrides the cassette name for another example' do
|
28
|
+
expect(VCR.current_cassette.name).to eq('foo')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'allows the cassette name to be overriden', :vcr => { :cassette_name => 'foo' } do
|
33
|
+
expect(VCR.current_cassette.name).to eq('foo')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'allows the cassette options to be set', :vcr => { :match_requests_on => [:method] } do
|
37
|
+
expect(VCR.current_cassette.match_requests_on).to eq([:method])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe VCR::RSpec::Macros do
|
42
|
+
extend described_class
|
43
|
+
|
44
|
+
describe '#use_vcr_cassette' do
|
45
|
+
def self.perform_test(context_name, expected_cassette_name, *args, &block)
|
46
|
+
context context_name do
|
47
|
+
after(:each) do |example|
|
48
|
+
if example.metadata[:test_ejection]
|
49
|
+
expect(VCR.current_cassette).to be_nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
use_vcr_cassette(*args)
|
54
|
+
|
55
|
+
it 'ejects the cassette in an after hook', :test_ejection do
|
56
|
+
expect(VCR.current_cassette).to be_a(VCR::Cassette)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "creates a cassette named '#{expected_cassette_name}" do
|
60
|
+
expect(VCR.current_cassette.name).to eq(expected_cassette_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
module_eval(&block) if block
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
perform_test 'when called with an explicit name', 'explicit_name', 'explicit_name'
|
68
|
+
|
69
|
+
perform_test 'when called with an explicit name and some options', 'explicit_name', 'explicit_name', :match_requests_on => [:method, :host] do
|
70
|
+
it 'uses the provided cassette options' do
|
71
|
+
expect(VCR.current_cassette.match_requests_on).to eq([:method, :host])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
perform_test 'when called with nothing', 'VCR::RSpec::Macros/#use_vcr_cassette/when called with nothing'
|
76
|
+
|
77
|
+
perform_test 'when called with some options', 'VCR::RSpec::Macros/#use_vcr_cassette/when called with some options', :match_requests_on => [:method, :host] do
|
78
|
+
it 'uses the provided cassette options' do
|
79
|
+
expect(VCR.current_cassette.match_requests_on).to eq([:method, :host])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VCR::Hooks::FilteredHook do
|
4
|
+
describe "#conditionally_invoke" do
|
5
|
+
it 'invokes the hook' do
|
6
|
+
called = false
|
7
|
+
subject.hook = lambda { called = true }
|
8
|
+
subject.conditionally_invoke
|
9
|
+
expect(called).to be true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'forwards the given arguments to the hook' do
|
13
|
+
args = nil
|
14
|
+
subject.hook = lambda { |a, b| args = [a, b] }
|
15
|
+
subject.conditionally_invoke(3, 5)
|
16
|
+
expect(args).to eq([3, 5])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'forwards only as many arguments as the hook block accepts' do
|
20
|
+
args = nil
|
21
|
+
subject.hook = lambda { |a| args = [a] }
|
22
|
+
subject.conditionally_invoke(3, 5)
|
23
|
+
expect(args).to eq([3])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'does not invoke the hook if all of the filters return false' do
|
27
|
+
called = false
|
28
|
+
subject.hook = lambda { called = true }
|
29
|
+
subject.filters = lambda { false }
|
30
|
+
subject.conditionally_invoke
|
31
|
+
expect(called).to be false
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'does not invoke the hook if any of the filters returns false' do
|
35
|
+
called = false
|
36
|
+
subject.hook = lambda { called = true }
|
37
|
+
subject.filters = [lambda { false }, lambda { true }]
|
38
|
+
subject.conditionally_invoke
|
39
|
+
expect(called).to be false
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'forwards arguments to the filters' do
|
43
|
+
filter_args = nil
|
44
|
+
subject.filters = lambda { |a, b| filter_args = [a, b]; false }
|
45
|
+
subject.conditionally_invoke(3, 5)
|
46
|
+
expect(filter_args).to eq([3, 5])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'handles splat args properly' do
|
50
|
+
filter_args = nil
|
51
|
+
subject.filters = lambda { |*args| filter_args = args; false }
|
52
|
+
subject.conditionally_invoke(3, 5)
|
53
|
+
expect(filter_args).to eq([3, 5])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'forwards only as many arguments as the filter blocks accept' do
|
57
|
+
args1 = args2 = nil
|
58
|
+
subject.filters = [
|
59
|
+
lambda { |a| args1 = [a]; true },
|
60
|
+
lambda { |a, b| args2 = [a, b]; false }
|
61
|
+
]
|
62
|
+
|
63
|
+
subject.conditionally_invoke(3, 5)
|
64
|
+
expect(args1).to eq([3])
|
65
|
+
expect(args2).to eq([3, 5])
|
66
|
+
end
|
67
|
+
|
68
|
+
it '#to_procs the filter objects' do
|
69
|
+
filter_called = false
|
70
|
+
subject.hook = lambda { }
|
71
|
+
subject.filters = [double(:to_proc => lambda { filter_called = true })]
|
72
|
+
subject.conditionally_invoke
|
73
|
+
expect(filter_called).to be true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe VCR::Hooks do
|
79
|
+
let(:hooks_class) { Class.new { include VCR::Hooks } }
|
80
|
+
|
81
|
+
subject { hooks_class.new }
|
82
|
+
let(:invocations) { [] }
|
83
|
+
|
84
|
+
before(:each) do
|
85
|
+
hooks_class.instance_eval do
|
86
|
+
define_hook :before_foo
|
87
|
+
define_hook :before_bar, :prepend
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'allows the class to override the hook method and super to the main definition' do
|
92
|
+
override_called = nil
|
93
|
+
|
94
|
+
hooks_class.class_eval do
|
95
|
+
define_method :before_foo do |&block|
|
96
|
+
override_called = true
|
97
|
+
super(&block)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
subject.before_foo { }
|
102
|
+
expect(override_called).to be true
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#clear_hooks' do
|
106
|
+
it 'clears all hooks' do
|
107
|
+
subject.before_foo { invocations << :callback }
|
108
|
+
subject.clear_hooks
|
109
|
+
subject.invoke_hook(:before_foo)
|
110
|
+
expect(invocations).to be_empty
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#invoke_hook' do
|
115
|
+
it 'invokes each of the callbacks' do
|
116
|
+
subject.before_foo { invocations << :callback_1 }
|
117
|
+
subject.before_foo { invocations << :callback_2 }
|
118
|
+
|
119
|
+
expect(invocations).to be_empty
|
120
|
+
subject.invoke_hook(:before_foo)
|
121
|
+
expect(invocations).to eq([:callback_1, :callback_2])
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'maps the return value of each callback' do
|
125
|
+
subject.before_foo { 17 }
|
126
|
+
subject.before_foo { 12 }
|
127
|
+
expect(subject.invoke_hook(:before_foo)).to eq([17, 12])
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'does not invoke any filtered callbacks' do
|
131
|
+
subject.before_foo(:real?) { invocations << :blue_callback }
|
132
|
+
subject.invoke_hook(:before_foo, double(:real? => false))
|
133
|
+
expect(invocations).to be_empty
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'invokes them in reverse order if the hook was defined with :prepend' do
|
137
|
+
subject.before_bar { 17 }
|
138
|
+
subject.before_bar { 12 }
|
139
|
+
expect(subject.invoke_hook(:before_bar)).to eq([12, 17])
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#has_hooks_for?" do
|
144
|
+
it 'returns false when given an unrecognized hook name' do
|
145
|
+
expect(subject).not_to have_hooks_for(:abcd)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'returns false when given the name of a defined hook that has no registered callbacks' do
|
149
|
+
expect(subject).not_to have_hooks_for(:before_foo)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'returns true when given the name of a defined hook that has registered callbacks' do
|
153
|
+
subject.before_foo { }
|
154
|
+
expect(subject).to have_hooks_for(:before_foo)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VCR::InternetConnection do
|
4
|
+
describe '.available?' do
|
5
|
+
before(:each) do
|
6
|
+
described_class.send(:remove_instance_variable, :@available) if described_class.instance_variable_defined?(:@available)
|
7
|
+
end
|
8
|
+
|
9
|
+
def stub_pingecho_with(value)
|
10
|
+
allow(VCR::Ping).to receive(:pingecho).with("example.com", anything, anything).and_return(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when pinging example.com succeeds' do
|
14
|
+
it 'returns true' do
|
15
|
+
stub_pingecho_with(true)
|
16
|
+
expect(described_class).to be_available
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'memoizes the value so no extra pings are made' do
|
20
|
+
expect(VCR::Ping).to receive(:pingecho).once.and_return(true)
|
21
|
+
3.times { described_class.available? }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when pinging example.com fails' do
|
26
|
+
it 'returns false' do
|
27
|
+
stub_pingecho_with(false)
|
28
|
+
expect(described_class).not_to be_available
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'memoizes the value so no extra pings are made' do
|
32
|
+
expect(VCR::Ping).to receive(:pingecho).once.and_return(false)
|
33
|
+
3.times { described_class.available? }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module VCR
|
4
|
+
describe VersionChecker do
|
5
|
+
it 'raises an error if the major version is too low' do
|
6
|
+
checker = VersionChecker.new('foo', '0.7.3', '1.0.0')
|
7
|
+
expect { checker.check_version! }.to raise_error(Errors::LibraryVersionTooLowError)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'raises an error if the minor version is too low' do
|
11
|
+
checker = VersionChecker.new('foo', '1.0.99', '1.1.3')
|
12
|
+
expect { checker.check_version! }.to raise_error(Errors::LibraryVersionTooLowError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'raises an error if the patch version is too low' do
|
16
|
+
checker = VersionChecker.new('foo', '1.0.8', '1.0.10')
|
17
|
+
expect { checker.check_version! }.to raise_error(Errors::LibraryVersionTooLowError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'does not raise an error when the version is equal' do
|
21
|
+
checker = VersionChecker.new('foo', '1.0.0', '1.0.0')
|
22
|
+
expect { checker.check_version! }.not_to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'does not raise an error when the version is higher' do
|
26
|
+
checker = VersionChecker.new('foo', '2.0.0', '1.0.0')
|
27
|
+
expect { checker.check_version! }.not_to raise_error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "VCR.version" do
|
4
|
+
subject { VCR.version }
|
5
|
+
|
6
|
+
it { should =~ /\A\d+\.\d+\.\d+(\.\w+)?\z/ }
|
7
|
+
|
8
|
+
describe '#parts' do
|
9
|
+
subject { super().parts }
|
10
|
+
it { should be_instance_of(Array) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#major' do
|
14
|
+
subject { super().major }
|
15
|
+
it { should be_instance_of(Fixnum) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#minor' do
|
19
|
+
subject { super().minor }
|
20
|
+
it { should be_instance_of(Fixnum) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#patch' do
|
24
|
+
subject { super().patch }
|
25
|
+
it { should be_instance_of(Fixnum) }
|
26
|
+
end
|
27
|
+
end
|