Testing a complicated method

I'm working on a checkers implementation where I have dozens of easily tested methods, but I'm not sure how to test my main #play_game method. Where most of my methods have easily determined inputs and outputs, and are, therefore, easy to test, this method is multifaceted and really doesn't have an easily discernible output. Here is the code:

def play_game
    puts @gui.intro

    while(game_over? == false)
      message = nil
      @gui.render_board(@board)
      @gui.move_request
      player_input = gets 
      coordinates = UserInput.translate_move_request_to_coordinates(player_input) 

      message = MoveCheck.move_validator(coordinates[0], coordinates[1], coordinates[2], coordinates[3])
      puts message unless (message.nil? or message == "jumping move")
      if(message == nil or message == "jumping move")
        @current_player = switch_player unless (message == "jumping move" and jump_available? == true)
      end
    end
    puts @gui.display_game_ending_message  
  end

So how can I test this (using RSpec) or should I not worry about it and really on my otherwise comprehensive testing?

Answers


All play_game is really doing is running the game loop. What you are really looking to test is what happens inside the game loop. The easiest way to do that is to break the content of the game loop down into more easily testable methods.

Once you have the game loop as just a series of methods, you can then much more easily test each of them in isolation.


Need Your Help

Unit Tests for comparing text files in NUnit

unit-testing nunit diff text-files

I have a class that processes a 2 xml files and produces a text file.

Inserting image in UITableView cell issue

iphone objective-c uitableview

sorry for the silly question, but I'm still in the process of learning Objective-C and iPhone programming.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.