Permalink
Browse files

Add Dialect#context

  • Loading branch information...
blambeau committed Jun 13, 2012
1 parent f5ec0c5 commit aecc05fac77089f1fb1d9d8923f4912f4be989bf
Showing with 33 additions and 0 deletions.
  1. +5 −0 lib/wlang/dialect.rb
  2. +28 −0 spec/unit/dialect/test_context.rb
View
@@ -153,6 +153,11 @@ def render(fn, scope = nil, buffer = "")
# evaluation
+ # Returns the execution context, defined as the subject of the root scope.
+ def context
+ scope.root.subject
+ end
+
# Returns the current rendering scope.
def scope
@scope || Scope.null
@@ -0,0 +1,28 @@
+require 'spec_helper'
+module WLang
+ describe Dialect, 'context' do
+
+ let(:dialect){ Dialect.new }
+
+ subject{ dialect.context }
+
+ it 'defaults to nil if no scope' do
+ subject.should be_nil
+ end
+
+ it "is the scope's subject when one scope" do
+ dialect.with_scope(:x) do
+ subject.should eq(:x)
+ end
+ end
+
+ it "is the root scope's subject when multiple scope" do
+ dialect.with_scope(:x) do
+ dialect.with_scope(:y) do
+ subject.should eq(:x)
+ end
+ end
+ end
+
+ end
+end

0 comments on commit aecc05f

Please sign in to comment.