Skip to content
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

Document how to create ExUnit tests for a responder #36

Closed
docteurklein opened this issue Mar 25, 2016 · 2 comments · Fixed by #37
Closed

Document how to create ExUnit tests for a responder #36

docteurklein opened this issue Mar 25, 2016 · 2 comments · Fixed by #37

Comments

@docteurklein
Copy link
Contributor

I'm currently having problems to create tests for my user-land responders.
I tried to copy Hedwig.Responders.HelpTest:

working responder example:

defmodule Edgar.Responder.ItIsSomething do

  @moduledoc """
  react to it's something
  """

  use Hedwig.Responder

  @usage """
  <text> (it's something) - react to this text with an image
  """
  hear ~r/it's something/i, msg do
    send msg, "http://i3.kym-cdn.com/photos/images/original/000/114/139/tumblr_lgedv2Vtt21qf4x93o1_40020110725-22047-38imqt.jpg"
  end
end

test

defmodule Edgar.Responder.ItIsSomethingTest do
  use Hedwig.RobotCase

  @tag start_robot: true, name: "edgar"
  test "it's something - replies with an image url", %{adapter: adapter, msg: msg} do
    send adapter, {:message, %{msg | text: "it's something"}}
    assert_receive {:message, %{text: text}}
    assert String.equals(text, "http://i3.kym-cdn.com/photos/images/original/000/114/139/tumblr_lgedv2Vtt21qf4x93o1_40020110725-22047-38imqt.jpg")
  end
end

result


  1) test it's something - replies with an image url (Edgar.Responder.ItIsSomethingTest)
     test/edgar/responder/it_is_something.exs:5
     No message matching {:message, %{text: text}} after 100ms.
     The process mailbox is empty.
     stacktrace:
       test/edgar/responder/it_is_something.exs:7

Hope my question is not too dumb :)
Cheers o/

@docteurklein
Copy link
Contributor Author

EDIT: I just noticed you recently (january :)) moved TestRobot and RobotCase in lib, which makes them available when downloaded from hex.
It resolves the module loading problem (I updated the issue accordingly), but i still get the same error concerning the empty mailbox.

@keathley
Copy link
Member

We sorted this out in Slack but I thought I would add the comments here for historical reasons. You're missing the responders: config in your @tag. It should read something like: @tag start_robot: true, name: "edgar", responders: [{YOUR_MODULE_NAME, []}].

It might be worthwhile to add some documentation about this in the README or in module docs to help others avoid this problem in the future. We also discussed defaulting to the mix config for responders but I'm not sure what the ramifications of that might be. @scrogson would know better then me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants