我正在编写一个充当远程 API 客户端的 gem,因此我使用 webmock 来模拟远程 API,并使用带有 rspec-mock 的 Cucumber 进行测试。
作为我的 Cucumber 测试的一部分,我打算在一个子句中存根我的 API,Given
但是我想指定在一个Then
子句中调用远程 API。
一个非常基本的例子是:
特征文件
Scenario: Doing something that triggers a call
Given I have mocked Google
When I call my library
Then it calls my Google stub
And I get a response back from my library
步骤定义
Given /I have mocked my API/ do
stub_request(:get, 'www.google.com')
end
When /I call my library/ do
MyLibrary.call_google_for_some_reason
end
Then /it calls my Google stub/ do
# Somehow test it here
end
问题: 如何验证我的谷歌存根已被调用?
旁注:我知道我可以使用expect(a_request(...))
orexpect(WebMock).to ...
语法,但我的感觉是我将重复我的Given
子句中定义的内容。