当前位置

网站首页> 程序设计 > 开源项目 > 编程语言 > 浏览文章

HTTP 交互模拟库 VCR

作者:小梦 来源: 网络 时间: 2024-06-20 阅读:

VCR 是 Ruby 开发的一个用于简化 HTTP 交互测试的工具包。

示例代码:

require 'rubygems'require 'test/unit'require 'vcr'VCR.configure do |c|  c.cassette_library_dir = 'fixtures/vcr_cassettes'  c.hook_into :webmock # or :fakewebendclass VCRTest < Test::Unit::TestCase  def test_example_dot_com    VCR.use_cassette('synopsis') do      response = Net::HTTP.get_response(URI('http://www.iana.org/domains/example/'))      assert_match /Example Domains/, response.body    end  endend

相关阅读

热点阅读

网友最爱