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:
parent
72b486f43b
commit
aec888e7bc
3 changed files with 67 additions and 41 deletions
|
@ -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)
|
||||
|
|
|
@ -55,15 +55,15 @@ describe Pry::CommandSet do
|
|||
end
|
||||
|
||||
it 'should use the first argument as context' do
|
||||
ctx = @ctx
|
||||
|
||||
@set.command 'foo' do
|
||||
self.context.should == ctx
|
||||
end
|
||||
inside = inner_scope do |probe|
|
||||
@set.command('foo', &probe)
|
||||
|
||||
@set.run_command @ctx, 'foo'
|
||||
end
|
||||
|
||||
expect(inside.context).to eq(@ctx)
|
||||
end
|
||||
|
||||
it 'should raise an error when calling an undefined command' do
|
||||
@set.command('foo') {}
|
||||
expect { @set.run_command @ctx, 'bar' }.to raise_error Pry::NoCommandError
|
||||
|
@ -620,28 +620,32 @@ describe Pry::CommandSet do
|
|||
:output => StringIO.new,
|
||||
:target => binding
|
||||
}
|
||||
|
||||
inside = inner_scope do |probe|
|
||||
@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]
|
||||
end
|
||||
define_method(:process, &probe)
|
||||
end
|
||||
|
||||
@set.process_line('agnes', ctx)
|
||||
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
|
||||
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
|
||||
inside = inner_scope do |probe|
|
||||
@set.create_command(/nann+y ogg+/) do
|
||||
define_method(:process, &probe)
|
||||
end
|
||||
|
||||
@set.process_line('nannnnnny oggggg')
|
||||
end
|
||||
|
||||
expect(inside.command_set).to eq(@set)
|
||||
end
|
||||
end
|
||||
|
||||
if defined?(Bond)
|
||||
|
|
|
@ -137,32 +137,48 @@ describe "Pry::Command" do
|
|||
end
|
||||
|
||||
describe 'context' do
|
||||
context = {
|
||||
let(:context) {
|
||||
{
|
||||
:target => binding,
|
||||
:output => StringIO.new,
|
||||
:eval_string => "eval-string",
|
||||
:command_set => @set,
|
||||
:pry_instance => Pry.new
|
||||
}
|
||||
}
|
||||
|
||||
describe '#setup' do
|
||||
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]
|
||||
end
|
||||
|
||||
define_method(:process) do
|
||||
eval_string.should == "eval-string"
|
||||
command_set.should == @set
|
||||
_pry_.should == context[:pry_instance]
|
||||
end
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
describe 'classy api' do
|
||||
|
@ -385,14 +401,14 @@ describe "Pry::Command" do
|
|||
end
|
||||
|
||||
it "should set the commands' arg_string and captures" do
|
||||
|
||||
cmd = @set.command /benj(ie|ei)/ do |*args|
|
||||
self.arg_string.should == "mouse"
|
||||
self.captures.should == ['ie']
|
||||
args.should == ['ie', 'mouse']
|
||||
end
|
||||
inside = inner_scope { |probe|
|
||||
cmd = @set.command(/benj(ie|ei)/, &probe)
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue