aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Blowers <shdblowers@gmail.com>2016-11-22 14:57:39 (GMT)
committerSteven Blowers <shdblowers@gmail.com>2016-11-22 14:57:39 (GMT)
commitc680de5bf01c0dd313701de5be5be633ed7f41c4 (patch)
tree91c7b2fc5a66f3039b7be767aa6346cd0d590a30
parent8ca99bdea1f8900442b32b65edfaada4378eeed3 (diff)
downloadzendex-c680de5bf01c0dd313701de5be5be633ed7f41c4.tar.gz
zendex-c680de5bf01c0dd313701de5be5be633ed7f41c4.tar.xz
improvements to using meck in tests
-rw-r--r--test/zendex/ticket_test.exs42
1 files changed, 21 insertions, 21 deletions
diff --git a/test/zendex/ticket_test.exs b/test/zendex/ticket_test.exs
index 4bbe388..c4250d1 100644
--- a/test/zendex/ticket_test.exs
+++ b/test/zendex/ticket_test.exs
@@ -1,38 +1,38 @@
defmodule Zendex.TicketTest do
- use ExUnit.Case, async: true
+ use ExUnit.Case, async: false
setup do
- [conn: Zendex.Connection.setup("http://test.zendesk.com", "User", "Passw")]
+ %{conn: Zendex.Connection.setup("http://test.zendesk.com",
+ "User",
+ "Password123!")}
end
setup_all do
:meck.new(HTTPoison)
-
- on_exit fn ->
- :meck.unload
- end
-
+ on_exit fn -> :meck.unload end
:ok
end
- test "getting tickets", context do
- :meck.expect(HTTPoison,
- :get!,
- fn("http://test.zendesk.com/api/v2/tickets.json", [{"Authorization", "Basic VXNlcjpQYXNzdw=="}]) ->
- %HTTPoison.Response{body: Poison.encode!("ticket")}
- end)
+ test "getting tickets", %{conn: conn} do
+ stub = fn("http://test.zendesk.com/api/v2/tickets.json",
+ [{"Authorization", "Basic VXNlcjpQYXNzd29yZDEyMyE="}]) ->
+ %HTTPoison.Response{body: Poison.encode!("ticket")}
+ end
+ :meck.expect(HTTPoison, :get!, stub)
- assert "ticket" == Zendex.Ticket.list(context[:conn])
+ assert "ticket" == Zendex.Ticket.list(conn)
end
- test "creating a ticket", context do
- :meck.expect(HTTPoison,
- :post!,
- fn(_, _, _) ->
- %HTTPoison.Response{body: Poison.encode!("Ticket created successfully!")}
- end)
+ test "creating a ticket", %{conn: conn} do
+ stub = fn("http://test.zendesk.com/api/v2/tickets.json",
+ "{\"ticket\":{\"title\":\"HELP!\"}}",
+ [{"Authorization", "Basic VXNlcjpQYXNzd29yZDEyMyE="},
+ {"Content-Type", "application/json"}]) ->
+ %HTTPoison.Response{body: Poison.encode!("Ticket created successfully!")}
+ end
+ :meck.expect(HTTPoison, :post!, stub)
assert "Ticket created successfully!" ==
- Zendex.Ticket.create(context[:conn], %{"ticket": %{}})
+ Zendex.Ticket.create(conn, %{"ticket": %{"title": "HELP!"}})
end
end