require File.expand_path('spec/spec_helper') require 'neo4j' require 'geoff' describe Geoff do before { stub_node_dsl_object_id } context do class Branch include Neo4j::NodeMixin end class Cafe include Neo4j::NodeMixin end describe 'base nodes' do let(:builder) do Geoff(Cafe, Branch) end let(:expected_geoff) do strip_whitespace <<-EOS (ROOT)-[:Cafe]->(Cafe) (ROOT)-[:Branch]->(Branch) EOS end specify do builder.to_s.should == expected_geoff end end describe 'Geoff sugar' do let(:node) do Geoff(Branch) do branch 'starbucks_branch' do delay_time 15 end end end let(:expected_geoff) do strip_whitespace <<-EOS (ROOT)-[:Branch]->(Branch) (starbucks_branch) {"_classname":"Branch","delay_time":15} (Branch)-[:all]->(starbucks_branch) EOS end specify do node.to_geoff.should == expected_geoff end specify do pending 'not implemented' ->{ Geoff do branch 'starbucks_branch' do delay_time 15 end end }.should raise_error Geoff::MissingClassDefinition, "branch" end end end context 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 = Geoff.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 = Geoff.new(Sandwich, Cheese, Egg) dsl.to_geoff.should == expected_geoff end specify do ->{Geoff.new 2 } .should raise_error ArgumentError ->{Geoff.new '' } .should raise_error ArgumentError ->{Geoff.new ['']}.should raise_error ArgumentError ->{Geoff.new [1]} .should raise_error ArgumentError ->{Geoff.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 Geoff.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 describe 'called second time' do let(:node) do Geoff.new(Cafe) do cafe 'Starbucks' end end let(:expected_geoff) do node.to_geoff end it 'returns same geoff as on first call' do pending 'Not implemented yet' node.to_geoff.should == expected_geoff end end end end end