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

parroty / exvcr / dbffa5f39277b0e25e1cc297b5c1cb5f78ab7929

21 Sep 2024 10:59AM UTC coverage: 92.224%. Remained the same
dbffa5f39277b0e25e1cc297b5c1cb5f78ab7929

push

github

web-flow
remove kramdown syntax from links (#222)

676 of 733 relevant lines covered (92.22%)

944.91 hits per line

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

97.14
/lib/exvcr/adapter/ibrowse/converter.ex
1
defmodule ExVCR.Adapter.IBrowse.Converter do
2
  @moduledoc """
3
  Provides helpers to mock :ibrowse methods.
4
  """
5

6
  use ExVCR.Converter
7

8
  defp string_to_response(string) do
9
    response = Enum.map(string, fn({x, y}) -> {String.to_atom(x), y} end)
576✔
10
    response = struct(ExVCR.Response, response)
576✔
11

12
    response =
576✔
13
      if response.status_code do
576✔
14
        %{response | status_code: Integer.to_charlist(response.status_code)}
549✔
15
      else
16
        response
27✔
17
      end
18

19
    response =
576✔
20
      if response.type == "error" do
576✔
21
        body = string_to_error_reason(response.body)
27✔
22
        %{response | body: body}
27✔
23
      else
24
        response
549✔
25
      end
26

27
    response =
576✔
28
      if is_map(response.headers) do
576✔
29
        headers = response.headers
549✔
30
                  |> Map.to_list
31
                  |> Enum.map(fn({k,v}) -> {to_charlist(k), to_charlist(v)} end)
1,090✔
32
        %{response | headers: headers}
549✔
33
      else
34
        response
27✔
35
      end
36

37
    response
576✔
38
  end
39

40
  defp string_to_error_reason([reason, details]), do: { String.to_atom(reason), binary_to_tuple(details) }
10✔
41
  defp string_to_error_reason([reason]), do: String.to_atom(reason)
9✔
42

43
  defp request_to_string([url, headers, method]), do: request_to_string([url, headers, method, [], []])
9✔
44
  defp request_to_string([url, headers, method, body]), do: request_to_string([url, headers, method, body, []])
×
45
  defp request_to_string([url, headers, method, body, options]), do: request_to_string([url, headers, method, body, options, 5000])
9✔
46
  defp request_to_string([url, headers, method, body, options, _timeout]) do
47
    %ExVCR.Request{
117✔
48
      url: parse_url(url),
49
      headers: parse_headers(headers),
50
      method: Atom.to_string(method),
51
      body: parse_request_body(body),
52
      options: parse_options(sanitize_options(options))
53
    }
54
  end
55

56
  # If option value is tuple, make it as list, for encoding as json.
57
  defp sanitize_options(options) do
58
    Enum.map(options, fn({key, value}) ->
117✔
59
      if is_tuple(value) do
9✔
60
        {key, Tuple.to_list(value)}
2✔
61
      else
62
        {key, value}
63
      end
64
    end)
65
  end
66

67
  defp response_to_string({:ok, status_code, headers, body}) do
68
    %ExVCR.Response{
108✔
69
      type: "ok",
70
      status_code: List.to_integer(status_code),
71
      headers: parse_headers(headers),
72
      body: to_string(body)
108✔
73
    }
74
  end
75

76
  defp response_to_string({:error, reason}) do
77
    %ExVCR.Response{
9✔
78
      type: "error",
79
      body: error_reason_to_string(reason)
80
    }
81
  end
82

83
  defp error_reason_to_string({reason, details}), do: [Atom.to_string(reason), tuple_to_binary(details)]
5✔
84
  defp error_reason_to_string(reason), do: [Atom.to_string(reason)]
85

86
  defp tuple_to_binary(tuple) do
87
    Enum.map(Tuple.to_list(tuple), fn(x) ->
9✔
88
      if is_atom(x), do: Atom.to_string(x), else: x
18✔
89
    end)
90
  end
91

92
  defp binary_to_tuple(list) do
93
    Enum.map(list, fn(x) ->
94
      if is_binary(x), do: String.to_atom(x), else: x
36✔
95
    end) |> List.to_tuple
18✔
96
  end
97
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