require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper')
describe Rtml::Widgets::HighlevelVariableProcessing do
before :each do
@doc = Rtml::Document.new
@doc.strings :first_name, :last_name, :full_name
@doc.integer :amount
@doc.integer :sale
end
context "with name mangling" do
before(:each) do
prefix = "swipe_card"
next_screen_name = "read_card"
@doc.screen "#{prefix}_risk_management", "#{prefix}_trans_reject" do
_if(tvars['card.parser.type'] == 'mag') { goto "#{prefix}_risk_check" }
_elsif(tvars['card.input_type'] == 3) { goto "#{prefix}_risk_check" }
end
@doc.screen "#{prefix}_risk_check", next_screen_name do
build :tform do
build :card, :parser => :mag, :parser_params => :risk_mgmt
end
end
@doc.screen "#{prefix}_trans_reject", :init, :timeout => '3' do
display "Transaction Rejected: "
end
end
it "" do
# puts @doc.to_tml
end
end
context "using periods instead of array operators" do
context "with one TML variable assigned to another" do
before :each do
@doc.screen :test do
tvars.first_name = tvars.last_name
end
end
it "should create a setvar tag with value tmlvar:other_variable" do
@doc.to_tml.should =~ /tmlvar:last_name/m
end
it "should not include the literal value of tmlvar:other_variable" do
(@doc.to_tml =~ /tmlvar:# 0) { tvars[:sale] = true }
_elsif(tvars[:amount] == 0) { tvars[:sale] = false }
_else { tvars[:amount] = 0 }
end
@doc.screen :main
@tml = @doc.to_tml
end
it "should not include 'next' attribute in the generated 'screen' element" do
(@doc / "screen[id=init]").first.property('next').should be_nil
end
it "should place quotes around numbers" do
@tml.should_not match(/lo=0/)
end
it "should not set the :next attribute to an RTML screen object instead of its :id" do
@tml.should_not match(/next=\# '0'" do
@variants.first.property('lo').to_s.should == '0'
end
it "should generate the first variant with :op => 'less_or_equal'" do
@variants.first.property('op').to_s.should == 'less_or_equal'
end
it "should generate the first variant with :ro => 'tmlvar:amount'" do
@variants.first.property('ro').to_s.should == 'tmlvar:amount'
end
it "should generate the second variant with :lo => 'tmlvar:amount'" do
@variants.second.property('lo').to_s.should == 'tmlvar:amount'
end
it "should generate the second variant with :op => 'equal'" do
@variants.second.property('op').to_s.should == 'equal'
end
it "should generate the second variant with :ro => '0'" do
@variants.second.property('ro').to_s.should == '0'
end
end
end
end
context "with high level variable assignments" do
before :each do
@doc.screen :init do
terminal_variables[:amount] = 0
terminal_variables[:first_name] = 'John'
terminal_variables[:last_name] = 'Smith'
terminal_variables[:full_name] = tvars[:first_name] + tvars[:last_name]
end
end
it "should generate setvars with the expected values" do
init = (@doc / 'init').first
assert_not_nil init, "Init screen doesn't exist"
(setvars = init / "setvar").should have(4).items
setvars.each do |setvar|
case setvar.property('name')
when 'amount' then assert_equal 0, setvar.property('lo')
when 'first_name' then assert_equal 'John', setvar.property('lo')
when 'last_name' then assert_equal 'Smith', setvar.property('lo')
when 'full_name' then
assert_equal 'tmlvar:first_name', setvar.property('lo')
assert_equal 'tmlvar:last_name', setvar.property('ro')
assert_equal 'plus', setvar.property('op')
else
flunk "Unexpected variable name: #{setvar.property('name')}; expected one of %w(amount first_name last_name full_name)"
end
end
end
end
end