require "spec_helper" describe "Expressive" do before(:each) do @scope = TopLevel.new end describe "understands booleans" do it { Expressive.run("true").should eql true } it { Expressive.run("false").should eql false } end describe "understands numbers" do it { Expressive.run("5").should eql 5 } it { Expressive.run("5.5").should eql 5.5 } end it "understands variables" do @scope["hello"] = "World" Expressive.run("hello", @scope).should eql "World" end describe "understands arithmetic" do it { Expressive.run("(+ 4 2)").should eql 6 } it { Expressive.run("(- 4 2)").should eql 2 } it { Expressive.run("(* 4 2)").should eql 8 } it { Expressive.run("(/ 4 2)").should eql 2 } it { Expressive.run("(sum 1 2 3)").should eql 6} end describe "understands compound statements" do it { Expressive.run("(= (+ 4 2) 6)").should eql true } end context "looking up an id based on a value" do it "should use the lookup method, find an id based on value" do #Expressive.run("lookup_case_state 'not_started'", @scope) #@payload[:_].should eql 1 end end context "when setting simple properties" do it "should set order_no to 1234" do Expressive.run("(set order_no 1234)", @scope).should eql 1234 @scope["order_no"].should eql 1234 end it "should reuse set properties" do Expressive.run("(set order_no 1234)(+ order_no 11)", @scope).should eql 1245 end it "should sum scoped arrays" do @scope["sub_totals"] = [100, 200, 300] Expressive.run("(sum sub_totals)", @scope).should eql 600 end end context "when setting complex properties" do context "e.g. current_state" do before(:each) { Expressive.run("(set current_state (lookup_case_state, 'not started'))", @scope) } it "should set current_state to 'started'" it "should set current_state_id to 2" end context "e.g. owned_by" do it "should set owned_by_id to 1" it "should set owned_by_type to 'CaseBlocks::User'" end end context "when setting multiple properties" do # it { # Expressive.apply_to @scope do |scope| # apply "set order_no 1234" # apply "set current_state (lookup case_state 'not started')" # apply "set owned_by (lookup_user_by_email 'ijonas@ijonas.com')" # end # @scope["order_no"].should eql "1234" # } end context "register external lookup functions" do end end