1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
RSpec::Matchers.define :expand do |behavior = nil, values = {}|
values, behavior = behavior, nil if behavior.kind_of?(Hash)
match do |pattern|
@string ||= nil
begin
expanded = pattern.expand(behavior, values)
rescue Exception
false
else
@string ? @string == expanded : !!expanded
end
end
chain :to do |string|
@string = string
end
failure_message do |pattern|
message = "expected %p to be expandable with %p" % [pattern, values]
message << " (%p behavior)" % behavior if behavior
expanded = pattern.expand(behavior, values)
message << " and result in %p, but got %p" % [@string, expanded] if @string
message
end
failure_message_when_negated do |pattern|
"expected %p not to be expandable with %p" % [pattern, values]
end
end
|