2015-03-05 3 views
0

Я пытаюсь объединить два пользовательских шаблона, используя ожидания блоков.RSpec .and and block expect

Это пример:

expect{puts "test"}.to matcher1.and matcher2 

И вот matchers:

RSpec::Matchers.define :matcher1 do |resource| 
    supports_block_expectations 

    match do |actual| 
    puts "before matcher1" 
    actual[] 
    puts "after matcher1" 
    true 
    end 
end 

RSpec::Matchers.define :matcher2 do 
    supports_block_expectations 

    match do |actual| 
    puts "before matcher2" 
    actual[] 
    puts "after matcher2" 
    true 
    end 
end 

И выход я получаю:

before matcher2 
before matcher1 
test 
after matcher1 
after matcher2 

В то время как я ожидал :

before matcher2 
test 
after matcher2 
before matcher1 
test 
after matcher1 

Почему мой пророк называется только один раз, и почему странное гнездование? Есть ли способ достичь того, чего я хочу, не повторяя блок?

ответ

0

Как указывалось в this reported issue, and не должен был быть таким образом, и помощники не должны использоваться для изменения поведения по предмету (как я пытался это сделать).