[macruby-changes] [4620] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 03:49:43 PDT 2010
Revision: 4620
http://trac.macosforge.org/projects/ruby/changeset/4620
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 03:49:42 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Assign the current context to IRB::Context.current during the runloop.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/context.rb
DietRB/trunk/spec/context_spec.rb
Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb 2010-10-08 10:49:33 UTC (rev 4619)
+++ DietRB/trunk/lib/irb/context.rb 2010-10-08 10:49:42 UTC (rev 4620)
@@ -4,6 +4,13 @@
class Context
class << self
attr_accessor :current
+
+ def make_current(context)
+ before, @current = @current, context
+ yield
+ ensure
+ @current = before
+ end
end
attr_reader :object, :binding, :line, :source
@@ -28,10 +35,11 @@
end
def run
- self.class.current = self
- while line = readline
- continue = process_line(line)
- break unless continue
+ self.class.make_current(self) do
+ while line = readline
+ continue = process_line(line)
+ break unless continue
+ end
end
end
@@ -80,4 +88,4 @@
@source = Source.new
end
end
-end
\ No newline at end of file
+end
Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb 2010-10-08 10:49:33 UTC (rev 4619)
+++ DietRB/trunk/spec/context_spec.rb 2010-10-08 10:49:42 UTC (rev 4620)
@@ -1,6 +1,19 @@
require File.expand_path('../spec_helper', __FILE__)
require 'tempfile'
+class << Readline
+ attr_reader :received
+
+ def stub_input(*input)
+ @input = input
+ end
+
+ def readline(prompt, history)
+ @received = [prompt, history]
+ @input.shift
+ end
+end
+
main = self
describe "IRB::Context" do
@@ -45,6 +58,16 @@
@context.format_exception(exception).should ==
"NameError: uninitialized constant Bacon::Context::DoesNotExist\n\t#{exception.backtrace.join("\n\t")}"
end
+
+ it "makes itself the current running context during the runloop and resigns once it's done" do
+ IRB::Context.current.should == nil
+
+ Readline.stub_input("current_during_run = IRB::Context.current")
+ @context.run
+ eval('current_during_run', @context.binding).should == @context
+
+ IRB::Context.current.should == nil
+ end
end
describe "IRB::Context, when evaluating source" do
@@ -89,19 +112,6 @@
end
end
-class << Readline
- attr_reader :received
-
- def stub_input(*input)
- @input = input
- end
-
- def readline(prompt, history)
- @received = [prompt, history]
- @input.shift
- end
-end
-
describe "IRB::Context, when receiving input" do
before do
@context = IRB::Context.new(main)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/c3957be0/attachment.html>
More information about the macruby-changes
mailing list