spec/models/geoff_spec.rb in geoff-0.0.3.beta vs spec/models/geoff_spec.rb in geoff-0.0.4
- old
+ new
@@ -1,72 +1,169 @@
require File.expand_path('spec/spec_helper')
require 'neo4j'
require 'geoff'
describe Geoff do
- class CoverageArea
- include Neo4j::NodeMixin
- end
- class Cafe
- include Neo4j::NodeMixin
- end
+ before { stub_node_dsl_object_id }
- class Carrier
- include Neo4j::NodeMixin
- end
+ context do
- class Branch
- include Neo4j::NodeMixin
- end
- describe 'base nodes' do
+ class Branch
+ include Neo4j::NodeMixin
+ end
- let(:builder) do
- Geoff(Cafe, Carrier, Branch, CoverageArea)
+ class Cafe
+ include Neo4j::NodeMixin
end
- let(:expected_geoff) do
- strip_whitespace <<-EOS
+ describe 'base nodes' do
+
+ let(:builder) do
+ Geoff(Cafe, Branch)
+ end
+
+ let(:expected_geoff) do
+ strip_whitespace <<-EOS
(ROOT)-[:Cafe]->(Cafe)
- (ROOT)-[:Carrier]->(Carrier)
(ROOT)-[:Branch]->(Branch)
- (ROOT)-[:CoverageArea]->(CoverageArea)
- EOS
- end
+ EOS
+ end
- specify do
- builder.to_s.should == expected_geoff
+ specify do
+ builder.to_s.should == expected_geoff
+ end
end
- end
- describe 'Geoff sugar' do
- let(:node) do
- Geoff(Branch) do
- branch 'starbucks_branch' do
- delay_time 15
+ describe 'Geoff sugar' do
+ let(:node) do
+ Geoff(Branch) do
+ branch 'starbucks_branch' do
+ delay_time 15
+ end
end
end
- end
- let(:expected_geoff) do
- strip_whitespace <<-EOS
+ 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
- specify do
- node.to_geoff.should == expected_geoff
+ class Sandwich
+ include Neo4j::NodeMixin
end
- specify do
- pending 'not implemented'
- ->{
- Geoff do
- branch 'starbucks_branch' do
- delay_time 15
+ 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
- }.should raise_error Geoff::MissingClassDefinition, "branch"
+
+ 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