require File.expand_path('spec/spec_helper') require 'neo4j' require './lib/geoff/neo4j_wrapper_dsl' describe Neo4jWrapperDsl do let(:expected_geoff) do strip_whitespace <<-EOS (ROOT)-[:Sandwich]->(Sandwich) (ROOT)-[:Cheese]->(Cheese) (ROOT)-[:Egg]->(Egg) EOS end class Sandwich include Neo4j::NodeMixin end class Cafe include Neo4j::NodeMixin end class Branch include Neo4j::NodeMixin end class Cheese include Neo4j::NodeMixin end class Egg include Neo4j::NodeMixin end describe "#to_s" do specify do dsl = Neo4jWrapperDsl.new Sandwich, Cheese, Egg dsl.to_s.should == dsl.to_geoff end end describe "#to_geoff" do it "outputs root node geoff syntax" do dsl = Neo4jWrapperDsl.new(Sandwich, Cheese, Egg) dsl.to_geoff.should == expected_geoff end specify do ->{Neo4jWrapperDsl.new 2 } .should raise_error ArgumentError ->{Neo4jWrapperDsl.new '' } .should raise_error ArgumentError ->{Neo4jWrapperDsl.new ['']}.should raise_error ArgumentError ->{Neo4jWrapperDsl.new [1]} .should raise_error ArgumentError ->{Neo4jWrapperDsl.new(Egg)}.should_not raise_error ArgumentError end context "with a block" do let(:expected) { strip_whitespace <<-EOS (ROOT)-[:Cafe]->(Cafe) (ROOT)-[:Branch]->(Branch) (Starbucks) {"_classname":"Cafe"} (Cafe)-[:all]->(Starbucks) (starbucks_branch) {"_classname":"Branch"} (Branch)-[:all]->(starbucks_branch) (Starbucks)-[:owns]->(starbucks_branch) EOS } specify "with parent node is root node, but no relationship, don't create relationship to root node" do Neo4jWrapperDsl.new(Cafe, Branch) do cafe 'Starbucks' do children 'owns' do #create relationship to parent node of type owns (comes from children DSL) branch 'starbucks_branch' end end end.to_geoff.should == expected end end end end