用于为 Web 请求注入虚假响应的 Ruby 测试辅助工具
= FakeWeb FakeWeb 是一个用于在 Ruby 中模拟 Web 请求的工具。它在全局范围内工作。 无需修改代码或编写大量的代码段。 == 安装
spec.add_development_dependency "fakeweb", ["~> 1.3"] == 帮助和讨论 当前版本的 RDocs 可在 http://fakeweb.rubyforge.org. 中找到 有一个邮件列表用于提问和讨论 https://groups.google.com/d/forum/fakeweb-users. 主要源仓库为 https://github.com/chrisk/fakeweb. {} [https://travis-ci.org/chrisk/fakeweb] FakeWeb 的测试在 https://travis-ci.org/chrisk/fakeweb. 运行 == 示例 首先要求 FakeWeb: require 'fakeweb' === 注册基本字符串响应 FakeWeb.register_uri(:get, "http://example.com/test1",", :body => "Hello World!") Net::HTTP.get(URI.parse("http://example.com/test1"")) => "Hello World!" Net::HTTP.get(URI.parse("http://example.com/test2"")) => FakeWeb 被绕过,并返回来自真实请求的响应
您还可以使用正则表达式调用 register_uri,以匹配多个 URI。
暂无开放 Issues,或尚未同步最近议题。