我如何配置 stub_request 以获得响应代码 200
How can i config stub_request to get response code 200
我有一个请求,在响应中我使用了这个:
def get_request
...
return response.code == "200"
end
但是当我在规范中设置时:
stub_request(:get, 'https:domain.com/stock').to_return(status: 200)
我收到此错误:undefined method `code' for false:FalseClass
解决方案是在生产中添加一个包含响应数据的正文。
stub_request(:get, 'https:domain.com/stock')
.to_return(status: 200, body: JSON.generate(available: []))
我有一个请求,在响应中我使用了这个:
def get_request
...
return response.code == "200"
end
但是当我在规范中设置时:
stub_request(:get, 'https:domain.com/stock').to_return(status: 200)
我收到此错误:undefined method `code' for false:FalseClass
解决方案是在生产中添加一个包含响应数据的正文。
stub_request(:get, 'https:domain.com/stock')
.to_return(status: 200, body: JSON.generate(available: []))