【发布时间】:2015-07-23 13:04:38
【问题描述】:
我正在编写一个充当远程 API 客户端的 gem,因此我使用 webmock 来模拟远程 API,并使用带有 rspec-mock 的 Cucumber 进行测试。
作为我 Cucumber 测试的一部分,我打算在 Given 子句中存根我的 API,但是我想指定在 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
问题: 如何验证我的 google 存根已被调用?
旁注:我知道我可以使用expect(a_request(...)) 或expect(WebMock).to ... 语法,但我的感觉是我会重复我在Given 子句中定义的内容。
【问题讨论】:
标签: ruby rspec cucumber webmock