Sha256: d1d0f75650c955e94ae76616ce4796ded939f5d4c707d21b93fdbe81d420bca6

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require File.join(File.dirname(__FILE__), ".." ,"spec_helper" )

module Elus
  include ElusTest

  describe Rule do
    context 'creating' do
      it 'should create appropriate Rules given correct arguments' do
        RULES.each do |args, name|
          rule = Rule.new(*args)
          rule.name.should == name
        end
      end
      it 'should fail if given wrong arguments' do
        WRONG_RULES.each do |args|
          lambda{Rule.new(*args)}.should raise_error(Invalid)
        end
      end
    end
    context 'applying Rule to Pieces' do
      it 'should produce expected outcome when applied to any Piece' do
        all_chars_twice('01.') do |piece, condition|
          p =  Piece.create(piece)
          c =  Piece.create(condition)
          random_chars_twice 100 do |yes, no|
            y =  Piece.create(yes)
            n =  Piece.create(no)
            rule = Rule.new(c, y, n)
            if p == c
              should_be_equal(rule.apply(p), p * y)
            else  
              should_be_equal(rule.apply(p), p * n)
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elus-0.1.0 spec/elus/rule_spec.rb