Hi Jose,
Good point! I actually didn't pay much attention to the behavior testing part because the code that was pointing out the use case was the one that was commented out. So, here goes another try. What do you think about the following code?
By the way, I really appreciate you taking out the time to look at the code. I know you have a packed schedule. :)
# This test should sufficiently test Behavior module's functions and use cases
defmodule BehaviorTest do
use ExUnit.Case
defmodule TestWithFun do
use Behavior, fun: :test
end
defmodule TestWithoutFun do
use Behavior
end
describe "__using__/1" do
test "defines static functions along with `fun/0 `is no fun provided" do
assert TestWithoutFun.__some_function__() == :something
assert TestWithoutFun.__some_other_function__() == :something
assert TestWithoutFun.fun() == :fun
end
test "defines static functions along with `test/0 ` when fun is :test" do
assert TestWithFun.__some_function__() == :something
assert TestWithFun.__some_other_function__() == :something
assert TestWithFun.test() == :fun
end
end
end
defmodule TestSubject1Test do
use ExUnit.Case
# This test is re-testing `Behavior.__using__/1` instead of just testing
# its usage
describe "uses Behavior" do
test "defines static functions along with `fun1/0`" do
assert TestSubject1.__some_function__() == :something
assert TestSubject1.__some_other_function__() == :something
assert TestSubject1.fun1() == :fun
end
end
# `@__using__` attribute will allow us to do something like this, instead
# of testing `Behavior.__using__/1` again.
# describe "use Behavior" do
# test "uses Behavior with fun option" do
# uses = TestSubject1.__info__(:attributes)[:__using__]
#
# assert {Behavior, [fun: :fun1]} in uses
# end
# end
end
## --- More tests for TestSubject2, TestSubject3 and TestSubject4
```
Now that we have tested how `Behavior.__using__/1` behaves (by calling the actual functions), testing whether `TestSubject1` has correct attributes set should be sufficient, right?