0

好的,rspec noob 在这里...我有一个简单的方法,我想测试一下。我只是想让测试说......当这个方法被调用时,它返回一个符号......任何指针?

方法....

  def defend_corners(board)
    @board = board
    @corners = {
        :a1=>" ", :a3=>" ",
        :c1=>" ", :c3=>" "
    }
    available_moves = @corners.select{ |k, v| v == " " }.keys
    puts "random move - corners"
    @move = available_moves[rand(available_moves.length)]
    return @move
  end

目前的测试......

  describe 'defend_corners' do
    it 'returns corner move' do
      myboard = Board.new

      @player_computer.defend_corners(myboard).should #return a symbol???
    end  
  end
4

3 回答 3

1
@player_computer.defend_corners(myboard).should be_an_instance_of(Symbol)

或者

@player_computer.defend_corners(myboard).should be_a_kind_of(Symbol)

或者

@player_computer.defend_corners(myboard).should be_a(Symbol)
于 2012-10-20T06:24:57.023 回答
0

这不漂亮,但我认为这样的工作:

@corners.keys.should_be include @player_computer.defend_corners(myboard)
于 2012-10-20T04:29:48.097 回答
0

2.5 小时后,答案是 (drum roll)....be_a(Symbol)

于 2012-10-20T05:24:43.603 回答