Sha256: f57348809450f118cb908afea5842fd3dd6bc2d85116ca92fb9c313bbb5f051e

Contents?: true

Size: 1.77 KB

Versions: 14

Compression:

Stored size: 1.77 KB

Contents

require File.join(File.dirname(__FILE__), "../../spec_helper")
include Nudge


describe BoolEqualQInstruction do
  
  it_should_behave_like "every Nudge Instruction"
  
  before(:each) do
    @context = Interpreter.new
    @i1 = BoolEqualQInstruction.new(@context)
  end
  
  
  describe "\#go" do
    before(:each) do
      @i1 = BoolEqualQInstruction.new(@context)
      @bool1 = ValuePoint.new("bool", false)
    end

    describe "\#preconditions?" do
      it "should check that there are enough parameters" do
        2.times {@context.stacks[:bool].push(@bool1)}
        @i1.preconditions?.should == true
      end
      
      it "should raise an error if the preconditions aren't met" do
        @context.clear_stacks # there are no params at all
        lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
      end
      
      it "should successfully run #go only if all preconditions are met" do
        3.times {@context.stacks[:bool].push(@bool1)}
        @i1.should_receive(:cleanup)
        @i1.go
      end
    end
    
    describe "\#derive" do
      it "should pop all the arguments" do
        2.times {@context.stacks[:bool].push(@bool1)}
        @i1.stub!(:cleanup) # and do nothing
        @i1.go
        @context.stacks[:bool].depth.should == 0
      end
    end
    
    describe "\#cleanup" do
      describe "should push the result" do
        {[true, true] => true, [true, false] => false, [false, false] => true}.each do |inputs, expected|
          params = inputs.inspect
          it "should produce #{expected} given #{params}" do
            inputs.each {|i| @context.stacks[:bool].push(ValuePoint.new("bool", i))}
            @i1.go
            @context.stacks[:bool].peek.value.should == expected
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
nudge-0.2.9 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.2.8 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.2.7 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.2.6 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.2.5 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.2.4 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.2.3 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.2.2 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.2.1 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.2.0 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.1.3 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.1.2 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.1.1 spec/instructions/bool/bool_equal_q_spec.rb
nudge-0.1.0 spec/instructions/bool/bool_equal_q_spec.rb