我的应用程序使用API创建了一个github gist。我需要用rspec模拟对API的请求。我正在使用webmock gem,但我不太明白如何在我的应用程序中使用它。我需要一点帮助才能开始。
这是我的spec/Git_Request_spec.rb
require_relative '../Gist_Request.rb'
require 'spec_helper'
RSpec.describe GistRequest do
describe "#post" do
it "crear gist" do
filename = "test.txt"
description = "descripción"
state = true
content = "contenido"
gist_create = GistRequest.new(description, state, filename, content)
gist_create.post()
expect(gist_create.response_status).to eq "201"
end
it "campos no válidos" do
filename = "test.txt"
description = "descripción"
state = true
content = "contenido"
gist_create = GistRequest.new(filename, content, state, description)
gist_create.post()
expect(gist_create.response_status).to eq "422"
end
end
end有什么想法吗?
发布于 2020-03-13 12:06:20
您需要使用存根方法来模拟您与api的交互。
stub_request(:http_method, url).with(`your data in
request`).to_return(`what do you expect to receive in response`).https://stackoverflow.com/questions/60660516
复制相似问题