require 'spec_helper' describe Rtml::Test::VariableScope do it "should raise if a variable is not defined" do proc { subject[:name] = "Colin" }.should raise_error(Rtml::Errors::VariableError) end it "should allow variables to be defined" do subject.declare_variable(:name) subject.variable_names.should include('name') end it "should perform TML arithmetic: plus" do subject.declare_variable(:counter, :type => :integer, :value => 1) subject.perform_operation_on(:counter, :lo => '1', :op => 'plus', :ro => '2') subject[:counter].should == 3 end it "should perform TML arithmetic: minus" do subject.declare_variable(:counter, :type => :integer, :value => 1) subject.perform_operation_on(:counter, :lo => '1', :op => 'minus', :ro => '2') subject[:counter].should == -1 end it "should perform TML arithmetic: format" it "should perform TML arithmetic: item" do subject.declare_variable(:which) subject.perform_operation_on(:which, :lo => 'one;two;three', :op => 'item', :ro => '1') subject[:which].should == 'two' end it "should perform TML arithmetic: number" do subject.declare_variable(:which) subject.perform_operation_on(:which, :lo => 'one;two;three', :op => 'number') subject[:which].should == '3' end it "should perform TML assignment" do subject.declare_variable(:counter, :type => :integer, :value => 1) subject.find_variable(:counter).perform_operation(:lo => '3') subject[:counter].should == 3 end it "should assign a dynamic value" do subject.declare_variable(:counter, :type => :integer, :value => 1) subject.declare_variable(:start, :type => :integer, :value => 5) subject[:counter] = "tmlvar:start" subject[:counter].should == 5 end it "should assign another variable" do # isn't this really the same as assigning a static value? because subject[:start] returns 1... subject.declare_variable(:counter, :type => :integer, :value => 1) subject.declare_variable(:start, :type => :integer, :value => 5) subject[:counter] = subject[:start] subject[:counter].should == 5 end it "should assign a static value" do subject.declare_variable(:counter, :type => :integer) subject[:counter] = 5 subject[:counter].should == 5 end end