有没有办法模仿Curb的Easy.perform方法进行单元测试?我使用它来访问Facebook的图形API,并且没有任何http模拟库似乎支持Curb。
这里最好的方法是什么?
答案 0 :(得分:3)
WebMock最近添加了Curb支持。 :)
答案 1 :(得分:0)
我真的认为fakeWeb是伪造网络电话的好方法;无论您使用哪种HTTP库,您都只需指定要接收的响应文本和代码。
描述为:
FakeWeb是伪造网络的助手 Ruby中的请求。它在全球范围内运作 级别,无需修改代码或 写广泛的存根
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