Sha256: 25198fdbd708670bd98c1adbe09e35526add1991c4963c0f12202528e305fc26

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

require 'spec'
require File.dirname(__FILE__) + '/craps'

class CrapsSpecification < Spec::Context

  def setup
    @die1 = mock "die1"
    @die2 = mock "die2"
    @game = Craps.new(@die1, @die2)
  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 { |roll| die.should_receive(:roll).once.with_no_args.and_return(roll) }
  end
  
end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-0.4.0 examples/craps_spec.rb