-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d5c335e
Allow choise of test libraries.
marnen d118285
Handle other cases.
marnen 3d29a04
Fix syntax error.
marnen 014d60d
Require the module before we use it. :)
marnen 5321724
Move case statement out of macro.
marnen b460865
Extract function.
marnen 0406f93
Remove diagnostic output.
marnen 4289bb8
Document the new option.
marnen fdb265a
Merge branch 'master' into decouple-from-exunit
marnen 71feb48
Put test library into an attribute.
marnen 0ecc42c
Improve error message.
marnen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -4,12 +4,16 @@ defmodule WhiteBread.Context do | |
alias WhiteBread.Context.Setup | ||
|
||
@step_keywords [:given_, :when_, :then_, :and_, :but_] | ||
@default_test_library :ex_unit | ||
|
||
@doc false | ||
defmacro __using__(_opts) do | ||
defmacro __using__(opts \\ []) do | ||
opts = Keyword.merge [test_library: @default_test_library], 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 +114,15 @@ defmodule WhiteBread.Context do | |
end | ||
end | ||
|
||
|
||
defp import_test_library(test_library) do | ||
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, "#{inspect test_library} is not a recognized value for :test_library. Recognized values are :ex_unit, :espec, and nil." | ||
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 also made the error message a little clearer here by printing the bad value. |
||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The 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.)