Skip to content

Commit

Permalink
change rspec expectation syntax using transpec
Browse files Browse the repository at this point in the history
  • Loading branch information
ngarbezza committed Oct 21, 2013
1 parent 7d4761d commit 492ac26
Show file tree
Hide file tree
Showing 46 changed files with 502 additions and 502 deletions.
4 changes: 2 additions & 2 deletions spec/lang/commands/assignments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
it "should associate the var name with the evaluated expression" do
assign = SingleAssignment.new a, Add.new(3.to_gbs_num, 4.to_gbs_num)
assign.evaluate context
context.has_variable_named?('a').should be_true
context.get(a).should == 7.to_gbs_num
expect(context.has_variable_named?('a')).to be_true
expect(context.get(a)).to eq(7.to_gbs_num)
end

end
8 changes: 4 additions & 4 deletions spec/lang/commands/cmd_block_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
Poner.new(Rojo.new), Poner.new(Verde.new),
Poner.new(Negro.new), Poner.new(Azul.new)]
cmd_block.evaluate context
context.head.are_there_balls?(Rojo.new).should be_true
context.head.are_there_balls?(Azul.new).should be_true
context.head.are_there_balls?(Negro.new).should be_true
context.head.are_there_balls?(Verde.new).should be_true
expect(context.head.are_there_balls?(Rojo.new)).to be_true
expect(context.head.are_there_balls?(Azul.new)).to be_true
expect(context.head.are_there_balls?(Negro.new)).to be_true
expect(context.head.are_there_balls?(Verde.new)).to be_true
end

it "builds an empty command block" do
Expand Down
12 changes: 6 additions & 6 deletions spec/lang/commands/if_cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
it "should evaluate the block if the condition is true" do
if_cmd = IfCmd.new True.new, then_block
if_cmd.evaluate context
context.head.are_there_balls?(Verde.new).should be_true
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
context.head.are_there_balls?(Verde.new).should be_false
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
Expand All @@ -33,15 +33,15 @@
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
context.head.are_there_balls?(Verde.new).should be_true
context.head.are_there_balls?(Rojo.new).should be_false
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
context.head.are_there_balls?(Verde.new).should be_false
context.head.are_there_balls?(Rojo.new).should be_true
expect(context.head.are_there_balls?(Verde.new)).to be_false
expect(context.head.are_there_balls?(Rojo.new)).to be_true
end

end
Expand Down
4 changes: 2 additions & 2 deletions spec/lang/commands/ir_al_origen_cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

ir_al_origen.evaluate context

context.head.x_pos.should == 0
context.head.y_pos.should == 0
expect(context.head.x_pos).to eq(0)
expect(context.head.y_pos).to eq(0)
end

end
10 changes: 5 additions & 5 deletions spec/lang/commands/mover_cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
it "should run" do
Mover.new(north).evaluate(context)

context.head.x_pos.should == 0
context.head.y_pos.should == 1
expect(context.head.x_pos).to eq(0)
expect(context.head.y_pos).to eq(1)
end

it "should undo" do
Expand All @@ -17,12 +17,12 @@
cmd.evaluate context
cmd.undo context

context.head.x_pos.should == 0
context.head.y_pos.should == 0
expect(context.head.x_pos).to eq(0)
expect(context.head.y_pos).to eq(0)
end

it "should return opposite cmd" do
Mover.new(north).opposite.should == Mover.new(south)
expect(Mover.new(north).opposite).to eq(Mover.new(south))
end

it "should fail if types don't match" do
Expand Down
6 changes: 3 additions & 3 deletions spec/lang/commands/poner_cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
it "should execute" do
Poner.new(green).evaluate(context)

context.head.number_of_balls(green).should == 1
expect(context.head.number_of_balls(green)).to eq(1)
end

it "should undo" do
context.head.put green

Poner.new(green).undo context

context.head.number_of_balls(green).should == 0
expect(context.head.number_of_balls(green)).to eq(0)
end

it "should return the opposite cmd" do
Poner.new(green).opposite.should == Sacar.new(green)
expect(Poner.new(green).opposite).to eq(Sacar.new(green))
end

it "should fail if types don't match" do
Expand Down
4 changes: 2 additions & 2 deletions spec/lang/commands/procedure_call_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
proc_call = ProcedureCall.new 'MyProcedure', []
proc_call.evaluate context

context.head.are_there_balls?(Verde.new).should be_true
expect(context.head.are_there_balls?(Verde.new)).to be_true
end

it "should allow to call a procedure from another procedure" do
Expand All @@ -29,7 +29,7 @@
call_to_outer_procedure = ProcedureCall.new 'Outer', []
call_to_outer_procedure.evaluate program_context

program_context.head.are_there_balls?(Azul.new).should be_true
expect(program_context.head.are_there_balls?(Azul.new)).to be_true
end

it "should fail to execute an undefined procedure" do
Expand Down
8 changes: 4 additions & 4 deletions spec/lang/commands/procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
body = CmdBlock.new [poner_cmd]
procedure = Procedure.new 'MyProcedure', empty_args, body
procedure.evaluate program_context
program_context.head.are_there_balls?(Rojo.new).should be_true
expect(program_context.head.are_there_balls?(Rojo.new)).to be_true
end

it "should execute in a new clean context, without having variables defined in another contexts" do
Expand All @@ -34,8 +34,8 @@

procedure.evaluate program_context, [Negro.new, Norte.new]

program_context.head.are_there_balls?(Negro.new).should be_true
program_context.head.y_pos.should == 1
expect(program_context.head.are_there_balls?(Negro.new)).to be_true
expect(program_context.head.y_pos).to eq(1)
end

it "should not set arguments as var names in outer context" do
Expand All @@ -45,7 +45,7 @@

procedure.evaluate program_context, [Oeste.new]

program_context.has_variable_named?('a_direction').should be_false
expect(program_context.has_variable_named?('a_direction')).to be_false
end

it "should fail if it is executed with more arguments than expected" do
Expand Down
12 changes: 6 additions & 6 deletions spec/lang/commands/repeat_with_cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
it "should iterate over numbers" do
repeat_with = RepeatWithCmd.new var_name, 1.to_gbs_num, 10.to_gbs_num, CmdBlock.new([Poner.new(Rojo.new)])
repeat_with.evaluate context
context.head.number_of_balls(Rojo.new).should == 10
expect(context.head.number_of_balls(Rojo.new)).to eq(10)
end

it "should throw an error if the range values have not the same type" do
Expand All @@ -25,17 +25,17 @@
it "should remove the index variable assignment after execution" do
repeat_with = RepeatWithCmd.new var_name, Azul.new, Verde.new, CmdBlock.new([])
repeat_with.evaluate context
context.has_variable_named?('var').should be_false
expect(context.has_variable_named?('var')).to be_false
end

it "should allow to use the index variable inside the command block" do
cmd_block = CmdBlock.new [Poner.new(VarName.new('var'))]
repeat_with = RepeatWithCmd.new var_name, Azul.new, Verde.new, cmd_block
repeat_with.evaluate context
context.head.are_there_balls?(Azul.new).should be_true
context.head.are_there_balls?(Negro.new).should be_true
context.head.are_there_balls?(Rojo.new).should be_true
context.head.are_there_balls?(Verde.new).should be_true
expect(context.head.are_there_balls?(Azul.new)).to be_true
expect(context.head.are_there_balls?(Negro.new)).to be_true
expect(context.head.are_there_balls?(Rojo.new)).to be_true
expect(context.head.are_there_balls?(Verde.new)).to be_true
end

end
6 changes: 3 additions & 3 deletions spec/lang/commands/sacar_cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

Sacar.new(red).evaluate context

context.head.number_of_balls(red).should == 2
expect(context.head.number_of_balls(red)).to eq(2)
end

it "should undo" do
Sacar.new(red).undo context

context.head.number_of_balls(red).should == 1
expect(context.head.number_of_balls(red)).to eq(1)
end

it "should return the opposite cmd" do
Sacar.new(red).opposite.should == Poner.new(red)
expect(Sacar.new(red).opposite).to eq(Poner.new(red))
end

it "should fail if there are no balls in the board" do
Expand Down
2 changes: 1 addition & 1 deletion spec/lang/commands/vaciar_tablero_cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
context.head.put red
vaciar_tablero = VaciarTablero.new
vaciar_tablero.evaluate context
context.board.empty?.should be_true
expect(context.board.empty?).to be_true
end

end
6 changes: 3 additions & 3 deletions spec/lang/commands/while_cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
def condition(times)
cond = double('while condition')
expected_values = [True.new] * times + [False.new]
cond.stub(:evaluate).and_return(*expected_values)
allow(cond).to receive(:evaluate).and_return(*expected_values)
cond
end

it "should evaluate the command block until the condition is not satisfied" do
while_cmd = WhileCmd.new condition(3), while_block
while_cmd.evaluate context
context.head.number_of_balls(Verde.new).should == 3
expect(context.head.number_of_balls(Verde.new)).to eq(3)
end

it "should not evaluate the command block if the condition is not satisfied" do
while_cmd = WhileCmd.new condition(0), while_block
while_cmd.evaluate context
context.head.are_there_balls?(Verde.new).should be_false
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
Expand Down
28 changes: 14 additions & 14 deletions spec/lang/expressions/arithmetic_expressions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

it "should evaluate with two numbers" do
add = Add.new(42.to_gbs_num, 23.to_gbs_num)
add.evaluate.should == 65.to_gbs_num
expect(add.evaluate).to eq(65.to_gbs_num)
end

it "should evaluate nested add expressions" do
Expand All @@ -14,7 +14,7 @@
add_43_23 = Add.new add_27_16, 23.to_gbs_num
add_66_42 = Add.new add_43_23, 42.to_gbs_num

add_66_42.evaluate.should == 108.to_gbs_num
expect(add_66_42.evaluate).to eq(108.to_gbs_num)
end

end
Expand All @@ -23,19 +23,19 @@

it "should evaluate with two numbers" do
sub = Sub.new(42.to_gbs_num, 15.to_gbs_num)
sub.evaluate.should == 27.to_gbs_num
expect(sub.evaluate).to eq(27.to_gbs_num)
end

it "should evaluate and return a negative result" do
sub = Sub.new(15.to_gbs_num, 42.to_gbs_num)
sub.evaluate.should == -27.to_gbs_num
expect(sub.evaluate).to eq(-27.to_gbs_num)
end

it "should evaluate nested sub expressions" do
sub_n1_n2 = Sub.new 42.to_gbs_num, 15.to_gbs_num
sub = Sub.new sub_n1_n2, 8.to_gbs_num

sub.evaluate.should == 19.to_gbs_num
expect(sub.evaluate).to eq(19.to_gbs_num)
end

end
Expand All @@ -44,12 +44,12 @@

it "should evaluate a simple mul" do
mul = Mul.new(4.to_gbs_num, 8.to_gbs_num)
mul.evaluate.should == 32.to_gbs_num
expect(mul.evaluate).to eq(32.to_gbs_num)
end

it "should evaluate a nested mul expression" do
mul = Mul.new(-2.to_gbs_num, 4.to_gbs_num)
Mul.new(mul, 5.to_gbs_num).evaluate.should == -40.to_gbs_num
expect(Mul.new(mul, 5.to_gbs_num).evaluate).to eq(-40.to_gbs_num)
end

end
Expand All @@ -58,12 +58,12 @@

it "should evaluate a simple div" do
div = Div.new(12.to_gbs_num, 3.to_gbs_num)
div.evaluate.should == 4.to_gbs_num
expect(div.evaluate).to eq(4.to_gbs_num)
end

it "should evaluate to an integer division" do
div = Div.new(10.to_gbs_num, 3.to_gbs_num)
div.evaluate.should == 3.to_gbs_num
expect(div.evaluate).to eq(3.to_gbs_num)
end

it "should raise an error when dividing by zero" do
Expand All @@ -78,12 +78,12 @@

it "should evaluate a mod with result 0" do
mod = Mod.new(4.to_gbs_num, 4.to_gbs_num)
mod.evaluate.should == 0.to_gbs_num
expect(mod.evaluate).to eq(0.to_gbs_num)
end

it "should evaluate a mod with result > 0" do
mod = Mod.new(10.to_gbs_num, 3.to_gbs_num)
mod.evaluate.should == 1.to_gbs_num
expect(mod.evaluate).to eq(1.to_gbs_num)
end

end
Expand All @@ -94,13 +94,13 @@
pow_1 = Pow.new(1.to_gbs_num, 0.to_gbs_num)
pow_42 = Pow.new(42.to_gbs_num, 0.to_gbs_num)

pow_1.evaluate.should == 1.to_gbs_num
pow_42.evaluate.should == 1.to_gbs_num
expect(pow_1.evaluate).to eq(1.to_gbs_num)
expect(pow_42.evaluate).to eq(1.to_gbs_num)
end

it "should calculate 2 raised to 4" do
pow = Pow.new(2.to_gbs_num, 4.to_gbs_num)
pow.evaluate.should == 16.to_gbs_num
expect(pow.evaluate).to eq(16.to_gbs_num)
end

end
Expand Down
Loading

0 comments on commit 492ac26

Please sign in to comment.