• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

parroty / exvcr / f6cc9bc0ae05f24b374e6c1fa9b52e9d0967e032-PR-202

pending completion
f6cc9bc0ae05f24b374e6c1fa9b52e9d0967e032-PR-202

Pull #202

github

parroty
Pull Request #202: Fix name conflict for finch test case

577 of 642 relevant lines covered (89.88%)

95.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/lib/exvcr/adapter/httpc.ex
1
defmodule ExVCR.Adapter.Httpc do
2
  @moduledoc """
3
  Provides adapter methods to mock :httpc methods.
4
  """
5

6
  use ExVCR.Adapter
7
  alias ExVCR.Util
8

9
  defmacro __using__(_opts) do
10
    # do nothing
11
  end
12

13
  defdelegate convert_from_string(string), to: ExVCR.Adapter.Httpc.Converter
8✔
14
  defdelegate convert_to_string(request, response), to: ExVCR.Adapter.Httpc.Converter
8✔
15
  defdelegate parse_request_body(request_body), to: ExVCR.Adapter.Httpc.Converter
×
16

17
  @doc """
18
  Returns the name of the mock target module.
19
  """
20
  def module_name do
21
    :httpc
22
  end
23

24
  @doc """
25
  Returns list of the mock target methods with function name and callback.
26
  Implementation for global mock.
27
    TODO:
28
      {:request, &ExVCR.Recorder.request(recorder, [&1,&2])}
29
      {:request, &ExVCR.Recorder.request(recorder, [&1,&2,&3,&4,&5])}
30
  """
31
  def target_methods() do
32
    [ {:request, &ExVCR.Recorder.request([&1])},
13✔
33
      {:request, &ExVCR.Recorder.request([&1,&2,&3,&4])} ]
5✔
34
  end
35

36
  @doc """
37
  Returns list of the mock target methods with function name and callback.
38
    TODO:
39
      {:request, &ExVCR.Recorder.request(recorder, [&1,&2])}
40
      {:request, &ExVCR.Recorder.request(recorder, [&1,&2,&3,&4,&5])}
41
  """
42
  def target_methods(recorder) do
43
    [ {:request, &ExVCR.Recorder.request(recorder, [&1])},
×
44
      {:request, &ExVCR.Recorder.request(recorder, [&1,&2,&3,&4])} ]
×
45
  end
46

47

48
  @doc """
49
  Generate key for searching response.
50
  """
51
  def generate_keys_for_request(request) do
52
    case request do
16✔
53
      [method, {url, headers} | _] ->
54
        [url: url, method: method, request_body: nil, headers: Util.stringify_keys(headers)]
55
      [method, {url, headers, _, body} | _] ->
56
        [url: url, method: method, request_body: body, headers: Util.stringify_keys(headers)]
57
      [url | _] ->
58
        [url: url, method: :get, request_body: nil, headers: []]
59
    end
60
  end
61

62
  @doc """
63
  Callback from ExVCR.Handler when response is retrieved from the HTTP server.
64
  """
65
  def hook_response_from_server(response) do
66
    apply_filters(response)
8✔
67
  end
68

69
  defp apply_filters({:ok, {status_code, headers, body}}) do
70
    replaced_body = to_string(body) |> ExVCR.Filter.filter_sensitive_data
8✔
71
    filtered_headers = ExVCR.Filter.remove_blacklisted_headers(headers)
8✔
72
    {:ok, {status_code, filtered_headers, replaced_body}}
73
  end
74

75
  defp apply_filters({:error, reason}) do
76
    {:error, reason}
77
  end
78

79
  @doc """
80
  Returns the response from the ExVCR.Reponse record.
81
  """
82
  def get_response_value_from_cache(response) do
83
    if response.type == "error" do
8✔
84
      {:error, response.body}
1✔
85
    else
86
      {:ok, {response.status_code, response.headers, response.body}}
7✔
87
    end
88
  end
89

90
  @doc """
91
  Default definitions for stub.
92
  """
93
  def default_stub_params(:headers), do: %{"content-type" => "text/html"}
1✔
94
  def default_stub_params(:status_code), do: ["HTTP/1.1", 200, "OK"]
95
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc