-
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
Conversation
@@ -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 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.)
@marnen I really like this approach. I actually now regret defaulting to always importing |
lib/white_bread/context.ex
Outdated
@@ -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 |
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 have
opts = Keyword.merge [test_library: @default_test_library], opts
and further up the file:
@step_keywords [:given_, :when_, :then_, :and_, :but_]
@default_test_library :ex_unit
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.
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 comment
The 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.
I think this is probably ready to merge now. |
WhiteBread.Context brings in ExUnit.Assertions, which was conflicting with the ESpec functions that I want to use in my steps. So I made the test library configurable, defaulting to ExUnit.
Really, though, I only did it this way to avoid breaking existing behavior. In the longer term, I don't actually think that WhiteBread.Context should import a testing library at all out of the box. I'd rather see something like this:
What do you think?