Sha256: 7649b18eb0d9419394e9ee59c09b9253228ffb33db35dbf8cf529c5be4ffb5fe

Contents?: true

Size: 1.98 KB

Versions: 7

Compression:

Stored size: 1.98 KB

Contents

shared_examples_for Hanuman::Shortcuts do

  before(:each) do
    @orig_reg = subject.registry.show
    subject.registry.clear!
  end
   
  after(:each)  do
    subject.registry.clear!
    subject.registry.merge!(@orig_reg)
  end
  
  context '.registry' do
    it 'returns the registry'  do
      subject.registry.should == Hanuman::GlobalRegistry
    end
  end
  
  context '.add_shortcut_method_for' do
    let(:shortcut){ :banshee }
    it 'add shortcut methods for creating builders' do
      expect{ subject.add_shortcut_method_for(shortcut, Hanuman::StageBuilder) }.to change{ subject.respond_to? shortcut }.from(false).to(true)
    end
  end

  context '.builder_shortcut' do
    context 'with an existing definition' do
      let(:existing_definition){ Hanuman::StageBuilder.receive(label: :sunfire) }

      it 'returns the existing definition from the registry' do
        subject.registry.create(:sunfire, existing_definition)
        subject.registry.should_receive(:retrieve).with(:sunfire).and_return(existing_definition)
        subject.builder_shortcut(Hanuman::StageBuilder, :sunfire)         
      end
    end
    
    context 'with a nonexisting definition' do
      let(:mock_builder_type){ double :builder_type }
      let(:mock_builder)     { double :builder      }
      let(:block_arg)        { ->(){ def absorb() 'radiation' ; end } }

      it 'creates a new definition using the supplied builder_type' do
        mock_builder_type.should_receive(:receive).with(label: :sunfire).and_return mock_builder
        mock_builder.should_receive(:define).with(&block_arg)
        subject.builder_shortcut(mock_builder_type, :sunfire, &block_arg)
      end
    end

    context 'graph builder decoration' do
      it 'decorates the builder with registry methods if the builder is a GraphBuilder' do
        Hanuman::GlobalRegistry.should_receive(:decorate_with_registry).with an_instance_of(Hanuman::GraphBuilder)
        subject.builder_shortcut(Hanuman::GraphBuilder, :sunfire)
      end
    end
  end
  
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ul-wukong-4.1.1 spec/support/shared_examples_for_shortcuts.rb
ul-wukong-4.1.0 spec/support/shared_examples_for_shortcuts.rb
wukong-4.0.0 spec/support/shared_examples_for_shortcuts.rb
wukong-3.0.1 spec/support/shared_examples_for_shortcuts.rb
wukong-3.0.0 spec/support/shared_examples_for_shortcuts.rb
wukong-3.0.0.pre3 spec/support/shared_examples_for_shortcuts.rb
wukong-3.0.0.pre2 spec/support/shared_examples_for_shortcuts.rb