spec/expressive_spec.rb in expressive-0.0.8 vs spec/expressive_spec.rb in expressive-0.0.9
- 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 get put post >= > < <= and or if date) }
+ it { Expressive.all_symbols.should =~ %w(+ - * / = set sum get put post >= > < <= and or if date lookup) }
end
describe "understands booleans" do
it { Expressive.run("true").should eql true }
it { Expressive.run("false").should eql false }
@@ -93,13 +93,14 @@
Expressive.run('(set vsi "vsi1234")', @scope).should eql "vsi1234"
@scope['vsi'].should eql 'vsi1234'
end
it "using multiple set commands" do
- Expressive.run('(and (set vsi "vsi1234") (set vso "vso1234"))', @scope).should eql true
+ Expressive.run('(and (set vsi "vsi1234") (set vso "vso1234") (set vsbool true))', @scope).should eql true
@scope['vsi'].should eql 'vsi1234'
@scope['vso'].should eql 'vso1234'
+ @scope['vsbool'].should be_true
end
end
describe "understands date parsing" do
it "will return the current date" do
@@ -110,9 +111,43 @@
end
it "will return a date parsed from text" do
date = Date.new(2012, 11, 22).to_time.utc
Expressive.run('(date(22/11/2012))').should eql date
+ end
+ end
+
+ describe "understands using lookup tables" do
+ before(:each) do
+ @user1 = mock(:user, id:1, login: "user1", display_name: "User 1")
+ @user2 = mock(:user, id:2, login: "user2", display_name: "User 2")
+ @scope.add_lookup_table("users", @user1.login => @user1, @user2.login => @user2)
+ @scope.add_lookup_table("users", "x_current" => @user2)
+ end
+
+ it "will return a value from a lookup table" do
+ Expressive.run('(lookup users "x_current")', @scope).should eql @user2
+ Expressive.run('(lookup users "user1")', @scope).should eql @user1
+ end
+ it "will set multiple values based on results of a lookup" do
+ @owned_by_ext_value = Expressive::ExtendedValue.new(:x_owned_by, @scope)
+ @owned_by_ext_value.setter = Proc.new do |value, scope|
+ scope["owned_by_id"] = value.id
+ scope["owned_by_type"] = value.class.to_s
+ end
+
+ Expressive.run('(set x_owned_by (lookup users "x_current"))', @scope)
+ @scope["owned_by_id"].should eql @user2.id
+ @scope["owned_by_type"].should eql "RSpec::Mocks::Mock"
+ end
+ end
+
+ describe "understands using lookup functions" do
+ it "should perform the lookup function (add account and reverse login)" do
+ @scope.add_lookup_function("account_reverse_login", account: "ea") do |options, login|
+ "#{options[:account]}-#{login.reverse}"
+ end
+ Expressive.run('(lookup account_reverse_login "ijonas")', @scope).should eql "ea-sanoji"
end
end
describe "understands web-hook statements" do
context "put" do