josephwilk / amrita

A polite, well mannered and thoroughly upstanding testing framework for Elixir
200 stars 28 forks source link

receive message checker #11

Open josephwilk opened 11 years ago

josephwilk commented 11 years ago

Add message checkers.

sideshowcoder commented 11 years ago

I am not really fluent in elixir yet but will give it a shot, just wanted to let you know somebody is working on this now :)

josephwilk commented 11 years ago

Brilliant, thanks! Let me know if you need any help and also feel free to be creative with the exact syntax.

sideshowcoder commented 11 years ago

Just trying to wrap my head around it, is this the way you would like to go or am I completly of track?

josephwilk commented 11 years ago

It looks nice, my only concern is with the error messaging.

Since the call received does not know the checker arguments when there is no message we cannot mention the expected message.

The current message is (which I think we can improve by creating a more specific fail function for messages:

received |> :hello

#Error message:
Expected to have received message |> received

When we do receive a message but it does not match the expected message the error would be one of equality and not related to the act of messaging. For example:

self <- { :hello }
received |> { :hello, "sir" }

#Fails with 
# { :hello } |> equal({ :hello, "sir" })

My thought is to delay execution of received in order to get a better error message.

At the moment received is executed immediately. We could instead make it return a function that then gets passed to some message matcher (or equality). Then the right hand side of the |> would be able to execute that function at its convince and importantly use the result to report an error message.

Roughly something like:

def received do
  fn (checker) ->  get_received |> checker end
end

#Easy
received |> msg { :hello }   # msg(received_fn, {:hello})

#Harder Since equal needs to support fns for comparison.
received |>  { :hello }  # equal(received_fn, {:hello})

Hope that makes some sense. Shout if you have any questions. Thanks.

sideshowcoder commented 11 years ago

Thanks for your time and great explanation you make I a great experience trying to help out here.

I was looking into modifying equals to work with functions as well but at first sight this seems like a more involved change so I would suggest handling this in a separate feature. Also at this first improvment passing checkers is not possible yet I'm gonna try to work this in just wanted to get my implementation suggestion out.