Skip to content

Commit

Permalink
Rename method for greater clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Nov 2, 2011
1 parent 04e2595 commit a578656
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions lib/vcr/cassette.rb
Expand Up @@ -38,15 +38,15 @@ def initialize(name, options = {})

raise_error_unless_valid_record_mode

load_recorded_interactions
load_previously_recorded_interactions
end

def eject
write_recorded_interactions_to_disk
end

def recorded_interactions
@recorded_interactions ||= []
def previously_recorded_interactions
@previously_recorded_interactions ||= []
end

def record_http_interaction(interaction)
Expand Down Expand Up @@ -108,7 +108,7 @@ def should_remove_matching_existing_interactions?
record_mode == :all
end

def load_recorded_interactions
def load_previously_recorded_interactions
if file && File.size?(file)
interactions = @serializer.deserialize(raw_yaml_content)['http_interactions'].map { |h| HTTPInteraction.from_hash(h) }

Expand All @@ -122,10 +122,10 @@ def load_recorded_interactions
interactions.each { |i| i.response.update_content_length_header }
end

recorded_interactions.replace(interactions)
previously_recorded_interactions.replace(interactions)
end

interactions = should_stub_requests? ? recorded_interactions : []
interactions = should_stub_requests? ? previously_recorded_interactions : []

@http_interactions = HTTPInteractionList.new(
interactions,
Expand All @@ -143,7 +143,7 @@ def raw_yaml_content
end

def merged_interactions
old_interactions = recorded_interactions
old_interactions = previously_recorded_interactions

if should_remove_matching_existing_interactions?
new_interaction_list = HTTPInteractionList.new(new_recorded_interactions, match_requests_on)
Expand Down
14 changes: 7 additions & 7 deletions spec/vcr/cassette_spec.rb
Expand Up @@ -136,7 +136,7 @@ def http_interaction

it 'does not raise an error in the case of an empty file' do
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
VCR::Cassette.new('empty', :record => :none).recorded_interactions.should eq([])
VCR::Cassette.new('empty', :record => :none).previously_recorded_interactions.should eq([])
end

describe "reading the file from disk" do
Expand Down Expand Up @@ -273,16 +273,16 @@ def stub_old_interactions(interactions)

VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
cassette = VCR::Cassette.new('with_localhost_requests', :record => record_mode)
cassette.recorded_interactions.map { |i| URI.parse(i.uri).host }.should eq(%w[example.com])
cassette.previously_recorded_interactions.map { |i| URI.parse(i.uri).host }.should eq(%w[example.com])
end

it "loads the recorded interactions from the library yml file" do
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
cassette = VCR::Cassette.new('example', :record => record_mode)

cassette.should have(3).recorded_interactions
cassette.should have(3).previously_recorded_interactions

i1, i2, i3 = *cassette.recorded_interactions
i1, i2, i3 = *cassette.previously_recorded_interactions

i1.request.method.should eq(:get)
i1.request.uri.should eq('http://example.com/')
Expand Down Expand Up @@ -329,7 +329,7 @@ def stub_old_interactions(interactions)
).exactly(3).times

cassette = VCR::Cassette.new('example', :record => record_mode, :tag => :foo)
cassette.should have(3).recorded_interactions
cassette.should have(3).previously_recorded_interactions
end

it 'does not playback any interactions that are ignored in a before_playback hook' do
Expand All @@ -339,7 +339,7 @@ def stub_old_interactions(interactions)

VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
cassette = VCR::Cassette.new('example', :record => record_mode)
cassette.should have(2).recorded_interactions
cassette.should have(2).previously_recorded_interactions
end

it 'instantiates the http_interactions with the loaded interactions and the request matchers' do
Expand Down Expand Up @@ -460,7 +460,7 @@ def interaction(response_body, request_attributes)
let(:saved_recorded_interactions) { YAML.load_file(subject.file)['http_interactions'].map { |h| VCR::HTTPInteraction.from_hash(h) } }

before(:each) do
subject.stub(:recorded_interactions => [interaction_foo_1])
subject.stub(:previously_recorded_interactions => [interaction_foo_1])
subject.record_http_interaction(interaction_foo_2)
subject.record_http_interaction(interaction_bar)
subject.eject
Expand Down

0 comments on commit a578656

Please sign in to comment.