I am new to rails and rspec, and currently taking an online a tutorial.
In the tutorial I am running the following code:
def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{board[8]} "
end
board = [" "," "," "," "," "," "," "," "," "]
display_board(board)
When I run the test I get the following output:
/lib/display_board.rb
defines a method display_board
#display_board method
represents a cell as a string with 3 spaces (FAILED - 1)
Failures:
1) /lib/display_board.rb #display_board method represents a cell as a string with 3 spaces
Failure/Error:
def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{board[8]} "
end
ArgumentError:
wrong number of arguments (0 for 1)
# ./lib/display_board.rb:2:in `display_board'
# ./spec/display_board_spec.rb:10:in `block (4 levels) in <top (required)>'
# ./spec/spec_helper.rb:5:in `capture_puts'
# ./spec/display_board_spec.rb:10:in `block (3 levels) in <top (required)>'
Finished in 0.00296 seconds (files took 0.14604 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/display_board_spec.rb:9 # /lib/display_board.rb #display_board method represents a cell as a string with 3 spaces
The test case is as follows:
it 'represents a cell as a string with 3 spaces' do
output = capture_puts{ display_board }
expect(output).to include(" ")
end
Where line 10 is the spec file is "output = capture_puts{ display_board }"
And "capture_puts" is defined in the spec_helpr.rb as follows:
def capture_puts
begin
old_stdout = $stdout
$stdout = StringIO.new('','w')
yield
$stdout.string
ensure
$stdout = old_stdout
end
end
I searched for the error "wrong number of arguments (0 for 1)", but I didn't get any useful result. Please advice since I am really a beginner with Ruby and Rails.