Skip to content

Commit

Permalink
[mrjoelkemp] Update README to mock base on partial input
Browse files Browse the repository at this point in the history
Update the README on how to mix mocks based on the entire
input to a function or a partial input to a function using a small
helper.

Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
mrjoelkemp and Olshansk authored Sep 18, 2020
1 parent 0e07a6e commit ad69c01
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,20 @@ defmodule MyTest do
get: fn
(%{}, "http://example.com") -> "<html>Hello from example.com</html>"
(%{}, "http://example.org") -> "<html>example.org says hi</html>"
(%{}, url) -> conditionally_mocked(url)
end
]) do
assert Map.get(%{}, "http://example.com") == "<html>Hello from example.com</html>"
assert Map.get(%{}, "http://example.org") == "<html>example.org says hi</html>"
assert Map.get(%{}, "http://example.xyz") == "<html>Hello from example.xyz</html>"
assert Map.get(%{}, "http://example.tech") == "<html>example.tech says hi</html>"
end
end

def conditionally_mocked(url) do
cond do
String.contains?(url, ".xyz") -> "<html>Hello from example.xyz</html>"
String.contains?(url, ".tech") -> "<html>example.tech says hi</html>"
end
end
end
Expand Down

0 comments on commit ad69c01

Please sign in to comment.