spec/expressive_spec.rb in expressive-0.0.32 vs spec/expressive_spec.rb in expressive-0.0.33

- old
+ new

@@ -4,11 +4,11 @@ before(:each) do @scope = Expressive::TopLevel.new end describe "all_symbols" do - it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval $index $random $join) } + it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval $index $random $join $not) } end describe "understands booleans" do it { Expressive.run("true").should eql true } it { Expressive.run("false").should eql false } @@ -285,10 +285,30 @@ it { Expressive.run('(and true nil_value)', @scope).should eql false } it { Expressive.run('(and nil_value true)', @scope).should eql false } it { Expressive.run('(or nil_value true)', @scope).should eql true } it { Expressive.run('(or nil_value false)', @scope).should eql false } end + + context "not - negate a boolean" do + before(:each) do + @scope["key1"] = "value1" + @scope["key2"] = "value2" + @scope["key3"] = "value1" + @scope["key4"] = nil + end + it { Expressive.run('($not true)', @scope).should eql false } + it { Expressive.run('($not false)', @scope).should eql true } + it { Expressive.run('($not (= 1 2))', @scope).should eql true} + it { Expressive.run('($not (= 1 1))', @scope).should eql false} + it { Expressive.run('($not (= key1 key2))', @scope).should eql true} + it { Expressive.run('($not (= key1 key3))', @scope).should eql false} + it { Expressive.run("($not (= key1 ''))", @scope).should eql true} + it { Expressive.run('($not (= key1 "value1"))', @scope).should eql false} + it { Expressive.run('($not (= key4 "value2"))', @scope).should eql true} + it { Expressive.run('($not (= key4 ''))', @scope).should eql false} + + end end describe "generates random values" do it "generates random literal values" do [1, 2, 3, 4].include?(Expressive.run('($random 1 2 3 4)', @scope)).should be_true @@ -726,6 +746,16 @@ assert_requested(request) @scope['goodbye'].should eql 'srsly' end end end + + describe "parse error handling" do + it "should raise parse exceptions" do + expect{ Expressive.run(nil) }.to raise_error Expressive::ParseError, "Error parsing nil expression: undefined method `length' for nil:NilClass" + end + it "should raise runtime exceptions" do + expect{ Expressive.run('( 1 2') }.to raise_error Expressive::RunError, "Error running '( 1 2': private method `eval' called for nil:NilClass" + end + end + end