-
Notifications
You must be signed in to change notification settings - Fork 36
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
Decouple from ExUnit #96
Changes from 8 commits
d5c335e
d118285
3d29a04
014d60d
5321724
b460865
0406f93
4289bb8
fdb265a
71feb48
0ecc42c
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 |
---|---|---|
|
@@ -6,10 +6,13 @@ defmodule WhiteBread.Context do | |
@step_keywords [:given_, :when_, :then_, :and_, :but_] | ||
|
||
@doc false | ||
defmacro __using__(_opts) do | ||
defmacro __using__(opts \\ []) do | ||
opts = Keyword.merge [test_library: :ex_unit], opts | ||
[test_library: test_library] = opts | ||
|
||
quote do | ||
import WhiteBread.Context | ||
import ExUnit.Assertions | ||
unquote(import_test_library test_library) | ||
|
||
@behaviour WhiteBread.ContextBehaviour | ||
|
||
|
@@ -110,5 +113,15 @@ defmodule WhiteBread.Context do | |
end | ||
end | ||
|
||
|
||
defp import_test_library(test_library) do | ||
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. Yes, this is a function that returns a quoted block. It seemed like the right thing here, but I'm open to other ideas (considering I'm a relative beginner in Elixir...). 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. Seems a sensible approach to me here. It's relatively easy to follow what it's doing. 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 realized that I don't know the answer to this question: if macros are evaluated at compile time, will the fact that this is a function cause any problems? (It's been working well for me, but I just want to make sure that I didn't stumble into an Elixir gotcha.) |
||
case test_library do | ||
:ex_unit -> quote do: import ExUnit.Assertions | ||
:espec -> quote do | ||
require ESpec | ||
use ESpec | ||
end | ||
nil -> quote do: true | ||
_ -> raise ArgumentError, ":test_library must be one of :ex_unit, :espec, or nil." | ||
end | ||
end | ||
end |
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.
One small change request. Can this be pulled out as
@default_test_library
so that we haveand further up the file:
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.
That sounds like a good idea.