here is a snippet from my spec:
context "Given array [1,2,3] and block {|e| puts e if e == 1}" do
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
end
here is the Rspec output:
1) .my_each Given array [1,2,3] and block {|e| puts e if e == 1} prints out 1 and returns [1,2,3] Failure/Error: expect(subject.my_each { |e| puts e if e == 1 }).to output("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)>'