使用分体式客户机 gem 分体式 io stub 请求问题

问题描述 投票:0回答:1

我已经用split_client gem做了AB测试的split io(https:/help.split.iohcen-usarticles360020673251-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

但在运行测试后,我还是会随机出现错误。那么是什么原因导致了这个问题,有什么替代方案或解决办法。

ruby ab-testing
1个回答
0
投票

我认为你应该明确地禁用http请求。在我的例子中,我使用了 webmock 和我写的。

setup do
    WebMock.enable!
  end

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

© www.soinside.com 2019 - 2024. All rights reserved.