I am new to Rspec and I want to create a rspec example for a method which prints a 2d array.
Method which prints the array:
def print_array
array.each do |row|
row.each do |cell|
print cell
end
puts
end
end
For example, the result from the above code could be:
0 0 0
0 0 0
0 0 0
So I want to create an expectation(rspec) for the above method.
I tried to check the puts and print (STDOUT) but didn't work:
it "prints the array" do
...
expect(STDOUT).to receive(:puts).with("0 0 0 ...")
obj.print_array
end
Is there any way to test what exactly is printed out?