require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper') describe Rtml::Widgets::DocumentVariableProcessing do context "with an existing document" do before :each do Rtml::Document.create!(:name => 'test') @doc = Rtml::Document.find_by_name('test') end it "should raise InvalidOptionError if options contain any invalid keys" do assert_raises Rtml::Errors::InvalidOptionError do @doc.declare_variable :varname, :some_invalid_key => 1234 end end it "should raise InvalidOptionError if type is invalid" do assert_raises Rtml::Errors::InvalidOptionError do @doc.declare_variable :varname, :type => :invalid_type_name end end %w(string integer datetime opaque binary).each do |type| line = __LINE__ + 2 code = <<-end_code it "should declare and define one TML #{type}" do @doc.#{type} :#{type} @doc.#{type.pluralize}.should have(1).item @doc.defined_variables(#{type.inspect}).should have(1).item end end_code eval code, binding, __FILE__, line line = __LINE__ + 2 code = <<-end_code it "should declare and define multiple TML #{type.pluralize}" do @doc.#{type.pluralize} :#{type}1, :#{type}2 @doc.#{type.pluralize}.should have(2).items @doc.defined_variables(#{type.inspect}).should have(2).items end end_code eval code, binding, __FILE__, line end end context "with a new document" do before :each do @doc = Rtml::Document.new end it "should raise InvalidOptionError if options contain any invalid keys" do assert_raises Rtml::Errors::InvalidOptionError do @doc.declare_variable :varname, :some_invalid_key => 1234 end end it "should raise InvalidOptionError if type is invalid" do assert_raises Rtml::Errors::InvalidOptionError do @doc.declare_variable :varname, :type => :invalid_type_name end end %w(string integer datetime opaque binary).each do |type| line = __LINE__ + 2 code = <<-end_code it "should declare and define one TML #{type}" do @doc.#{type} :#{type} @doc.#{type.pluralize}.should have(1).item @doc.defined_variables(#{type.inspect}).should have(1).item end end_code eval code, binding, __FILE__, line line = __LINE__ + 2 code = <<-end_code it "should declare and define multiple TML #{type.pluralize}" do @doc.#{type.pluralize} :#{type}1, :#{type}2 @doc.#{type.pluralize}.should have(2).items @doc.defined_variables(#{type.inspect}).should have(2).items end end_code eval code, binding, __FILE__, line end end end