-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Test noun customization #4635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test noun customization #4635
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,16 +73,18 @@ defmodule ExUnit do | |
* `:time` - the time to run the test | ||
* `:tags` - the test tags | ||
* `:logs` - the captured logs | ||
* `:type` - the test type | ||
|
||
""" | ||
defstruct [:name, :case, :state, time: 0, tags: %{}, logs: ""] | ||
defstruct [:name, :case, :state, time: 0, tags: %{}, logs: "", type: :test] | ||
|
||
@type t :: %__MODULE__{ | ||
name: atom, | ||
case: module, | ||
state: ExUnit.state, | ||
time: non_neg_integer, | ||
tags: map} | ||
tags: map, | ||
type: atom} | ||
end | ||
|
||
defmodule TestCase do | ||
|
@@ -211,6 +213,9 @@ defmodule ExUnit do | |
on formatting and reporters (defaults to 20) | ||
|
||
* `:timeout` - set the timeout for the tests (default 60_000ms) | ||
|
||
* `:plural_rules` - See `ExUnit.plural_rule/1` and `ExUnit.plural_rule/2`. | ||
You should not set this option directly. | ||
""" | ||
def configure(options) do | ||
Enum.each options, fn {k, v} -> | ||
|
@@ -225,6 +230,42 @@ defmodule ExUnit do | |
Application.get_all_env(:ex_unit) | ||
end | ||
|
||
@doc """ | ||
Returns the pluralization for `word`. | ||
|
||
If one is not registered, returns `"\#{word}s"`. | ||
""" | ||
@spec plural_rule(binary) :: binary | ||
def plural_rule(word) when not is_binary(word), | ||
do: raise_plural_argument_error("word") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have a single clause that checks for binaries only. |
||
def plural_rule(word) do | ||
configuration() | ||
|> Keyword.get(:plural_rules, %{}) | ||
|> Map.get(word, "#{word}s") | ||
end | ||
|
||
@doc """ | ||
Registers a `pluralization` for `word`. | ||
|
||
If one is already registered, it is replaced. | ||
""" | ||
@spec plural_rule(binary, binary) :: :ok | ||
def plural_rule(word, _pluralization) when not is_binary(word), | ||
do: raise_plural_argument_error("word") | ||
def plural_rule(_word, pluralization) when not is_binary(pluralization), | ||
do: raise_plural_argument_error("pluralization") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just use regular guards. No need for the "when not". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, let's have a single clause that checks they are binary and that's it. |
||
def plural_rule(word, pluralization) do | ||
plural_rules = | ||
configuration() | ||
|> Keyword.get(:plural_rules, %{}) | ||
|> Map.put(word, pluralization) | ||
|
||
configure(plural_rules: plural_rules) | ||
end | ||
|
||
defp raise_plural_argument_error(argument_name), | ||
do: raise ArgumentError, message: "`#{argument_name}` must be a binary" | ||
|
||
@doc """ | ||
API used to run the tests. It is invoked automatically | ||
if ExUnit is started via `ExUnit.start/1`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this from here since you are not supposed to set it directly anyway.