1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Update specs using inner_scope helper

This commit is contained in:
Christian Haase 2014-09-12 18:40:37 +02:00 committed by Ryan Fitzgerald
parent 72b486f43b
commit aec888e7bc
3 changed files with 67 additions and 41 deletions

View file

@ -73,6 +73,12 @@ module PryTestHelpers
e.define_singleton_method(:backtrace) { mock_backtrace }
end
end
def inner_scope
catch(:inner_scope) do
yield ->{ throw(:inner_scope, self) }
end
end
end
def pry_tester(*args, &block)

View file

@ -55,13 +55,13 @@ describe Pry::CommandSet do
end
it 'should use the first argument as context' do
ctx = @ctx
inside = inner_scope do |probe|
@set.command('foo', &probe)
@set.command 'foo' do
self.context.should == ctx
@set.run_command @ctx, 'foo'
end
@set.run_command @ctx, 'foo'
expect(inside.context).to eq(@ctx)
end
it 'should raise an error when calling an undefined command' do
@ -620,27 +620,31 @@ describe Pry::CommandSet do
:output => StringIO.new,
:target => binding
}
@set.create_command('agnes') do
define_method(:process) do
eval_string.should == ctx[:eval_string]
output.should == ctx[:output]
target.should == ctx[:target]
_pry_.should == ctx[:pry_instance]
inside = inner_scope do |probe|
@set.create_command('agnes') do
define_method(:process, &probe)
end
@set.process_line('agnes', ctx)
end
@set.process_line('agnes', ctx)
expect(inside.eval_string).to eq(ctx[:eval_string])
expect(inside.output).to eq(ctx[:output])
expect(inside.target).to eq(ctx[:target])
expect(inside._pry_).to eq(ctx[:pry_instance])
end
it 'should add command_set to context' do
set = @set
@set.create_command(/nann+y ogg+/) do
define_method(:process) do
command_set.should == set
inside = inner_scope do |probe|
@set.create_command(/nann+y ogg+/) do
define_method(:process, &probe)
end
@set.process_line('nannnnnny oggggg')
end
@set.process_line('nannnnnny oggggg')
expect(inside.command_set).to eq(@set)
end
end

View file

@ -137,31 +137,47 @@ describe "Pry::Command" do
end
describe 'context' do
context = {
:target => binding,
:output => StringIO.new,
:eval_string => "eval-string",
:command_set => @set,
:pry_instance => Pry.new
let(:context) {
{
:target => binding,
:output => StringIO.new,
:eval_string => "eval-string",
:command_set => @set,
:pry_instance => Pry.new
}
}
it 'should capture lots of stuff from the hash passed to new before setup' do
cmd = @set.create_command 'fenchurch', "Floats slightly off the ground" do
define_method(:setup) do
self.context.should == context
target.should == context[:target]
target_self.should == context[:target].eval('self')
output.should == context[:output]
describe '#setup' do
it 'should capture lots of stuff from the hash passed to new before setup' do
inside = inner_scope do |probe|
cmd = @set.create_command('fenchurch', "Floats slightly off the ground") do
define_method(:setup, &probe)
end
cmd.new(context).call
end
define_method(:process) do
eval_string.should == "eval-string"
command_set.should == @set
_pry_.should == context[:pry_instance]
end
expect(inside.context).to eq(context)
expect(inside.target).to eq(context[:target])
expect(inside.target_self).to eq(context[:target].eval('self'))
expect(inside.output).to eq(context[:output])
end
end
cmd.new(context).call
describe '#process' do
it 'should capture lots of stuff from the hash passed to new before setup' do
inside = inner_scope do |probe|
cmd = @set.create_command('fenchurch', "Floats slightly off the ground") do
define_method(:process, &probe)
end
cmd.new(context).call
end
expect(inside.eval_string).to eq("eval-string")
expect(inside.__send__(:command_set)).to eq(@set)
expect(inside._pry_).to eq(context[:pry_instance])
end
end
end
@ -385,14 +401,14 @@ describe "Pry::Command" do
end
it "should set the commands' arg_string and captures" do
inside = inner_scope { |probe|
cmd = @set.command(/benj(ie|ei)/, &probe)
cmd = @set.command /benj(ie|ei)/ do |*args|
self.arg_string.should == "mouse"
self.captures.should == ['ie']
args.should == ['ie', 'mouse']
end
cmd.new.process_line %(benjie mouse)
}
cmd.new.process_line %(benjie mouse)
expect(inside.arg_string).to eq("mouse")
expect(inside.captures).to eq(['ie'])
end
it "should raise an error if the line doesn't match the command" do