spec/node_spec.rb in aniero-tire_swing-0.0.3 vs spec/node_spec.rb in aniero-tire_swing-0.0.4
- old
+ new
@@ -1,9 +1,16 @@
require File.join(File.dirname(__FILE__), %w[spec_helper])
describe TireSwing::Node do
+ it "has a parent accessor" do
+ node = TireSwing::Node.new
+ node.parent.should be_nil
+ node.parent = :parent
+ node.parent.should == :parent
+ end
+
describe ".create" do
it "returns a class that inherits from TireSwing::Node" do
klass = TireSwing::Node.create
klass.should be_an_instance_of(Class)
klass.ancestors.should include(TireSwing::Node)
@@ -118,10 +125,20 @@
@child.should_receive(:build).and_return("child")
@top.should_receive(:children).and_return(["foo", 1, @child])
TireSwing::Node.create(:foo => :children).new(@top).foo.should == ["foo", 1, "child"]
end
+ it "assigns the parent node if the child node is also a TireSwing node" do
+ @top.should_receive(:child).and_return(@child)
+ node = TireSwing::Node.create(:foo => :child)
+ child_node = TireSwing::Node.new
+ @child.should_receive(:build).and_return(child_node)
+ new_top = node.new(@top)
+ new_top.foo.should == child_node
+ child_node.parent.should == new_top
+ end
+
end
it "yields the syntax node instance if a named attribute is a lambda" do
@node = TireSwing::Node.create(:value => lambda { |x| @x = x; "asdf" })
@node.new(@top).value.should == "asdf"
@@ -134,9 +151,18 @@
@top.should_receive(:text_value).and_return("1234")
node.new(@top).value.should == 1234
end
end
+ end
+ end
+
+ describe "#clone" do
+ it "does a deep copy of a node" do
+ # can't leave this as an anonymous class, marshal dump/load doesn't like it
+ MyNode = TireSwing::Node.create
+ node = MyNode.new
+ node.clone.should_not eql node
end
end
end