<commit_before>defmodule PactElixir.DslTest do
  use ExUnit.Case

  import PactElixir.Dsl

  test "Provider responds to /foo with 'bar'" do
    provider =
      service_provider(consumer: "PactTester", provider: "PactProvider")
      |> add_interaction(
        "give me foo",
        given("foo exists"),
        with_request(method: :get, path: "/foo"),
        will_respond_with(status: 200, body: "bar")
      )
      |> build

    assert get_request(provider, "/foo").body == "bar"

    assert "[]" = mock_server_mismatches(provider)
    assert mock_server_matched?(provider) == true

    {:ok}
  end

  defp get_request(provider, path) do
    %HTTPoison.Response{} = HTTPoison.get!("http://localhost:#{provider.port}#{path}")
  end
end<commit_msg>Test for missing request<commit_after>defmodule PactElixir.DslTest do
  use ExUnit.Case

  import PactElixir.Dsl

  test "Provider responds to /foo with 'bar'" do
    provider =
      service_provider(consumer: "PactTester", provider: "PactProvider")
      |> add_interaction(
        "give me foo",
        given("foo exists"),
        with_request(method: :get, path: "/foo"),
        will_respond_with(status: 200, body: "bar")
      )
      |> build

    assert get_request(provider, "/foo").body == "bar"

    assert "[]" = mock_server_mismatches(provider)
    assert mock_server_matched?(provider) == true

    {:ok}
  end

  test "Mock server includes mismatch without request" do
    provider =
      service_provider(consumer: "PactTester", provider: "PactProvider")
      |> add_interaction(
        "give me foo",
        given("foo exists"),
        with_request(method: :get, path: "/foo"),
        will_respond_with(status: 200, body: "bar")
      )
      |> build

    assert mock_server_matched?(provider) == false
    [failure | _tail] = mock_server_mismatches(provider) |> Poison.decode!
    assert %{"type" => "missing-request"} = failure

    {:ok}
  end

  defp get_request(provider, path) do
    %HTTPoison.Response{} = HTTPoison.get!("http://localhost:#{provider.port}#{path}")
  end
end
{'fraction_non_alphanumeric': 0.13475521085797382, 'fraction_numerical': 0.004362578768783325, 'mean_word_length': 3.2556701030927835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '944374', 'n_tokens_mistral': 690, 'n_tokens_neox': 660, 'n_words': 151}