Sha256: c56f5d6b066e8798a36617f791ab8aeb19c1483b09804803b732fa4decb9e4f8
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
describe "if command" do let(:context) { ProgramExecutionContext.for double('GobstonesProgram') } let(:then_block) { CmdBlock.new [Poner.new(Verde.new)] } let(:else_block) { CmdBlock.new [Poner.new(Rojo.new)] } describe "if-then" do it "should evaluate the block if the condition is true" do if_cmd = IfCmd.new True.new, then_block if_cmd.evaluate context expect(context.head.are_there_balls?(Verde.new)).to be_true end it "should not evaluate the block if the condition is false" do if_cmd = IfCmd.new False.new, then_block if_cmd.evaluate context expect(context.head.are_there_balls?(Verde.new)).to be_false end it "should raise a type error if the condition is not boolean" do [Number.new(42), Norte.new, Verde.new].each do |value| if_cmd = IfCmd.new value, then_block expect { if_cmd.evaluate context } .to raise_error(GobstonesTypeError, /is not a boolean/) end end end describe "if-then-else" do it "should evaluate the 'then' block and not evaluate the 'else' block" do if_cmd = IfElseCmd.new True.new, then_block, else_block if_cmd.evaluate context expect(context.head.are_there_balls?(Verde.new)).to be_true expect(context.head.are_there_balls?(Rojo.new)).to be_false end it "should not evaluate the 'then' block and evaluate the 'else' block" do if_cmd = IfElseCmd.new False.new, then_block, else_block if_cmd.evaluate context expect(context.head.are_there_balls?(Verde.new)).to be_false expect(context.head.are_there_balls?(Rojo.new)).to be_true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gobstones-0.0.1.1 | spec/lang/commands/if_cmd_spec.rb |