首页 > 解决方案 > 拆分客户端 gem 的拆分 io 存根请求问题

问题描述

我已经使用 Ruby SDK 设置了用于 AB 测试的 split_client gem 拆分 io(https://help.split.io/hc/en-us/articles/360020673251-Ruby-SDK),我正在接受治疗应用。但是当我尝试运行测试时,我遇到了错误

stub_request(:post, "https://events.split.io/api/metrics/time").
  with(
    body: "{\"name\":\"splitChangeFetcher.time\",\"latencies\":[292.122]}",
    headers: {
      'Accept'=>'*/*',
      'Accept-Encoding'=>'gzip,deflate',
      'Authorization'=>'Bearer 4354t',
      'Connection'=>'keep-alive',
      'Content-Type'=>'application/json',
      'Keep-Alive'=>'30',
      'Splitsdkmachineip'=>'0.0.0.1',
      'Splitsdkmachinename'=>'local',
      'Splitsdkversion'=>'ruby-7.0.3',
      'User-Agent'=>'Ruby'
    }).
  to_return(status: 200, body: "", headers: {})

我试图在 spec_helper 中存根这个请求,如下所示

config.before :each do
    stub_request(:any, /events.split.io/)
      .to_return(status: 200, body: "", headers: {})
  end

但是在运行测试后我仍然随机收到错误。那么可能导致此问题的原因以及任何替代方案或解决方案。

标签: rubyab-testing

解决方案


我认为您应该明确禁用 http 请求。就我而言,我使用webmock并写道:

setup do
    WebMock.enable!
  end

这只是对下一个搜索解决方案的建议。


推荐阅读