def some_method condition
actual = [1,2,3]
expected = include(1)
matcher = lambda {|condition|
if condition == "YES"
return RSpec::Matcher.should
else
return RSpec::Matcher.should_not
end}
actual.matcher.call(condition) expected
end
如何根据解析到方法中的条件动态制作一个should或should_not匹配器?
答案 0 :(得分:1)
我认为你的意思是:
def some_method condition
actual = [1,2,3]
expected = include(1)
matcher = lambda {|condition|
if condition == "YES"
:should
else
:should_not
end}
actual.send(&matcher.call(condition), expected)
end
这将在实际结果上调用方法should
或should_not
。
另一方面,我很难看到什么时候这是一个好主意...单元测试应该是确定性的和可读的,这个想法使它们两者都不那么......