parroty / exvcr

HTTP request/response recording library for elixir, inspired by VCR.
MIT License
714 stars 133 forks source link

Support for Multiple Stub Requests #216

Closed scudelletti closed 7 months ago

scudelletti commented 7 months ago

Hello there! 👋

Since we support multiple requests when using fixtures I thought it would be nice to support multiple requests also when using the :stub option.

This feature is quite useful in scenarios in which we need to create stubs manually or dynamically.

Usage:

  stubs = [
    [url: "http://example.com/1", body: "Stub Response 1", status_code: 200],
    [url: "http://example.com/2", body: "Stub Response 2", status_code: 404]
  ]

  use_cassette :stub, stubs do
    {:ok, response} = Finch.build(:get, "http://example.com/1") |> Finch.request(ExVCRFinch)
    assert response.status == 200
    assert response.body =~ ~r/Stub Response 1/

    {:ok, response} = Finch.build(:get, "http://example.com/2") |> Finch.request(ExVCRFinch)
    assert response.status == 404
    assert response.body =~ ~r/Stub Response 2/
  end

Thank you for your time and for maintaining this awesome library! Please let me know if any change is required.

coveralls commented 7 months ago

Coverage Status

coverage: 90.061% (-2.8%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

coveralls commented 7 months ago

Coverage Status

coverage: 89.908% (-2.9%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

coveralls commented 7 months ago

Coverage Status

coverage: 89.908% (-2.9%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

coveralls commented 7 months ago

Coverage Status

coverage: 89.407% (-3.5%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

coveralls commented 7 months ago

Coverage Status

coverage: 90.061% (-2.8%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

coveralls commented 7 months ago

Coverage Status

coverage: 88.532% (-4.3%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

coveralls commented 7 months ago

Coverage Status

coverage: 87.92% (-4.9%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

coveralls commented 7 months ago

Coverage Status

coverage: 88.073% (-4.8%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

coveralls commented 7 months ago

Coverage Status

coverage: 88.379% (-4.5%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

coveralls commented 7 months ago

Coverage Status

coverage: 87.994% (-4.9%) from 92.857% when pulling bbc1dbc4aab9c3145a7a82334bf63c50a7deb42c on scudelletti:ds-add-multiple-stub-support into 5023de6686fe805444768e83b5012f2664922bdb on parroty:master.

parroty commented 7 months ago

Thanks!