require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper') describe Rtml::Instruction do context "built statically" do it "should produce a document from a class method" do rtml_document = Rtml::Instruction.follow([ 'screen :init, :main', 'screen :main', ' display "test"', ]) rtml_document.should resemble(:tml => [:screen, {:screen => :display}]) end it "should produce a document from instances" do instructions = [ Rtml::Instruction.new(:name => :screen, :arguments => {:name => :init, :next => :main}), Rtml::Instruction.new(:name => :screen, :arguments => {:name => :main}) ] instructions.last.instructions.build(:name => :display, :arguments => {:content => "test"}) rtml_document = Rtml::Document.new rtml_document.setup_default_document instructions.each { |instruction| instruction.follow(rtml_document) } rtml_document.should resemble(:tml => [:screen, {:screen => :display}]) end end context "built dynamically" do context "with an entry point that exists" do it "should be able to find its Widget" do doc = Rtml::Document.create instr = Rtml::Instruction.create(:source => doc, :x => 0, :y => 0, :name => "screen") instr.widget.should == Rtml::Widgets::Screens end end context "with an entry point that does not exist" do it "should find a nil Widget" do doc = Rtml::Document.create instr = Rtml::Instruction.create(:source => doc, :x => 0, :y => 0, :name => "missing_entry_point_name") instr.widget.should == nil end end end end