【发布时间】:2016-05-23 07:00:34
【问题描述】:
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) 中存根。
因此,我无法在stub_request 中指定sms_uid,因为在调用存根后会生成随机的sms_uid。这会导致测试每次都失败。有没有办法可以在生成代码后(换句话说,在它通过特定方法之后)存根请求,或者有没有办法存根通过域“https://api.silverstreet.com”的所有请求?
【问题讨论】:
-
您将此添加到哪个规范文件中?
标签: ruby-on-rails ruby rspec webmock