Sha256: a4e023bfc473d8c889cec4df0d10b9ef995eb0a1cb231568ab943e2b53a54e70

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe Compositor::List do
  let(:context) { Object.new }

  it 'returns the generated array with the explicit receiver' do
    integers = [1, 2, 3]
    expected = {
      tests: [
        {number: 1},
        {number: 2},
        {number: 3}
      ]
    }

    dsl = Compositor::DSL.create(context)
    dsl.list root: :tests, collection: integers do |item|
      dsl.dsl_int item
    end

    dsl.to_hash.should == expected
  end

  it 'returns the generated array with explicit receiver' do
    integers = [1, 2, 3]
    expected = {
      tests: [
        {number: 1},
        {number: 2},
        {number: 3}
      ]
    }

    dsl = Compositor::DSL.create(context)
    dsl.list root: :tests, collection: integers do |item|
      dsl_int item
    end

    expected.should == dsl.to_hash
  end

  describe '#empty' do
    it 'returns the default type' do
      dsl = Compositor::DSL.create(context) do
        list collection: [], root: false
      end

      [].should == dsl.to_hash
    end

    it 'doesnt execute the block if an empty collection is passed' do
      dsl = Compositor::DSL.create(context) do
        list collection: [], root: false do |p|
          raise "Shouldnt be a DSL" if p.instance_of?(Compositor::DSL)
        end
      end

      [].should == dsl.to_hash
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
compositor-1.0.1 spec/compositor/list_spec.rb
compositor-1.0.0 spec/compositor/list_spec.rb
compositor-0.1.4 spec/compositor/list_spec.rb
compositor-0.1.3 spec/compositor/list_spec.rb