forked from antonmi/espec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples can be generated via loops: subject 1..5 Enum.map 1..3, fn(n) -> it do: is_expected().to have(unquote(n)) end Examples descriptions can contain interpolations: subject(24) Enum.map 2..4, fn(n) -> it "is divisible by #{n}" do expect(rem(subject(), unquote(n))).to be(0) end end
- Loading branch information
1 parent
181815d
commit cbacb36
Showing
3 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule GeneratedExamplesSpec do | ||
use ESpec, async: true | ||
|
||
subject 1..5 | ||
|
||
Enum.map 1..3, fn(n) -> | ||
it do: is_expected().to have(unquote(n)) | ||
end | ||
|
||
context "with description" do | ||
subject(24) | ||
|
||
Enum.map 2..4, fn(n) -> | ||
it "is divisible by #{n}" do | ||
expect(rem(subject(), unquote(n))).to be(0) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
defmodule GeneratedExamplesTest do | ||
use ExUnit.Case, async: true | ||
|
||
defmodule SomeSpec do | ||
use ESpec | ||
|
||
Enum.map 1..3, fn(idx) -> | ||
it "fails, same name" do | ||
expect(unquote(idx)) |> to(eq(0)) | ||
end | ||
|
||
it "fails, different name #{idx}" do | ||
expect(unquote(idx)) |> to(eq(-1)) | ||
end | ||
end | ||
end | ||
|
||
setup_all do | ||
ESpec.Runner.Queue.start(:input) | ||
ESpec.Runner.Queue.start(:output) | ||
:ok | ||
end | ||
|
||
test "runs all of them and they fail with the appropriate message" do | ||
examples = ESpec.SuiteRunner.run(SomeSpec, %{}, false) | ||
|
||
assert(Enum.map(examples, fn(e) -> e.error.message end) == | ||
Enum.map(3..1, fn(idx) -> | ||
["Expected (==) `-1`, but got: `#{idx}`", | ||
"Expected (==) `0`, but got: `#{idx}`"] | ||
end) | ||
|> List.flatten) | ||
end | ||
end |