Sha256: f3748f71ffa6f85a1afc719571617ed3d8d5adaa38fd883b1e3ed3e02a893ae0
Contents?: true
Size: 1.33 KB
Versions: 12
Compression:
Stored size: 1.33 KB
Contents
require 'spec_helper' module WLang describe Dialect, 'evaluate' do let(:struct){ Struct.new(:who) } let(:dialect){ Dialect.new } def with_scope(*args, &bl) dialect.with_scope(*args, &bl) end def evaluate(*args, &bl) dialect.evaluate(*args, &bl) end it 'works with a hash' do with_scope({:who => "World"}) do evaluate("who").should eq("World") evaluate(:who).should eq("World") end end it 'works with a struct' do with_scope(struct.new("World")) do evaluate("who").should eq("World") evaluate(:who).should eq("World") end end it 'uses the hash in priority' do with_scope({:keys => [1,2,3]}) do evaluate("keys").should eq([1,2,3]) end end it 'falls back to send' do with_scope({:who => "World"}) do evaluate("keys").should eq([:who]) end end it 'supports a default value' do evaluate("who", 12).should eq(12) evaluate("who", nil).should be_nil end it 'supports a default value through a Proc' do evaluate("who"){ 12 }.should eq(12) evaluate("who"){ nil }.should be_nil end it 'raises a NameError when not found' do lambda{ evaluate("who") }.should raise_error(NameError) end end # describe Dialect, 'evaluate' end # module WLang
Version data entries
12 entries across 12 versions & 1 rubygems