【发布时间】:2017-09-20 08:52:00
【问题描述】:
我希望能够为端点响应测试远程 3d 方 API,这就是为什么我想编写一堆本地 rspec 测试并定期启动它们,以查看这些端点是否按预期工作没有重大变化。由于我的应用程序高度依赖于这个不断变化的 API,我别无选择,只能自动化我的测试。
目前我拿了一个常规的rspec API测试代码:
require "rails_helper"
RSpec.describe "Remote request", type: :request do
describe ".send request" do
it ".posts valid data" do
post "http://123.45.67.89/api/endpoint",
params: {
"job_request_id": 123456,
"data": "12345",
"app_secret": "12345",
"options": {
...
}
}
expect(JSON.parse response.body).to include("message" => "success")
expect(response).to have_http_status(200)
end
end
end
此代码的问题在于 Rspec 访问的是 /api/endpoint url,而不是完整的 http://123.45.67.89/api/endpoint url。我该如何改变这种行为?
【问题讨论】:
标签: ruby-on-rails rspec