2013-08-29 80 views
0

鑑於此代碼:rspec的 - 錯誤的參數數目(0 1..2)

class Game 

    def self.game_board 
    return [[][][]] 
    end 
    def self.empty_output 
    '_|_|_'+ 
    '_|_|_'+ 
    ' | |' 
    end 
end 

並且這些測試:

describe 'It should display a grid' do 
    it 'should have empty output' do 
    Game.empty_output.should == 
    '_|_|_'+ 
    '_|_|_'+ 
    ' | |' 
    end 
    it 'should have an empty array for the game ' do 
    Game.game_board.should == 
    [[][][]] 
    end 
end 

爲什麼測試失敗,試圖返回數組與錯誤

.F 

Failures: 

    1) "It should display a grid should be empty 
    Failure/Error: return [[][][]] 
    ArgumentError: 
     wrong number of arguments (0 for 1..2) 
    # ./checkers_rspec.rb:4:in `[]' 
    # ./checkers_rspec.rb:4:in `game_board' 
    # ./checkers_rspec.rb:24:in `block (2 levels) in <top (required)>' 

Finished in 0.00121 seconds 
2 examples, 1 failure 
+3

是'[[] [] []]'即使有效語法陣列?不應該讀取'[[],[],[]]'? – Zajn

+0

是的,+1 Zajn :) –

+0

任何人想解釋錯誤信息? ;-)(在最簡單的情況下輸入'[] []'到irb) –

回答

0
[[][][]] should hae been [[],[],[]] in both cases. 
相關問題