require 'spec_helper' describe Rtml::Test::Simulator do subject do Rtml::Test::Simulator.new(File.join(File.dirname(__FILE__), '../../../support/raw_tml/enter_amount.tml')) end context "with AVS" do subject { Rtml::Test::Simulator.new(File.join(File.dirname(__FILE__), '../../../support/raw_tml/avs.tml')) } it "should load" do subject end end context "supplying input after execution has completed" do subject { Rtml::Test::Simulator.new(File.join(File.dirname(__FILE__), '../../../support/raw_tml/empty_screen.tml'))} it "should raise a comprehensible error" do proc { subject.press(:enter) }.should raise_error(Rtml::Errors::ApplicationError) end end it "should let you set HTTP headers" do subject.header("ITID", '100') subject.headers['ITID'].should == '100' subject.should_receive(:get).with('/?ignore_state=true', {}, {'ITID' => '100'}) subject.visit("/") end it "should define state in the controller" do subject.header("ITID", "100") subject.visit("/rtml/index.rtml") subject.response.template.controller.state.itid.should == '100' end context "with a reference to another document" do subject do Rtml::Test::Simulator.new(File.join(File.dirname(__FILE__), '../../../support/raw_tml/foreign_reference.tml')) end it "should catch :new_document and use it to make a new request" do subject.press(:menu) subject.current_screen_id.should == "main_menu" end end context "with a reference to a TML variable" do subject do Rtml::Test::Simulator.new(File.join(File.dirname(__FILE__), '../../../support/raw_tml/tmlvar_reference.tml')) end it "should follow the reference" do subject.press(:menu) subject.current_screen_id.should == "main_menu" end context "in a submit attribute" do subject do Rtml::Test::Simulator.new(File.join(File.dirname(__FILE__), '../../../support/raw_tml/tmlvar_reference.tml')) end it "should follow the reference" do subject.should_receive(:post_data).with("#submitted_to", {"value"=>nil}) subject.visit(:submit_scr) end end end context "with document level events" do subject do Rtml::Test::Simulator.new(File.join(File.dirname(__FILE__), '../../../support/raw_tml/document_level_events.tml')) end it "should process menu presses" do subject.press(:menu) subject.current_screen_id.should == 'on_menu' end it "should process cancel presses" do subject.press(:cancel) subject.current_screen_id.should == 'on_cancel' end end it "should raise on document-level menu presses" do subject.visit "#enter_amt" proc { subject.press(:menu) }.should raise_error(Rtml::Errors::ApplicationError) end it "should raise on document-level cancel presses" do subject.visit "#enter_amt" proc { subject.press(:cancel) }.should raise_error(Rtml::Errors::ApplicationError) end it "should load a static TML file" do subject end it "should be waiting for input" do subject.current_screen_id.should == "idle" subject.should be_waiting_for_input end it "should allow to fill in forms" do subject.visit "#enter_amt" subject.fill_in "payment.amount", '100' subject.variables['payment.amount'].should == 100 end it "should raise if form does not contain element for specified variable" do subject.visit "#enter_amt" proc { subject.fill_in "missing_field", '100' }.should raise_error(Rtml::Errors::SimulationError) end it "should allow to follow hyperlinks by inner text, case insensitive" do subject.follow_link("make a payment") subject.current_screen_id.should == "enter_amt" end it "should allow to follow hyperlinks by href" do subject.follow_link("#enter_amt") subject.current_screen_id.should == "enter_amt" end it "should raise if link is not found" do proc { subject.follow_link("missing_link") }.should raise_error(Rtml::Errors::SimulationError) end it "should allow to press a key" do subject.visit "#enter_amt" subject.press("OK") subject.current_screen_id.should_not == "#enter_amt" end it "should pause at card parsers" do subject.visit "#enter_amt" subject.press("OK") subject.continue(:ignore_display => true) subject.current_screen_id.should == "swipe" end context "at a screen with a properly configured card reader" do before(:each) { subject.visit "#swipe" } context "when :visa card is swiped" do before(:each) { subject.swipe_card(:visa) } it "should set variables" do subject.variables['card.pan'].should == 4111111111111111 subject.variables['card.scheme'].should == 'VISA' end it "should continue execution" do subject.current_screen_id.should_not == "swipe" end end end it "should not allow card swipes without properly configured card reader" do subject.visit "#risk" proc { subject.swipe_card(:visa) }.should raise_error(Rtml::Errors::SimulationError) end it "should raise if visiting a missing screen" do proc { subject.visit "#missingscrn" }.should raise_error(Rtml::Errors::ApplicationError) end it "should not allow card swipes without card parsers" do subject.visit "#enter_amt" proc { subject.swipe_card(:visa) }.should raise_error(Rtml::Errors::SimulationError) end # this is really where Cucumber should start to come in handy. context "after selecting 'make a payment'" do before(:each) { subject.follow_link("Make a payment") } context "after filling in 'amount' with '$1.00'" do before(:each) { subject.fill_in "payment.amount", '100'; subject.press("OK") } it "should display the amount" do subject.current_screen.to_s.should match(/Amount Due:/) end end end end