输出匹配器预期块但不是块

时间:2017-03-29 19:34:49

标签: rspec

这是我的规范的片段:

context“给定数组[1,2,3]和阻止{| e |把e,如果e == 1}”“做

subject { Array.new([1,2,3]) }

it "prints out 1 and returns [1,2,3]" do
  expect(subject.my_each { |e| puts e if e == 1 }).to output("1\n").to_stdout
  expect(subject.my_each { |e| puts e if e == 1 }).to eql([1,2,3])
end

这是Rspec输出:

1).my_each给定数组[1,2,3]和块{| e |如果e == 1}打印出1并返回[1,2,3]      失败/错误:期望(subject.my_each {| e |把e,如果e == 1})。输出(“1 \ n”)。to_stdout

   expected block to output "1\n" to stdout, but was not a block
   Diff:
   @@ -1,2 +1 @@
   -1

 # ./spec/enumerable_spec.rb:30:in `block (3 levels) in <top (required)>'

1 个答案:

答案 0 :(得分:0)

根据this,我改变了对此的期望: 期待{subject.my_each {| e |如果e == 1}}。输出(“1 \ n”)。to_stdout