dojo-toulouse / elixir-koans

Small exercises to discover elixir by testing
249 stars 61 forks source link

Issue in "Assertions are smart" #19

Closed MarcosX closed 9 years ago

MarcosX commented 9 years ago

Hi all, I'm pretty new to Elixir and using this Koans to learn more about the language and I stumbled on the following issue (while meditating about "Assertions are smart"):

Here is an example of changes I've made in my local copy

    think "Assertions are smart" do
        is_1_equal_2? = fn -> assert 1 == 2 end
        is_1_greater_than_2? = fn -> assert 1 > 2 end

        #This works:
        message = "Assertion with " <> "==" <> " failed"
        assert_raise ExUnit.AssertionError, message, is_1_equal_2?

        #This doesn't:
        message = "Expected 1 to be " <> __? <> " 2"
        assert_raise ExUnit.ExpectationError, message, is_1_greater_than_2?
    end

Looking at the code for version 1.0.4 (which is what I have now), it seems like we might need to update.

  def assert(value, message) when is_binary(message) do
    assert(value, message: message)
  end

  def assert(value, opts) when is_list(opts) do
    unless value, do: raise(ExUnit.AssertionError, opts)
    true
  end

from https://github.com/elixir- lang/elixir/blob/a3dd9e247375bd99dbac115cdd6d11f08d71952f/lib/ex_unit/lib/ex_unit/assertions.ex

Let me know what you all think and I can make a PR if needed :)

apieum commented 9 years ago

Hi, thank you. I've made these koans for one dojo to test elixir, then I've never had the time to improve and maintain it or develop something else with elixir. Others have done, but probably you're going to find bugs as I accept PR without testing them and because elixir has evolved a lot since our dojo.

Your code seems good, just don't forget to replace "==" by __?