File: vcr_stub_helpers.rb

package info (click to toggle)
ruby-vcr 6.0.0%2Breally5.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,320 kB
  • sloc: ruby: 8,456; sh: 177; makefile: 7
file content (17 lines) | stat: -rw-r--r-- 663 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module VCRStubHelpers
  def interactions_from(file)
    hashes = YAML.load_file(File.join(VCR::SPEC_ROOT, 'fixtures', file))['http_interactions']
    hashes.map { |h| VCR::HTTPInteraction.from_hash(h) }
  end

  def stub_requests(*args)
    allow(VCR).to receive(:http_interactions).and_return(VCR::Cassette::HTTPInteractionList.new(*args))
  end

  def http_interaction(url, response_body = "FOO!", status_code = 200)
    request = VCR::Request.new(:get, request_url)
    response_status = VCR::ResponseStatus.new(status_code)
    response = VCR::Response.new(response_status, nil, response_body, '1.1')
    VCR::HTTPInteraction.new(request, response)
  end
end