thefonso
thefonso

Reputation: 3390

rspec how to test call to specific method in external class

So I've got a method in a game class...

def drawgrid
  @board.draw
end

I want to write a test that verifies that drawgrid calls @board.draw

My current test looks like this....

  describe 'drawgrid method' do
    it 'should call @board.drawgrid' do

      @game.drawgrid.should be_true

      @game.drawgrid
    end
  end

Is this the best/ideal way to write this? Is there a better way?

Am I doing this right?

This seems nebulous to me.

Upvotes: 0

Views: 149

Answers (1)

Alcides Queiroz
Alcides Queiroz

Reputation: 9576

Use should_receive for this:

@board.should_receive(:draw)

Upvotes: 2

Related Questions