Skip to content

Commit

Permalink
Replace Dict by Map
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmi committed Jul 24, 2016
1 parent 8d3c504 commit 3bdd705
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ expect string |> to(have_first value) #String.first(string) == value
... be_blank #String.length(string) == 0
... be_empty #String.length(string) == 0
```
#### Dict
#### Map
```elixir
expect dict |> to(have_key value) #Dict.has_key?(value)
expect dict |> to(have_value value) #Enum.member?(Dict.values(dict), value)
expect map |> to(have_key value) #Map.has_key?(value)
expect map |> to(have_value value) #Enum.member?(Map.values(dict), value)
```

#### Type checking
Expand Down
6 changes: 3 additions & 3 deletions lib/espec/assertion_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ defmodule ESpec.AssertionHelpers do
def be_valid_string(), do: {Assertions.String.BeValidString, []}
def be_blank(), do: {Assertions.String.BeBlank, []}

def have_key(value), do: {Assertions.Dict.HaveKey, value}
def have_value(value), do: {Assertions.Dict.HaveValue, value}
def eq_dict(value), do: {Assertions.Dict.EqDict, value}
def have_key(value), do: {Assertions.Map.HaveKey, value}
def have_value(value), do: {Assertions.Map.HaveValue, value}
def eq_dict(value), do: {Assertions.Map.EqDict, value}

Enum.each @elixir_types, fn(type) ->
def unquote(String.to_atom("be_#{type}"))() do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ESpec.Assertions.Dict.HaveKey do
defmodule ESpec.Assertions.Map.HaveKey do
@moduledoc """
Defines 'have_key' assertion.
Expand All @@ -7,7 +7,7 @@ defmodule ESpec.Assertions.Dict.HaveKey do
use ESpec.Assertions.Interface

defp match(dict, val) do
result = Dict.has_key?(dict, val)
result = Map.has_key?(dict, val)
{result, result}
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ESpec.Assertions.Dict.HaveValue do
defmodule ESpec.Assertions.Map.HaveValue do
@moduledoc """
Defines 'have_value' assertion.
Expand All @@ -7,7 +7,7 @@ defmodule ESpec.Assertions.Dict.HaveValue do
use ESpec.Assertions.Interface

defp match(dict, val) do
result = Enum.member?(Dict.values(dict), val)
result = Enum.member?(Map.values(dict), val)
{result, result}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/espec/example_runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ defmodule ESpec.ExampleRunner do
case res do
{key, list} when key in @dict_keys and is_list(list) ->
if Keyword.keyword?(list) do
Enum.reduce(list, map, fn({k,v}, a) -> Dict.put(a, k, v) end)
Enum.reduce(list, map, fn({k,v}, a) -> Map.put(a, k, v) end)
else
map
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ESpec.Assertions.Dict.HaveKeySpec do
defmodule ESpec.Assertions.Map.HaveKeySpec do
use ESpec, async: true

subject %{a: 1, b: 2}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ESpec.Assertions.Dict.HaveValueSpec do
defmodule ESpec.Assertions.Map.HaveValueSpec do
use ESpec, async: true

subject %{a: 1, b: 2}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Dict.HaveKeyTest do
defmodule Map.HaveKeyTest do
use ExUnit.Case, async: true

defmodule SomeSpec do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Dict.HaveValueTest do
defmodule Map.HaveValueTest do
use ExUnit.Case, async: true

defmodule SomeSpec do
Expand Down

0 comments on commit 3bdd705

Please sign in to comment.