spec/unit/namespace_spec.rb in blueprints-0.8.2 vs spec/unit/namespace_spec.rb in blueprints-0.9.0

- old
+ new

@@ -1,23 +1,71 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Blueprints::Namespace do - before do - mock = @mock + describe "children" do + it "should allow adding children to namespace" do + namespace.add_child(blueprint) + namespace[:blueprint].should == blueprint + end - old_root = Blueprints::Namespace.root - @namespace = Blueprints::Namespace.root = Blueprints::Namespace.new(:namespace) - Blueprints::Blueprint.new(:blueprint1, __FILE__) { mock } - Blueprints::Blueprint.new(:blueprint2, __FILE__) { mock } - Blueprints::Namespace.root = old_root + it "should warn when adding children overwrites existing one" do + namespace_blueprint + Blueprints.expects(:warn).with("Overwriting existing blueprint", blueprint) + namespace.add_child(blueprint) + end - Blueprints::Blueprint.new(:outside_namespace, __FILE__) { mock } - Blueprints::Namespace.root.build :namespace + it "should allow recursive finding of children" do + namespace_blueprint + Blueprints::Namespace.root['namespace.blueprint'].should == namespace_blueprint + end + + it "should raise error if blueprint can't be found" do + namespace_blueprint + expect { + Blueprints::Namespace.root['namespace.blueprint2'] + }.to raise_error(Blueprints::BlueprintNotFoundError) + end end + describe "children context" do + before do + namespace_blueprint + end + + it "should update attributes and dependencies of children when updating those of namespace" do + namespace.attributes(:parent => 1).depends_on(:parent_depends) + namespace_blueprint.attributes[:parent].should == 1 + namespace_blueprint.dependencies.should include(:parent_depends) + end + end + + describe "build" do + before do + blueprint + namespace_blueprint + namespace_blueprint2 + end + + it "should set result to results of all blueprints in namespace" do + result = namespace.build(stage) + result.should =~ [mock1, mock2] + end + + it "should pass build once and eval context params" do + namespace_blueprint.expects(:build).with(instance_of(Blueprints::EvalContext), false, :option => 'value') + namespace_blueprint2.expects(:build).with(instance_of(Blueprints::EvalContext), false, :option => 'value') + namespace.build(stage, false, :option => 'value') + end + end + describe "demolish" do it "should allow to demolish namespace" do - @mock.expects(:destroy).twice - @namespace.demolish + blueprint + namespace_blueprint + namespace_blueprint2 + results = namespace.build stage + results.each { |result| result.expects(:destroy) } + + @namespace.demolish(stage) end end end