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.
- Loading branch information
Showing
5 changed files
with
117 additions
and
70 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
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 |
---|---|---|
@@ -1,39 +1,64 @@ | ||
defmodule LeakingLetTest do | ||
use ExUnit.Case | ||
|
||
@code1 (quote do | ||
defmodule SomeSpec do | ||
use ESpec | ||
describe "first" do | ||
let :a, do: 1 | ||
it do: expect a |> to(eq 1) | ||
end | ||
describe "second" do | ||
it do: expect a |> to(eq 1) | ||
end | ||
defmodule SomeSpec do | ||
use ESpec | ||
describe "first" do | ||
let :a, do: 1 | ||
it do: expect a |> to(eq 1) | ||
end | ||
end) | ||
|
||
@code2 (quote do | ||
defmodule SomeSpec do | ||
use ESpec | ||
describe "first" do | ||
let :a, do: 1 | ||
it do: expect a |> to(eq 1) | ||
end | ||
describe "second" do | ||
it do: expect a |> to(eq 1) | ||
end | ||
end) | ||
it do: expect a |> to(eq 1) | ||
end | ||
|
||
test "code1" do | ||
assert_raise ESpec.LetError, "The let function `a/0` is not defined in the current scope!", fn -> | ||
Code.compile_quoted(@code1) | ||
defmodule SomeSpec2 do | ||
use ESpec | ||
describe "second" do | ||
it do: a |> should(eq 1) | ||
end | ||
describe "first" do | ||
let :a, do: 1 | ||
it do: a |> should(eq 1) | ||
end | ||
end | ||
|
||
test "code2" do | ||
assert_raise ESpec.LetError, "The let function `a/0` is not defined in the current scope!", fn -> | ||
Code.compile_quoted(@code2) | ||
end | ||
setup_all do | ||
{:ok, | ||
ex1: Enum.at(SomeSpec.examples, 0), | ||
ex2: Enum.at(SomeSpec.examples, 1), | ||
ex3: Enum.at(SomeSpec.examples, 2), | ||
|
||
ex4: Enum.at(SomeSpec2.examples, 0), | ||
ex5: Enum.at(SomeSpec2.examples, 1), | ||
} | ||
end | ||
|
||
test "runs ex1 then ex2", context do | ||
example = ESpec.ExampleRunner.run(context[:ex1]) | ||
assert example.status == :success | ||
|
||
example = ESpec.ExampleRunner.run(context[:ex2]) | ||
assert example.status == :failure | ||
assert example.error.message =~ "The let function `a/0` is not defined in the current scope!" | ||
end | ||
|
||
test "runs ex1 then ex3", context do | ||
example = ESpec.ExampleRunner.run(context[:ex1]) | ||
assert example.status == :success | ||
|
||
example = ESpec.ExampleRunner.run(context[:ex3]) | ||
assert example.status == :failure | ||
assert example.error.message =~ "The let function `a/0` is not defined in the current scope!" | ||
end | ||
|
||
test "runs ex5 then ex4", context do | ||
example = ESpec.ExampleRunner.run(context[:ex5]) | ||
assert example.status == :success | ||
|
||
example = ESpec.ExampleRunner.run(context[:ex4]) | ||
assert example.status == :failure | ||
assert example.error.message =~ "The let function `a/0` is not defined in the current scope!" | ||
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 |
---|---|---|
@@ -1,58 +1,78 @@ | ||
defmodule LeakingSubjectTest do | ||
use ExUnit.Case | ||
|
||
@code1 (quote do | ||
defmodule SomeSpec do | ||
use ESpec | ||
describe "first" do | ||
subject do: [] | ||
it "is empty by default", do: should be_empty | ||
end | ||
defmodule SomeSpec do | ||
use ESpec | ||
|
||
it do: should be_empty | ||
end | ||
end) | ||
describe "first" do | ||
subject do: [] | ||
|
||
@code2 (quote do | ||
defmodule SomeSpec do | ||
use ESpec | ||
describe "first" do | ||
subject do: [] | ||
it "is empty by default", do: should be_empty | ||
end | ||
it "is empty by default", do: should be_empty | ||
end | ||
|
||
describe "second" do | ||
it do: should be_empty | ||
it do: is_expected |> to(be_empty) | ||
it do: is_expected.to be_empty | ||
end | ||
end) | ||
|
||
@code3 (quote do | ||
defmodule SomeSpec do | ||
use ESpec | ||
describe "first" do | ||
subject do: [] | ||
it "is empty by default", do: should be_empty | ||
end | ||
end | ||
|
||
it do: is_expected.to be_empty | ||
defmodule SomeSpec2 do | ||
use ESpec | ||
describe "second" do | ||
it do: should(eq 1) | ||
end | ||
describe "first" do | ||
subject do: 1 | ||
it do: should(eq 1) | ||
end | ||
end) | ||
end | ||
|
||
setup_all do | ||
{:ok, | ||
ex1: Enum.at(SomeSpec.examples, 0), | ||
ex2: Enum.at(SomeSpec.examples, 1), | ||
ex3: Enum.at(SomeSpec.examples, 2), | ||
ex4: Enum.at(SomeSpec.examples, 3), | ||
|
||
test "code1" do | ||
assert_raise ESpec.LetError, "The subject is not defined in the current scope!", fn -> | ||
Code.compile_quoted(@code1) | ||
end | ||
ex5: Enum.at(SomeSpec2.examples, 0), | ||
ex6: Enum.at(SomeSpec2.examples, 1), | ||
} | ||
end | ||
|
||
test "code2" do | ||
assert_raise ESpec.LetError, "The subject is not defined in the current scope!", fn -> | ||
Code.compile_quoted(@code2) | ||
end | ||
test "runs ex1 then ex2", context do | ||
example = ESpec.ExampleRunner.run(context[:ex1]) | ||
assert example.status == :success | ||
|
||
example = ESpec.ExampleRunner.run(context[:ex2]) | ||
assert example.status == :failure | ||
assert example.error.message =~ "The subject is not defined in the current scope!" | ||
end | ||
|
||
test "code3" do | ||
assert_raise ESpec.LetError, "The subject is not defined in the current scope!", fn -> | ||
Code.compile_quoted(@code3) | ||
end | ||
test "runs ex1 then ex3", context do | ||
example = ESpec.ExampleRunner.run(context[:ex1]) | ||
assert example.status == :success | ||
|
||
example = ESpec.ExampleRunner.run(context[:ex3]) | ||
assert example.status == :failure | ||
assert example.error.message =~ "The subject is not defined in the current scope!" | ||
end | ||
|
||
test "runs ex1 then ex4", context do | ||
example = ESpec.ExampleRunner.run(context[:ex1]) | ||
assert example.status == :success | ||
|
||
example = ESpec.ExampleRunner.run(context[:ex4]) | ||
assert example.status == :failure | ||
assert example.error.message =~ "The subject is not defined in the current scope!" | ||
end | ||
|
||
test "runs ex6 then ex5", context do | ||
example = ESpec.ExampleRunner.run(context[:ex6]) | ||
assert example.status == :success | ||
|
||
example = ESpec.ExampleRunner.run(context[:ex5]) | ||
assert example.status == :failure | ||
assert example.error.message =~ "The subject is not defined in the current scope!" | ||
end | ||
end |