Sha256: f353f1d2f8391ddb902b4ad25545c8b2d25eab8a66d5f555b95d4fffb1619c5d

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

require 'helpers'

describe GamesDice::RerollRule do

  describe "#new" do

    it "should accept self-consistent operator/value pairs as a trigger" do
      GamesDice::RerollRule.new( 5, :>, :reroll_subtract )
      GamesDice::RerollRule.new( (1..5), :member?, :reroll_replace )
    end

    it "should reject inconsistent operator/value pairs for a trigger" do
      lambda { GamesDice::RerollRule.new( 5, :member?, :reroll_subtract ) }.should raise_error( ArgumentError )
      lambda { GamesDice::RerollRule.new( (1..5), :>, :reroll_replace ) }.should raise_error( ArgumentError )
    end

    it "should reject bad re-roll types" do
      lambda { GamesDice::RerollRule.new( 5, :>, :reroll_again ) }.should raise_error( ArgumentError )
      lambda { GamesDice::RerollRule.new( (1..5), :member?, 42 ) }.should raise_error( ArgumentError )
    end

  end

  describe '#applies?' do

    it "should return true if a trigger condition is met" do
      rule = GamesDice::RerollRule.new( 5, :>, :reroll_subtract )
      rule.applies?(4).should be_true

      rule = GamesDice::RerollRule.new( (1..5), :member?, :reroll_subtract )
      rule.applies?(4).should be_true
    end

    it "should return false if a trigger condition is not met" do
      rule = GamesDice::RerollRule.new( 5, :>, :reroll_subtract )
      rule.applies?(7).should be_false

      rule = GamesDice::RerollRule.new( (1..5), :member?, :reroll_subtract )
      rule.applies?(6).should be_false
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
games_dice-0.3.11 spec/reroll_rule_spec.rb
games_dice-0.3.10 spec/reroll_rule_spec.rb