Sha256: 45436f530b3d57f4d82f07cdc5b9df4bfde60b7232c493a56fff1c1748b23d69

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe Blueprints::Buildable do
  it "should inspect buildable nicely" do
    namespace_blueprint.attributes(:attr => 'value').depends_on(:dependency)
    namespace_blueprint.inspect.should == %q(<#Blueprints::Blueprint name: "namespace.blueprint", attributes: {:attr=>"value"}, dependencies: [:dependency]>)
  end

  describe "name" do
    after do
      Blueprints.config.default_attributes = :name
    end

    it 'should raise TypeError when scenario name is not symbol or string' do
      lambda {
        Blueprints::Blueprint.new([], context)
      }.should raise_error(TypeError, "Pass blueprint names as strings or symbols only, cannot define blueprint []")
    end

    it "should return full name" do
      namespace_blueprint.full_name.should == 'namespace.blueprint'
    end

    describe "inferring" do
      it "should infer name using default attributes" do
        Blueprints::Buildable.new(nil, context.attributes(:name => 'inferred_name')).name.should == :inferred_name
      end

      it "should infer name from third default attribute" do
        Blueprints.config.default_attributes = :name, :to_s, :id
        Blueprints::Buildable.new(nil, context.attributes(:id => 'third')).name.should == :third
      end

      it "should parameterize infered name" do
        Blueprints::Buildable.new(nil, context.attributes(:name => 'my blueprint')).name.should == :my_blueprint
      end

      it "should raise error if name can't be inferred" do
        lambda {
          Blueprints::Buildable.new(nil, context.attributes(:id => 'third')).name.should == :third
        }.should raise_error(TypeError, "Pass blueprint names as strings or symbols only, cannot define blueprint nil")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blueprints-1.0.1 spec/unit/buildable_spec.rb
blueprints-1.0.0 spec/unit/buildable_spec.rb
blueprints-0.9.0 spec/unit/buildable_spec.rb