我需要测试以下行:
result = handle(streamOfMessages)
Wheremessages
和context
是填充良好的哈希值。我可以这样写it
:
messages1 = [ {"type"=>"someType1","value"=>"someBigHash1"}, {"type"=>"someType2","value"=>"someBigHash2"}, {"type"=>"someType1","value"=>"someBigHash3"} ]
result1 = handle(messages1)
result1.should == [someValue1, someOtherValue1]
messages2 = [ {"type"=>"someType1","value"=>"someBigHash1"}, {"type"=>"someType2","value"=>"someBigHash2"}, {"type"=>"someType1","value"=>"someBigHash3"} ]
result2 = handle(messages1)
result2.should == [someValue2, someOtherValue2]
// same about messages3, result3 etc
messages[i]
我可以制作一个数组数组并在循环中引用。然而,在我看来,这一切都是一种非常古老的方法,因此我正在寻找一种更具启发性(或者我什至应该说是基于DSL)的编程风格。如果有更好的语法来构造消息流和迭代多个流同时期望不同的结果,那就太好了。