【发布时间】:2018-09-25 21:29:10
【问题描述】:
Rspec 支持组合匹配器。它提供的组成匹配器列表是这样的:
all(matcher)
include(matcher, matcher)
start_with(matcher)
end_with(matcher)
contain_exactly(matcher, matcher, matcher)
match(matcher)
change {}.from(matcher).to(matcher)
change {}.by(matcher)
所有组合匹配器非常直观。您可以将匹配器传递给组合匹配器,并且传递的匹配器必须返回 true 才能使期望为 true:
expect(@items).to all(be_visible & be_in_stock)
但我不确定 start_with 和 end_with 组成匹配器。看这个例子:
fruits = ['apple', 'banana', 'cherry']
expect(fruits).to start_with( start_with('a') )
在这个例子中,外层和内层 start_with 做了什么?
【问题讨论】: