Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Dialect#context

  • Loading branch information...
commit aecc05fac77089f1fb1d9d8923f4912f4be989bf 1 parent f5ec0c5
@blambeau authored
Showing with 33 additions and 0 deletions.
  1. +5 −0 lib/wlang/dialect.rb
  2. +28 −0 spec/unit/dialect/test_context.rb
View
5 lib/wlang/dialect.rb
@@ -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
View
28 spec/unit/dialect/test_context.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.