Search code examples
twitterelixirtddstub

Using Mox to stub multiple Cursor responses from ExTwitter


I'm trying to find a way to realistically-ish stub an ExTwitter method that returns a Cursor so that I can test recursively fetching data, rate limiting, etc.

I've created a behavior with the relevant callback, and I'm trying to use Mox to stub the friends method. It seems like I'm not understanding the way pattern matching works with list arguments though because the second stub is overriding the first rather than matching both calls sequentially.

@twitter_client
|> stub(:friends, fn _handle, [cursor: -1, count: _count] ->
  %ExTwitter.Model.Cursor{
    items: [active_user, inactive_user],
    next_cursor: 1,
    previous_cursor: -1
  }
end)

@twitter_client
|> stub(:friends, fn _handle, [cursor: 1, count: _count] ->
  %ExTwitter.Model.Cursor{
    items: [active_user, inactive_user],
    next_cursor: 0,
    previous_cursor: 1
  }
end)

Solution

  • Please note that stub/3 will overwrite any previous calls to stub/3 in the stub doc.