2011-01-30 37 views
4
assert_nothing_raised do 
    @board.make_move(0,0,Board::HUMAN) 
end 

和文檔說:Ruby:我如何使用assert_nothing_raised?

Passes if block does not throw anything. 

Example: 

assert_nothing_thrown do 
    [1, 2].uniq 
end 

我make_move方法:

def make_move(x, y, player) 
    return false 
end 

我得到的錯誤:

test_can_make_valid_move_in_the_first_row(BoardTest): 
ArgumentError: wrong number of arguments (1 for 2) 
+0

什麼測試框架您使用的? Ruby自己的單元/測試? [MINITEST](https://github.com/seattlerb/minitest)?還有別的嗎? – Phrogz 2011-01-30 16:18:42

回答

4

這下面的代碼爲我工作。對你起作用嗎?

require 'test/unit' 
require 'test/unit/ui/console/testrunner' 

class MyTestClass < Test::Unit::TestCase 
    def test_something 
    assert_nothing_raised do 
     p 'hi' 
    end 
    end 
end 

Test::Unit::UI::Console::TestRunner.run(MyTestClass) 

我想你正在使用assert_nothing_raised正確。試着用一些更簡單的更換

@board.make_move(0,0,Board::HUMAN) 

,像

p 'hi' 

,看看是否可行。也可以嘗試註釋掉測試中的所有其他代碼。