这是我的规范的片段:
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)>'