Sha256: 35079d74a4ec181f456cd6978a2bc44949f9e6709754588f4b6145002c9f6fce

Contents?: true

Size: 1.49 KB

Versions: 10

Compression:

Stored size: 1.49 KB

Contents

require "spec_helper"

describe Eloqua::Builder::Templates do

  let(:xml) do
    Eloqua::Builder::Xml.new
  end

  subject do
    klass = Class.new
    klass.send(:include, Eloqua::Builder::Templates)
    klass
  end

  context "#define_builder_template" do

    before do
      subject.define_builder_template :iterator do |xml, list|
      end
    end

    it 'should have saved block in builder_templates' do
      subject.builder_templates.size.should == 1
    end

    it 'should be able to access block' do
      subject.builder_templates[:iterator].class.should == Proc
    end

  end

  context '#builder_template' do

    context 'passing no arguments to template' do

      before do
        subject.define_builder_template :bigwow do |xml|
          xml.big_wow("BANG!")
        end
      end

      it 'should be able to use template to create xml' do
        output = xml.omg(&subject.builder_template(:bigwow))
        output.strip.should == '<omg><big_wow>BANG!</big_wow></omg>'
      end

    end

    context 'passing arguments to template' do

      before do
        subject.define_builder_template :long do |xml, list|
          list.each do |element|
            xml.tag!(element[0], element[1])
          end
        end
      end

      it 'should take arguments and build output' do
        output = xml.long(&subject.builder_template(:long, [ ['big', 'value'], ['small', 'value'] ]))
        output.strip.should == '<long><big>value</big><small>value</small></long>'
      end

    end
    
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eloqua-1.2.4 spec/lib/eloqua/builder/templates_spec.rb
eloqua-1.2.3 spec/lib/eloqua/builder/templates_spec.rb
eloqua-1.2.2 spec/lib/eloqua/builder/templates_spec.rb
eloqua-1.2.1 spec/lib/eloqua/builder/templates_spec.rb
eloqua-1.2.0 spec/lib/eloqua/builder/templates_spec.rb
eloqua-1.1.4 spec/lib/eloqua/builder/templates_spec.rb
eloqua-1.1.3 spec/lib/eloqua/builder/templates_spec.rb
eloqua-1.1.2 spec/lib/eloqua/builder/templates_spec.rb
eloqua-1.1.1 spec/lib/eloqua/builder/templates_spec.rb
eloqua-1.1.0 spec/lib/eloqua/builder/templates_spec.rb