spec/unit/tools/test_tuple_handle.rb in alf-0.9.2 vs spec/unit/tools/test_tuple_handle.rb in alf-0.9.3
- old
+ new
@@ -9,32 +9,64 @@
handle.set(:hello => "a", :world => "b")
handle.should respond_to(:hello)
handle.should respond_to(:world)
end
- it "installed methods should behave correctly" do
+ it "should behave correctly" do
handle.set(:hello => "a", :world => "b")
handle.hello.should == "a"
handle.world.should == "b"
handle.set(:hello => "c", :world => "d")
handle.hello.should == "c"
handle.world.should == "d"
end
- it "should allow instance evaluatin on exprs" do
+ it "should allow instance evaluating on exprs" do
handle.set(:tested => 1)
handle.instance_eval{ tested < 1 }.should be_false
end
+ it "should support an attribute called :path" do
+ handle.set(:path => 1)
+ handle.instance_eval{ path < 1 }.should be_false
+ end
+
describe "compile" do
it "should return a Proc when passed a string" do
TupleHandle.compile("true").should be_a(Proc)
end
it "should return the Proc when directly passed" do
x = lambda{ true }
TupleHandle.compile(x).should == x
+ end
+
+ it "should support an empty Hash" do
+ pred = TupleHandle.compile({})
+ pred.call.should be_true
+ end
+
+ it "should support a Hash" do
+ pred = TupleHandle.compile({:status => 10})
+ handle = TupleHandle.new
+ handle.set({:status => 20}).evaluate(pred).should be_false
+ handle.set({:status => 10}).evaluate(pred).should be_true
+ end
+
+ it "should support a Hash using keywords as attribute names" do
+ pred = TupleHandle.compile({:when => 10})
+ handle = TupleHandle.new
+ handle.set({:when => 20}).evaluate(pred).should be_false
+ handle.set({:when => 10}).evaluate(pred).should be_true
+ end
+
+ it "should support a Hash containing a Date" do
+ today = Date.today
+ pred = TupleHandle.compile({:at => today})
+ handle = TupleHandle.new
+ handle.set({:at => today}).evaluate(pred).should be_true
+ handle.set({:at => today+1}).evaluate(pred).should be_false
end
end
describe "evaluate" do
\ No newline at end of file