diff --git a/CHANGES.md b/CHANGES.md index 4c78df7..8be6d32 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ * Removed Ramaze direct support. Use Rack instead. * Introduced API#format_backtrace * Introduced API#puts +* [more/anchor] Fixed multiline support when anchoring on an object * [more/caller] Added for showing formatted call stack * [core/underscore] This is changed to `core/last_value`, and the API is changed to `Rib.last_value` and `Rib.last_exception`. Surely this is less diff --git a/lib/rib/api.rb b/lib/rib/api.rb index 3e5628d..55a5c81 100644 --- a/lib/rib/api.rb +++ b/lib/rib/api.rb @@ -74,7 +74,11 @@ def eval_input input # Evaluate user input with #eval_binding, name and line def loop_eval input - eval_binding.eval(input, "(#{name})", line) + if eval_binding.kind_of?(Binding) + eval_binding.eval(input, "(#{name})", line) + else + eval_binding.instance_eval(input, "(#{name})", line) + end end # Print result using #format_result diff --git a/lib/rib/more/anchor.rb b/lib/rib/more/anchor.rb index 33beb99..545285f 100644 --- a/lib/rib/more/anchor.rb +++ b/lib/rib/more/anchor.rb @@ -7,15 +7,6 @@ module Rib::Anchor # --------------- Rib API --------------- - def loop_eval input - return super if Rib::Anchor.disabled? - if eval_binding.kind_of?(Binding) - super - else - eval_binding.instance_eval(input, "(#{name})", line) - end - end - def prompt return super if Rib::Anchor.disabled? return super unless config[:prompt_anchor] diff --git a/lib/rib/test.rb b/lib/rib/test.rb index 215ae4c..4f0a903 100644 --- a/lib/rib/test.rb +++ b/lib/rib/test.rb @@ -7,13 +7,14 @@ require 'rib' copy :rib do - before do - end - after do Muack.verify end + def new_shell + Rib::Shell.new(:binding => Object.new.instance_eval{binding}).before_loop + end + singleton_class.module_eval do def test_for *plugins, &block require 'rib/all' # exhaustive tests diff --git a/lib/rib/test/multiline.rb b/lib/rib/test/multiline.rb index 7eee296..3c368d2 100644 --- a/lib/rib/test/multiline.rb +++ b/lib/rib/test/multiline.rb @@ -1,8 +1,7 @@ copy :setup_multiline do def setup_shell - @shell = Rib::Shell.new( - :binding => Object.new.instance_eval{binding}).before_loop + @shell = new_shell stub(@shell).print{}.with_any_args stub(@shell).puts{} .with_any_args end @@ -30,7 +29,16 @@ def input_done str, err=nil mock(@shell).print_result(is_a(Object)){} end @shell.loop_once - true.should.eq true + ok + end + + def check str, err=nil + lines = str.split("\n") + lines[0...-1].each{ |line| + input(line) + @shell.loop_once + } + input_done(lines.last, err) end end diff --git a/test/core/test_last_value.rb b/test/core/test_last_value.rb index 623fc4e..d63291c 100644 --- a/test/core/test_last_value.rb +++ b/test/core/test_last_value.rb @@ -25,7 +25,7 @@ paste :rib before do - @shell = Rib::Shell.new + @shell = new_shell stub(@shell).puts(is_a(String)){} stub(Rib).shell{ @shell } end diff --git a/test/core/test_multiline.rb b/test/core/test_multiline.rb index 5a6a9f2..4c59206 100644 --- a/test/core/test_multiline.rb +++ b/test/core/test_multiline.rb @@ -7,15 +7,6 @@ paste :rib paste :setup_multiline - def check str, err=nil - lines = str.split("\n") - lines[0...-1].each{ |line| - input(line) - @shell.loop_once - } - input_done(lines.last, err) - end - test_for Rib::Multiline do paste :multiline end diff --git a/test/extra/test_anchor.rb b/test/extra/test_anchor.rb new file mode 100644 index 0000000..a79d97e --- /dev/null +++ b/test/extra/test_anchor.rb @@ -0,0 +1,18 @@ + +require 'rib/test' +require 'rib/more/anchor' +require 'rib/core/multiline' +require 'rib/test/multiline' + +describe Rib::Anchor do + paste :rib + paste :setup_multiline + + def new_shell + Rib::Shell.new(:binding => Class.new).before_loop + end + + test_for Rib::Anchor, Rib::Multiline do + paste :multiline + end +end