由于测试的原因,我最近移动了一些RSpec匹配器来使用类形式而不是DSL。当他们处于这种形式时,是否可以轻松获得链式行为?链接Rspec自定义匹配器
E.g.
class BeInZone
def initialize(expected)
@expected = expected
end
def matches?(target)
@target = target
@target.current_zone.eql?(Zone.new(@expected))
end
def failure_message
"expected #{@target.inspect} to be in Zone #{@expected}"
end
def negative_failure_message
"expected #{@target.inspect} not to be in Zone #{@expected}"
end
# chain methods here
end
非常感谢
你可以给你一个你想能够做的链式方法调用的例子吗? – 2013-05-02 13:28:14