changed
README.md
|
@@ -10,7 10,7 @@ by adding `criterion` to your list of dependencies in `mix.exs`:
|
10
10
|
```elixir
|
11
11
|
def deps do
|
12
12
|
[
|
13
|
- {:criterion, "~> 0.1.0", only: [:test]}
|
13
|
{:criterion, "~> 0.1.0", only: [:test, :dev]}
|
14
14
|
]
|
15
15
|
end
|
16
16
|
```
|
|
@@ -25,7 25,7 @@ defmodule Criterion.SharedSteps do
|
25
25
|
|
26
26
|
defstep "Given a number", _context, args do
|
27
27
|
min = args[:min] || 0
|
28
|
- %{number: min :rand.uniform(100)}
|
28
|
%{number: min Enum.random(0..100)}
|
29
29
|
end
|
30
30
|
end
|
31
31
|
```
|
|
@@ -39,17 39,30 @@ defmodule CriterionTest do
|
39
39
|
alias Criterion.SharedSteps
|
40
40
|
|
41
41
|
feature "Math" do
|
42
|
setup do
|
43
|
{:ok, pi: 3.14}
|
44
|
end
|
45
|
|
42
46
|
scenario "Square" do
|
43
|
- step "Given a number", from: SharedSteps, where: [min: 2]
|
47
|
step("Given a number greater than 5",
|
48
|
from: SharedSteps, # use only if the reusable step is in another module
|
49
|
via: "Given a number" # use only if the reusable step has a different step name,
|
50
|
where: [min: 5] # use only when you want to pass arguments to the reusable step,
|
51
|
)
|
44
52
|
|
45
53
|
step "When the number is multiplied by it self", %{number: number} do
|
46
54
|
result = number * number
|
47
|
- %{result: result}
|
55
|
%{result: result} # will be merged to the test context
|
48
56
|
end
|
49
57
|
|
50
58
|
step "Then the result is greater than the number", %{result: result, number: number} do
|
51
59
|
assert result > number
|
52
60
|
end
|
61
|
|
62
|
# you can access data from the initial context of the test
|
63
|
step "And pi is a constant", %{pi: pi} do
|
64
|
assert pi == 3.14
|
65
|
end
|
53
66
|
end
|
54
67
|
end
|
55
68
|
end
|
changed
hex_metadata.config
|
@@ -1,6 1,6 @@
|
1
1
|
{<<"links">>,[{<<"GitHub">>,<<"https://github.com/abel-mc/criterion">>}]}.
|
2
2
|
{<<"name">>,<<"criterion">>}.
|
3
|
- {<<"version">>,<<"0.1.10">>}.
|
3
|
{<<"version">>,<<"0.1.11">>}.
|
4
4
|
{<<"description">>,<<"A library to write tests bdd style.">>}.
|
5
5
|
{<<"elixir">>,<<"~> 1.15">>}.
|
6
6
|
{<<"app">>,<<"criterion">>}.
|
changed
lib/criterion.ex
|
@@ -5,10 5,10 @@ defmodule Criterion do
|
5
5
|
## Usage
|
6
6
|
|
7
7
|
1. Define a feature using `feature/2` macro
|
8
|
- 2. Define scenarios under the feature using the `scenario/3` macro.
|
9
|
- 2. Inside each scenario, define steps using the `step/3` macro.
|
10
|
- 3. Steps can be either plain steps, steps with context variables or shared step
|
11
|
- 4. Shared steps can be defined using `defstep/4` macro
|
8
|
2. Define scenarios under the feature using the `scenario/2` macro.
|
9
|
3. Inside each scenario, define steps using `step/2` block.
|
10
|
4. Steps can be either plain steps, steps with context variables or shared step
|
11
|
5. Shared steps can be defined using `defstep/4` macro
|
12
12
|
|
13
13
|
## Example
|
14
14
|
|
|
@@ -20,7 20,7 @@ defmodule Criterion do
|
20
20
|
|
21
21
|
defstep "Given a number", _context, args do
|
22
22
|
min = args[:min] || 0
|
23
|
- %{number: min :rand.uniform(100)}
|
23
|
%{number: min Enum.random(0..100)}
|
24
24
|
end
|
25
25
|
end
|
26
26
|
```
|
|
@@ -34,17 34,30 @@ defmodule Criterion do
|
34
34
|
alias Criterion.SharedSteps
|
35
35
|
|
36
36
|
feature "Math" do
|
37
|
setup do
|
38
|
{:ok, pi: 3.14}
|
39
|
end
|
40
|
|
37
41
|
scenario "Square" do
|
38
|
- step "Given a number", from: SharedSteps, where: [min: 2]
|
42
|
step("Given a number greater than 5",
|
43
|
from: SharedSteps, # use only if the reusable step is in another module
|
44
|
via: "Given a number" # use only if the reusable step has a different step name,
|
45
|
where: [min: 5] # use only when you want to pass arguments to the reusable step,
|
46
|
)
|
39
47
|
|
40
48
|
step "When the number is multiplied by it self", %{number: number} do
|
41
49
|
result = number * number
|
42
|
- %{result: result}
|
50
|
%{result: result} # will be merged to the test context
|
43
51
|
end
|
44
52
|
|
45
53
|
step "Then the result is greater than the number", %{result: result, number: number} do
|
46
54
|
assert result > number
|
47
55
|
end
|
56
|
|
57
|
# you can access data from the initial context of the test
|
58
|
step "And pi is a constant", %{pi: pi} do
|
59
|
assert pi == 3.14
|
60
|
end
|
48
61
|
end
|
49
62
|
end
|
50
63
|
end
|
|
@@ -148,10 161,14 @@ defmodule Criterion do
|
148
161
|
opts = List.flatten(opts)
|
149
162
|
from = opts[:from]
|
150
163
|
where = opts[:where]
|
164
|
via = opts[:via]
|
165
|
step_description = via || step_description
|
151
166
|
|
152
167
|
if from do
|
153
168
|
quote do
|
154
|
- fn context -> unquote(from).step(unquote(step_description), context, unquote(where)) end
|
169
|
fn context ->
|
170
|
unquote(from).step(unquote(step_description), context, unquote(where))
|
171
|
end
|
155
172
|
end
|
156
173
|
else
|
157
174
|
quote do
|
changed
mix.exs
|
@@ -4,7 4,7 @@ defmodule Criterion.MixProject do
|
4
4
|
def project do
|
5
5
|
[
|
6
6
|
app: :criterion,
|
7
|
- version: "0.1.10",
|
7
|
version: "0.1.11",
|
8
8
|
elixir: "~> 1.15",
|
9
9
|
start_permanent: Mix.env() == :prod,
|
10
10
|
deps: deps(),
|