使用 minitest 找到本教程,并想知道 rspec 中是否有等效的匹配器:
Interesting minitest assertion
describe "default attributes" do
it "must include httparty methods" do
Dish::Player.must_include HTTParty
end
it "must have the base url set to the Dribble API endpoint" do
Dish::Player.base_uri.must_equal 'http://api.dribbble.com'
end
end
最佳答案
测试一个类是否包含一个模块通常是错误的,因为您正在测试实现细节而不是预期的行为。
可以通过调用 ancestors
找到包含的模块在类里面,所以你可以简单地使用include
匹配器:
expect(Dish::Player.ancestors).to include(HTTParty)
您的第二个期望应该通过以下方式进行测试:expect(Dish::Player.base_uri).to eq 'http://api.dribbble.com'
编辑 直到今天我才知道类实现了
<=>
运算符(operator)。您可以简单地检查 Dish::Player < HTTParty
.
关于ruby - 是否有 rspec 匹配器来确认一个类是否包含库、模块或 gem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17176671/