ruby - 拆分客户端 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
但是在运行测试后我仍然随机收到错误。那么可能导致此问题的原因以及任何替代方案或解决方案。
解决方案
我认为您应该明确禁用 http 请求。就我而言,我使用webmock
并写道:
setup do
WebMock.enable!
end
这只是对下一个搜索解决方案的建议。
推荐阅读
- python - ValueError:int() 的无效文字,基数为 10:'PKL567'
- cassandra-jdbc - cassandra jdbc 的驱动程序
- python - 如何将 s3 amazon 连接到您的 django 项目?
- json - xml 到 json 的转换 - 用于 [[]] 的附加方括号,用于 lineitems 和 line item
- flutter - 是否允许在底页颤动中创建超过 1 个下拉菜单?我收到一个错误
- javascript - 将 react-booking-calendar 的语言环境设置为另一种语言
- apache-kafka - 重启集群或操作系统后的kafka删除所有连接器
- c++ - 如果传递的参数是 nullptr,如何调用类型 T 的默认构造函数?
- go - 将 interface{} 转换为结构
- email - Apps 脚本 - 将附件添加到电子邮件确认