4

有没有办法模拟 Curb 的 Easy.perform 方法进行单元测试?我使用它来访问 Facebook 的图形 API,并且没有一个 http 模拟库似乎支持 Curb。

这里最好的方法是什么?

4

2 回答 2

3

WebMock 最近添加了遏制支持。:)

http://github.com/bblimke/webmock

于 2010-10-14T02:15:57.413 回答
0

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

被描述成:

FakeWeb 是 Ruby 中伪造 Web 请求的助手。它在全球范围内工作,无需修改代码或编写大量存根

来自github 存储库的示例:

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
于 2010-08-01T17:29:02.900 回答