代码之家  ›  专栏  ›  技术社区  ›  Josiah Kiehl

模拟曲:简单。表演?(路边)

  •  4
  • Josiah Kiehl  · 技术社区  · 15 年前

    有没有一种方法可以轻松模拟路缘石。执行单元测试的方法?我使用它来访问Facebook的图形API,而HTTP模拟libs似乎都不支持遏制。

    这里最好的方法是什么?

    2 回复  |  直到 15 年前
        1
  •  3
  •   Josiah Kiehl    15 年前

    Webmock最近增加了对路缘石的支持。:)

    http://github.com/bblimke/webmock

        2
  •  0
  •   Jesse Wolgamott    15 年前

    我真的认为fakeweb是一个很好的伪造网络调用的方法;无论您使用什么HTTP库,您只需指定您想要接收的响应文本和代码。

    描述如下:

    fakeweb是伪造web的助手 Ruby中的请求。它在全球范围内工作 级别,不修改代码或 写大量的树桩

    示例来自 github repository :

    FakeWeb.register_uri(:get, "http://example.com/test1", :string => "Hello World!")
    
    Net::HTTP.get(URI.parse("http://example.com/test1"))
    => "Hello World!"
    
    Net::HTTP.get(URI.parse("http://example.com/test2"))
    => FakeWeb is bypassed and the response from a real request is returned