使用 Mox 存根来自 ExTwitter 的多个 Cursor 响应

Using Mox to stub multiple Cursor responses from ExTwitter

我正在尝试找到一种方法来真实地存根一个 ExTwitter 方法,该方法 returns 一个游标,以便我可以测试递归获取数据、速率限制等。

我已经用相关的回调创建了一个行为,我正在尝试使用 Mox 来存根 friends 方法。似乎我不理解模式匹配与列表参数一起工作的方式,因为第二个存根覆盖了第一个存根而不是顺序匹配两个调用。

@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)

请注意 stub/3 will overwrite any previous calls to stub/3stub doc.