Skip to content

Commit

Permalink
Fix multiline for anchoring on an object
Browse files Browse the repository at this point in the history
  • Loading branch information
godfat committed Feb 26, 2017
1 parent b828d02 commit e906253
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/rib/api.rb
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions lib/rib/more/anchor.rb
Expand Up @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions lib/rib/test.rb
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions 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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/core/test_last_value.rb
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions test/core/test_multiline.rb
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions 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

0 comments on commit e906253

Please sign in to comment.