Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify faraday's on_data callback tests #933

Merged
merged 9 commits into from
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 8 additions & 12 deletions spec/lib/vcr/library_hooks/faraday_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,26 @@
end

context 'when using on_data callback' do
def make_request
def make_request(&on_data_callback)
VCR.use_cassette('no_body') do
conn = Faraday.new(:url => "http://localhost:#{VCR::SinatraApp.port}") do |builder|
builder.request :url_encoded
builder.adapter :net_http
end
conn.get("localhost_test") do |request|
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
on_data_capture.push [chunk, overall_received_bytes]
end
request.options.on_data = on_data_callback
end
end
end

let(:on_data_capture) { [] }
it { expect { |b| make_request(&b) }.to yield_with_args('Localhost response', 18) }
it { expect(make_request {|_,_|}.body).to eq 'Localhost response' }

it 'records and replays correctly' do
expect(on_data_capture).to receive(:push).exactly(2).times.with(["Localhost response", 18])
context 'after recording' do
before { make_request {|_, _|} }

recorded = make_request
played_back = make_request

expect(recorded.body).to eq('Localhost response')
expect(played_back.body).to eq(recorded.body)
it { expect { |b| make_request(&b) }.to yield_with_args('Localhost response', 18) }
it { expect(make_request {|_,_|}.body).to eq 'Localhost response' }
end
end
end
Expand Down