config.before(:each) do
stub_request(:post, "https://api.3rdpartysmsprovider.com/send.php?body=This%20is%20a%20test%20message&destination=60123456789&dlr='1'&output=json&password=0000000&reference=#{@text.sms_uid}&sender=silver&username=0000000").
to_return(:status => 200, :body => "01", :headers => {})
end
我目前正在为发送 SMS 并在我们的数据库中创建它的日志的服务类编写规范。我正在尝试存根此请求,但@text.sms_uid
它是一个SecureRandom.urlsafe_base64
随机代码。我也在打架config.before(:each)
。
因此,我无法指定sms_uid
in,因为在调用存根后会生成stub_request
随机数。sms_uid
这会导致测试每次都失败。有没有一种方法可以在生成代码后(换句话说,在它通过特定方法之后)存根请求,或者有没有办法存根通过域的所有请求“ https://api.silverstreet.com “?