Sha256: e5f35f7443b52d2de43082b6ebdb1fa90c4556d6696e451d6006cff5ec6d6d9a

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

require 'spec'
require 'craps'

class CrapsSpecification < Spec::Context

  def setup
    @die1 = Mock.new
    @die2 = Mock.new
    @game = Craps.new(@die1, @die2)
  end
  
  def teardown
    @die1.__verify
    @die2.__verify
  end
  
  # coming out roll of 7
  
  def come_out_roll_of_1_6_wins
    _load_dice([1], [6])
    @game.play.should_be_true
  end

  def come_out_roll_of_2_5_wins
    _load_dice([2], [5])
    @game.play.should_be_true
  end

  def come_out_roll_of_3_4_wins
    _load_dice([3], [4])
    @game.play.should_be_true
  end

  def come_out_roll_of_4_3_wins
    _load_dice([4], [3])
    @game.play.should_be_true
  end

  def come_out_roll_of_5_2_wins
    _load_dice([5], [2])
    @game.play.should_be_true
  end  

  def come_out_roll_of_6_1_wins
    _load_dice([6], [1])
    @game.play.should_be_true
  end

  # coming out roll of 11
  
  def come_out_roll_of_5_6_wins
    _load_dice([5], [6])
    @game.play.should_be_true
  end

  def come_out_roll_of_6_5_wins
    _load_dice([6], [5])
    @game.play.should_be_true
  end
  
  # coming out roll of 2
  
  def come_out_roll_of_1_1_looses
    _load_dice([1], [1])
    @game.play.should_be_false
  end
  
  # coming out roll of 3
  
  def come_out_roll_of_1_2_looses
    _load_dice([1], [2])
    @game.play.should_be_false
  end

  def come_out_roll_of_2_1_looses
    _load_dice([2], [1])
    @game.play.should_be_false
  end

  # coming out roll of 12
  
  def come_out_roll_of_6_6_looses
    _load_dice([6], [6])
    @game.play.should_be_false
  end
  
  # loosing with a point
  
#  def second_roll_of_7_looses
#    _load_dice([2, 4], [2, 3])
#    @game.play.should_be_false
#  end
  
  # support

  def _load_dice(rolls1, rolls2)
    _load_die(@die1, rolls1)
    _load_die(@die2, rolls2)
  end
  
  def _load_die(die, rolls)
    rolls.each {| each | die.__expects(:roll).once.with_no_args.returns(each) }
  end
  
end

if __FILE__ == $0
  runner = Spec::TextRunner.new($stdout)
  runner.run(CrapsSpecification)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-0.1.5 examples/craps_spec.rb
rspec-0.1.6 examples/craps_spec.rb