2011-05-06 06:43:08 -04:00
|
|
|
describe Pry::CommandSet do
|
|
|
|
before do
|
2012-08-11 20:22:29 -04:00
|
|
|
@set = Pry::CommandSet.new do
|
|
|
|
import Pry::Commands
|
|
|
|
end
|
|
|
|
|
2011-12-31 06:10:23 -05:00
|
|
|
@ctx = {
|
2018-10-12 15:09:29 -04:00
|
|
|
target: binding,
|
|
|
|
command_set: @set,
|
|
|
|
pry_instance: Pry.new(output: StringIO.new)
|
2011-12-31 06:10:23 -05:00
|
|
|
}
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2013-09-22 05:21:51 -04:00
|
|
|
describe "[]=" do
|
|
|
|
it "removes a command from the command set" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set["help"]).not_to eq nil
|
2013-09-22 05:21:51 -04:00
|
|
|
@set["help"] = nil
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set["help"]).to eq nil
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set.run_command(TOPLEVEL_BINDING, "help") }.to raise_error Pry::NoCommandError
|
2013-09-22 05:21:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "replaces a command" do
|
|
|
|
old_help = @set["help"]
|
|
|
|
@set["help"] = @set["pry-version"]
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set["help"]).not_to eq old_help
|
2013-09-22 05:21:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "rebinds the command with key" do
|
|
|
|
@set["help-1"] = @set["help"]
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set["help-1"].match).to eq "help-1"
|
2013-09-22 05:21:51 -04:00
|
|
|
end
|
2013-09-22 05:39:10 -04:00
|
|
|
|
|
|
|
it "raises a TypeError when command is not a subclass of Pry::Command" do
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set["help"] = "hello" }.to raise_error TypeError
|
2013-09-22 05:39:10 -04:00
|
|
|
end
|
2013-09-22 05:21:51 -04:00
|
|
|
end
|
|
|
|
|
2011-05-06 06:43:08 -04:00
|
|
|
it 'should call the block used for the command when it is called' do
|
|
|
|
run = false
|
|
|
|
@set.command 'foo' do
|
|
|
|
run = true
|
|
|
|
end
|
|
|
|
|
2011-09-25 02:52:07 -04:00
|
|
|
@set.run_command @ctx, 'foo'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should pass arguments of the command to the block' do
|
2018-11-17 11:36:09 -05:00
|
|
|
expect do |probe|
|
2014-09-12 11:55:59 -04:00
|
|
|
@set.command('foo', &probe)
|
|
|
|
@set.run_command(@ctx, 'foo', 1, 2, 3)
|
2018-11-17 11:36:09 -05:00
|
|
|
end.to yield_with_args(1, 2, 3)
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2011-12-31 06:10:23 -05:00
|
|
|
it 'should use the first argument as context' do
|
2014-09-12 12:40:37 -04:00
|
|
|
inside = inner_scope do |probe|
|
|
|
|
@set.command('foo', &probe)
|
2011-09-25 02:52:07 -04:00
|
|
|
|
2014-09-12 12:40:37 -04:00
|
|
|
@set.run_command @ctx, 'foo'
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2014-09-12 12:40:37 -04:00
|
|
|
expect(inside.context).to eq(@ctx)
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2011-05-23 02:34:11 -04:00
|
|
|
it 'should raise an error when calling an undefined command' do
|
2011-05-06 06:43:08 -04:00
|
|
|
@set.command('foo') {}
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set.run_command @ctx, 'bar' }.to raise_error Pry::NoCommandError
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to remove its own commands' do
|
|
|
|
@set.command('foo') {}
|
|
|
|
@set.delete 'foo'
|
|
|
|
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set.run_command @ctx, 'foo' }.to raise_error Pry::NoCommandError
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2011-11-15 08:51:17 -05:00
|
|
|
it 'should be able to remove its own commands, by listing name' do
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.command(/^foo1/, 'desc', listing: 'foo') {}
|
2011-11-15 08:51:17 -05:00
|
|
|
@set.delete 'foo'
|
|
|
|
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set.run_command @ctx, /^foo1/ }.to raise_error Pry::NoCommandError
|
2011-11-15 08:51:17 -05:00
|
|
|
end
|
|
|
|
|
2011-05-06 06:43:08 -04:00
|
|
|
it 'should be able to import some commands from other sets' do
|
|
|
|
run = false
|
|
|
|
|
2011-05-07 01:32:05 -04:00
|
|
|
other_set = Pry::CommandSet.new do
|
2011-05-06 06:43:08 -04:00
|
|
|
command('foo') { run = true }
|
|
|
|
command('bar') {}
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.import_from(other_set, 'foo')
|
|
|
|
|
2011-09-25 02:52:07 -04:00
|
|
|
@set.run_command @ctx, 'foo'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2011-05-06 06:43:08 -04:00
|
|
|
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set.run_command @ctx, 'bar' }.to raise_error Pry::NoCommandError
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2012-04-02 06:15:27 -04:00
|
|
|
it 'should return command set after import' do
|
|
|
|
run = false
|
|
|
|
|
|
|
|
other_set = Pry::CommandSet.new do
|
|
|
|
command('foo') { run = true }
|
|
|
|
command('bar') {}
|
|
|
|
end
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.import(other_set)).to eq @set
|
2012-04-02 06:15:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return command set after import_from' do
|
|
|
|
run = false
|
|
|
|
|
|
|
|
other_set = Pry::CommandSet.new do
|
|
|
|
command('foo') { run = true }
|
|
|
|
command('bar') {}
|
|
|
|
end
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.import_from(other_set, 'foo')).to eq @set
|
2012-04-02 06:15:27 -04:00
|
|
|
end
|
|
|
|
|
2011-11-15 08:51:17 -05:00
|
|
|
it 'should be able to import some commands from other sets using listing name' do
|
|
|
|
run = false
|
|
|
|
|
|
|
|
other_set = Pry::CommandSet.new do
|
2018-10-12 15:09:29 -04:00
|
|
|
command(/^foo1/, 'desc', listing: 'foo') { run = true }
|
2011-11-15 08:51:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
@set.import_from(other_set, 'foo')
|
|
|
|
|
|
|
|
@set.run_command @ctx, /^foo1/
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2011-11-15 08:51:17 -05:00
|
|
|
end
|
|
|
|
|
2011-05-06 06:43:08 -04:00
|
|
|
it 'should be able to import a whole set' do
|
|
|
|
run = []
|
|
|
|
|
2011-05-07 01:32:05 -04:00
|
|
|
other_set = Pry::CommandSet.new do
|
2011-05-06 06:43:08 -04:00
|
|
|
command('foo') { run << true }
|
|
|
|
command('bar') { run << true }
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.import other_set
|
|
|
|
|
2011-09-25 02:52:07 -04:00
|
|
|
@set.run_command @ctx, 'foo'
|
|
|
|
@set.run_command @ctx, 'bar'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq [true, true]
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to import sets at creation' do
|
|
|
|
run = false
|
|
|
|
@set.command('foo') { run = true }
|
|
|
|
|
2011-09-25 02:52:07 -04:00
|
|
|
Pry::CommandSet.new(@set).run_command @ctx, 'foo'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should set the descriptions of commands' do
|
|
|
|
@set.command('foo', 'some stuff') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['foo'].description).to eq 'some stuff'
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2012-03-25 07:26:48 -04:00
|
|
|
describe "aliases" do
|
|
|
|
it 'should be able to alias command' do
|
|
|
|
run = false
|
|
|
|
@set.command('foo', 'stuff') { run = true }
|
2011-05-06 06:43:08 -04:00
|
|
|
|
2012-03-25 07:26:48 -04:00
|
|
|
@set.alias_command 'bar', 'foo'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['bar'].match).to eq 'bar'
|
|
|
|
expect(@set['bar'].description).to eq 'Alias for `foo`'
|
2011-05-06 06:43:08 -04:00
|
|
|
|
2012-03-25 07:26:48 -04:00
|
|
|
@set.run_command @ctx, 'bar'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2012-03-25 07:26:48 -04:00
|
|
|
end
|
2011-05-06 06:43:08 -04:00
|
|
|
|
2013-12-17 09:24:34 -05:00
|
|
|
it "should be able to alias command with command_prefix" do
|
|
|
|
run = false
|
2014-02-15 09:37:07 -05:00
|
|
|
|
2014-02-15 08:29:59 -05:00
|
|
|
begin
|
|
|
|
@set.command('owl', 'stuff') { run = true }
|
|
|
|
@set.alias_command 'owlet', 'owl'
|
|
|
|
|
|
|
|
Pry.config.command_prefix = '%'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['%owlet'].match).to eq 'owlet'
|
|
|
|
expect(@set['%owlet'].description).to eq 'Alias for `owl`'
|
2014-02-15 08:29:59 -05:00
|
|
|
|
|
|
|
@set.run_command @ctx, 'owlet'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2014-02-15 08:29:59 -05:00
|
|
|
ensure
|
|
|
|
Pry.config.command_prefix = ''
|
|
|
|
end
|
2013-12-17 09:24:34 -05:00
|
|
|
end
|
|
|
|
|
2012-04-12 04:58:59 -04:00
|
|
|
it 'should inherit options from original command' do
|
|
|
|
run = false
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.command('foo', 'stuff', shellwords: true, interpolate: false) { run = true }
|
2012-04-12 04:58:59 -04:00
|
|
|
|
|
|
|
@set.alias_command 'bar', 'foo'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['bar'].options[:shellwords]).to eq @set['foo'].options[:shellwords]
|
|
|
|
expect(@set['bar'].options[:interpolate]).to eq @set['foo'].options[:interpolate]
|
2012-04-12 04:58:59 -04:00
|
|
|
|
|
|
|
# however some options should not be inherited
|
2018-10-12 12:54:00 -04:00
|
|
|
expect(@set['bar'].options[:listing]).not_to eq @set['foo'].options[:listing]
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['bar'].options[:listing]).to eq "bar"
|
2012-04-12 04:58:59 -04:00
|
|
|
end
|
|
|
|
|
2012-03-25 07:26:48 -04:00
|
|
|
it 'should be able to specify alias\'s description when aliasing' do
|
|
|
|
run = false
|
|
|
|
@set.command('foo', 'stuff') { run = true }
|
2011-11-15 08:51:17 -05:00
|
|
|
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.alias_command 'bar', 'foo', desc: "tobina"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['bar'].match).to eq 'bar'
|
|
|
|
expect(@set['bar'].description).to eq "tobina"
|
2011-11-15 08:51:17 -05:00
|
|
|
|
2012-03-25 07:26:48 -04:00
|
|
|
@set.run_command @ctx, 'bar'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2012-03-25 07:26:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be able to alias a command by its invocation line" do
|
|
|
|
run = false
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.command(/^foo1/, 'stuff', listing: 'foo') { run = true }
|
2012-03-25 07:26:48 -04:00
|
|
|
|
|
|
|
@set.alias_command 'bar', 'foo1'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['bar'].match).to eq 'bar'
|
|
|
|
expect(@set['bar'].description).to eq 'Alias for `foo1`'
|
2012-03-25 07:26:48 -04:00
|
|
|
|
|
|
|
@set.run_command @ctx, 'bar'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2012-03-25 07:26:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be able to specify options when creating alias" do
|
|
|
|
run = false
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.command(/^foo1/, 'stuff', listing: 'foo') { run = true }
|
2012-03-25 07:26:48 -04:00
|
|
|
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.alias_command(/^b.r/, 'foo1', listing: "bar")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.to_hash[/^b.r/].options[:listing]).to eq "bar"
|
2012-03-25 07:26:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should set description to default if description parameter is nil" do
|
|
|
|
run = false
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.command(/^foo1/, 'stuff', listing: 'foo') { run = true }
|
2012-03-25 07:26:48 -04:00
|
|
|
|
2012-03-25 11:01:07 -04:00
|
|
|
@set.alias_command "bar", 'foo1'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set["bar"].description).to eq "Alias for `foo1`"
|
2012-03-25 07:26:48 -04:00
|
|
|
end
|
2011-11-15 08:51:17 -05:00
|
|
|
end
|
|
|
|
|
2011-11-15 09:09:16 -05:00
|
|
|
it 'should be able to change the descriptions of commands' do
|
2011-05-06 06:43:08 -04:00
|
|
|
@set.command('foo', 'bar') {}
|
|
|
|
@set.desc 'foo', 'baz'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['foo'].description).to eq 'baz'
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2011-11-15 09:09:16 -05:00
|
|
|
it 'should get the descriptions of commands' do
|
|
|
|
@set.command('foo', 'bar') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.desc('foo')).to eq 'bar'
|
2011-11-15 09:09:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should get the descriptions of commands, by listing' do
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.command(/^foo1/, 'bar', listing: 'foo') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.desc('foo')).to eq 'bar'
|
2011-11-15 09:09:16 -05:00
|
|
|
end
|
|
|
|
|
2011-12-31 06:50:04 -05:00
|
|
|
it 'should return Pry::Command::VOID_VALUE for commands by default' do
|
2011-05-06 06:43:08 -04:00
|
|
|
@set.command('foo') { 3 }
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.run_command(@ctx, 'foo')).to eq Pry::Command::VOID_VALUE
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to keep return values' do
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.command('foo', '', keep_retval: true) { 3 }
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.run_command(@ctx, 'foo')).to eq 3
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2011-09-03 21:30:20 -04:00
|
|
|
it 'should be able to keep return values, even if return value is nil' do
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.command('foo', '', keep_retval: true) { nil }
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.run_command(@ctx, 'foo')).to eq nil
|
2011-09-03 21:30:20 -04:00
|
|
|
end
|
|
|
|
|
2011-05-06 06:43:08 -04:00
|
|
|
it 'should be able to have its own helpers' do
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
@set.command('foo') { my_helper }
|
|
|
|
@set.helpers { def my_helper; end }
|
2011-05-06 06:43:08 -04:00
|
|
|
|
2011-09-25 02:52:07 -04:00
|
|
|
@set.run_command(@ctx, 'foo')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pry::Command.subclass('foo', '', {}, Module.new)
|
2018-10-12 15:09:29 -04:00
|
|
|
.new({target: binding}))
|
2015-03-10 16:49:29 -04:00
|
|
|
.not_to(respond_to :my_helper)
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
2011-05-23 02:34:11 -04:00
|
|
|
it 'should not recreate a new helper module when helpers is called' do
|
2011-05-06 06:43:08 -04:00
|
|
|
@set.command('foo') do
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
my_helper
|
|
|
|
my_other_helper
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@set.helpers do
|
|
|
|
def my_helper; end
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.helpers do
|
|
|
|
def my_other_helper; end
|
|
|
|
end
|
|
|
|
|
2011-09-25 02:52:07 -04:00
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should import helpers from imported sets' do
|
2011-05-07 01:32:05 -04:00
|
|
|
imported_set = Pry::CommandSet.new do
|
2011-05-06 06:43:08 -04:00
|
|
|
helpers do
|
|
|
|
def imported_helper_method; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.import imported_set
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
@set.command('foo') { imported_helper_method }
|
2011-09-25 02:52:07 -04:00
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should import helpers even if only some commands are imported' do
|
2011-05-07 01:32:05 -04:00
|
|
|
imported_set = Pry::CommandSet.new do
|
2011-05-06 06:43:08 -04:00
|
|
|
helpers do
|
|
|
|
def imported_helper_method; end
|
|
|
|
end
|
|
|
|
|
|
|
|
command('bar') {}
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.import_from imported_set, 'bar'
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
@set.command('foo') { imported_helper_method }
|
2011-09-25 02:52:07 -04:00
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|
2011-05-28 02:05:41 -04:00
|
|
|
|
|
|
|
it 'should provide a :listing for a command that defaults to its name' do
|
2018-11-17 11:36:09 -05:00
|
|
|
@set.command('foo', '') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['foo'].options[:listing]).to eq 'foo'
|
2011-05-28 02:05:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should provide a :listing for a command that differs from its name' do
|
2018-11-17 11:36:09 -05:00
|
|
|
@set.command('foo', '', listing: 'bar') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['foo'].options[:listing]).to eq 'bar'
|
2011-05-28 02:05:41 -04:00
|
|
|
end
|
2011-07-27 14:42:36 -04:00
|
|
|
|
|
|
|
it "should provide a 'help' command" do
|
2011-12-31 06:10:23 -05:00
|
|
|
@ctx[:command_set] = @set
|
|
|
|
@ctx[:output] = StringIO.new
|
2011-07-27 14:42:36 -04:00
|
|
|
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set.run_command(@ctx, 'help') }.to_not raise_error
|
2011-07-27 14:42:36 -04:00
|
|
|
end
|
|
|
|
|
2011-11-24 00:27:30 -05:00
|
|
|
describe "renaming a command" do
|
|
|
|
it 'should be able to rename and run a command' do
|
|
|
|
run = false
|
|
|
|
@set.command('foo') { run = true }
|
|
|
|
@set.rename_command('bar', 'foo')
|
|
|
|
@set.run_command(@ctx, 'bar')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2011-11-24 00:27:30 -05:00
|
|
|
end
|
|
|
|
|
2011-11-24 04:33:37 -05:00
|
|
|
it 'should accept listing name when renaming a command' do
|
|
|
|
run = false
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.command('foo', "", listing: 'love') { run = true }
|
2011-11-24 04:33:37 -05:00
|
|
|
@set.rename_command('bar', 'love')
|
|
|
|
@set.run_command(@ctx, 'bar')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(run).to eq true
|
2011-11-24 04:33:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should raise exception trying to rename non-existent command' do
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set.rename_command('bar', 'foo') }.to raise_error ArgumentError
|
2011-11-24 00:27:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should make old command name inaccessible' do
|
2018-11-04 04:34:24 -05:00
|
|
|
@set.command('foo') {}
|
2011-11-24 00:27:30 -05:00
|
|
|
@set.rename_command('bar', 'foo')
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set.run_command(@ctx, 'foo') }.to raise_error Pry::NoCommandError
|
2011-11-24 00:27:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to pass in options when renaming command' do
|
|
|
|
desc = "hello"
|
|
|
|
listing = "bing"
|
2018-11-04 04:34:24 -05:00
|
|
|
@set.command('foo') {}
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.rename_command('bar', 'foo', description: desc, listing: listing, keep_retval: true)
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set['bar'].description).to eq desc
|
|
|
|
expect(@set['bar'].options[:listing]).to eq listing
|
|
|
|
expect(@set['bar'].options[:keep_retval]).to eq true
|
2011-11-24 00:27:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
describe "before_* hook" do
|
|
|
|
it 'should be called before the original command' do
|
|
|
|
foo = []
|
|
|
|
@set.command('foo') { foo << 1 }
|
|
|
|
@set['foo'].hooks.add_hook('before_foo', 'name') { foo << 2 }
|
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
expect(foo).to eq [2, 1]
|
|
|
|
end
|
2011-11-15 08:51:17 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
it 'should be called before the original command, using listing name' do
|
|
|
|
foo = []
|
|
|
|
@set.command(/^foo1/, '', listing: 'foo') { foo << 1 }
|
|
|
|
cmd = @set.find_command_by_match_or_listing('foo')
|
|
|
|
cmd.hooks.add_hook('before_foo', 'name') { foo << 2 }
|
|
|
|
@set.run_command(@ctx, /^foo1/)
|
2011-11-15 08:51:17 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
expect(foo).to eq [2, 1]
|
|
|
|
end
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
it 'should share the context with the original command' do
|
|
|
|
@ctx[:target] = "test target string".__binding__
|
|
|
|
before_val = nil
|
|
|
|
orig_val = nil
|
|
|
|
@set.command('foo') { orig_val = target }
|
|
|
|
@set['foo'].hooks.add_hook('before_foo', 'name') { before_val = target }
|
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
expect(before_val).to eq @ctx[:target]
|
|
|
|
expect(orig_val).to eq @ctx[:target]
|
|
|
|
end
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
it 'should work when applied multiple times' do
|
|
|
|
foo = []
|
|
|
|
@set.command('foo') { foo << 1 }
|
|
|
|
@set['foo'].hooks.add_hook('before_foo', 'name1') { foo << 2 }
|
|
|
|
@set['foo'].hooks.add_hook('before_foo', 'name2') { foo << 3 }
|
|
|
|
@set['foo'].hooks.add_hook('before_foo', 'name3') { foo << 4 }
|
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
expect(foo).to eq [2, 3, 4, 1]
|
2011-11-14 09:12:19 -05:00
|
|
|
end
|
2018-11-01 03:50:31 -04:00
|
|
|
end
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
describe "after_* hooks" do
|
|
|
|
it 'should be called after the original command' do
|
|
|
|
foo = []
|
|
|
|
@set.command('foo') { foo << 1 }
|
|
|
|
@set['foo'].hooks.add_hook('after_foo', 'name') { foo << 2 }
|
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
expect(foo).to eq [1, 2]
|
|
|
|
end
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
it 'should be called after the original command, using listing name' do
|
|
|
|
foo = []
|
|
|
|
@set.command(/^foo1/, '', listing: 'foo') { foo << 1 }
|
|
|
|
cmd = @set.find_command_by_match_or_listing('foo')
|
|
|
|
cmd.hooks.add_hook('after_foo', 'name') { foo << 2 }
|
|
|
|
@set.run_command(@ctx, /^foo1/)
|
2011-11-15 08:51:17 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
expect(foo).to eq [1, 2]
|
|
|
|
end
|
2011-11-15 08:51:17 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
it 'should share the context with the original command' do
|
|
|
|
@ctx[:target] = "test target string".__binding__
|
|
|
|
after_val = nil
|
|
|
|
orig_val = nil
|
|
|
|
@set.command('foo') { orig_val = target }
|
|
|
|
@set['foo'].hooks.add_hook('after_foo', 'name') { after_val = target }
|
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
expect(after_val).to eq @ctx[:target]
|
|
|
|
expect(orig_val).to eq @ctx[:target]
|
|
|
|
end
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
it 'should determine the return value for the command' do
|
|
|
|
@set.command('foo', 'bar', keep_retval: true) { 1 }
|
|
|
|
@set['foo'].hooks.add_hook('after_foo', 'name') { 2 }
|
|
|
|
expect(@set.run_command(@ctx, 'foo')).to eq 2
|
|
|
|
end
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
it 'should work when applied multiple times' do
|
|
|
|
foo = []
|
|
|
|
@set.command('foo') { foo << 1 }
|
|
|
|
@set['foo'].hooks.add_hook('after_foo', 'name1') { foo << 2 }
|
|
|
|
@set['foo'].hooks.add_hook('after_foo', 'name2') { foo << 3 }
|
|
|
|
@set['foo'].hooks.add_hook('after_foo', 'name3') { foo << 4 }
|
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
expect(foo).to eq [1, 2, 3, 4]
|
2011-11-14 09:12:19 -05:00
|
|
|
end
|
2018-11-01 03:50:31 -04:00
|
|
|
end
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
describe "before_command and after_command" do
|
|
|
|
it 'should work when combining both before_command and after_command' do
|
|
|
|
foo = []
|
|
|
|
@set.command('foo') { foo << 1 }
|
|
|
|
@set['foo'].hooks.add_hook('after_foo', 'name') { foo << 2 }
|
|
|
|
@set['foo'].hooks.add_hook('before_foo', 'name') { foo << 3 }
|
|
|
|
@set.run_command(@ctx, 'foo')
|
2011-11-14 09:12:19 -05:00
|
|
|
|
2018-11-01 03:50:31 -04:00
|
|
|
expect(foo).to eq [3, 1, 2]
|
2011-11-14 09:12:19 -05:00
|
|
|
end
|
|
|
|
end
|
2012-01-02 19:04:47 -05:00
|
|
|
|
|
|
|
describe 'find_command' do
|
|
|
|
it 'should find commands with the right string' do
|
2018-11-04 04:34:24 -05:00
|
|
|
cmd = @set.command('rincewind') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('rincewind')).to eq cmd
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not find commands with spaces before' do
|
2018-11-04 04:34:24 -05:00
|
|
|
@set.command('luggage') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command(' luggage')).to eq nil
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should find commands with arguments after' do
|
2018-11-04 04:34:24 -05:00
|
|
|
cmd = @set.command('vetinari') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('vetinari --knock 3')).to eq cmd
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should find commands with names containing spaces' do
|
2018-11-04 04:34:24 -05:00
|
|
|
cmd = @set.command('nobby nobbs') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('nobby nobbs --steal petty-cash')).to eq cmd
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should find command defined by regex' do
|
2018-11-04 04:34:24 -05:00
|
|
|
cmd = @set.command(/(capt|captain) vimes/i) {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('Capt Vimes')).to eq cmd
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should find commands defined by regex with arguments' do
|
2018-11-04 04:34:24 -05:00
|
|
|
cmd = @set.command(/(cpl|corporal) Carrot/i) {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('cpl carrot --write-home')).to eq cmd
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not find commands by listing' do
|
2018-11-04 04:34:24 -05:00
|
|
|
@set.command(/werewol(f|ve)s?/, 'only once a month', listing: "angua") {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('angua')).to eq nil
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not find commands without command_prefix' do
|
2014-02-15 09:37:07 -05:00
|
|
|
begin
|
|
|
|
Pry.config.command_prefix = '%'
|
2018-11-04 04:34:24 -05:00
|
|
|
@set.command('detritus') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('detritus')).to eq nil
|
2014-02-15 09:37:07 -05:00
|
|
|
ensure
|
|
|
|
Pry.config.command_prefix = ''
|
|
|
|
end
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should find commands that don't use the prefix" do
|
2014-02-15 09:37:07 -05:00
|
|
|
begin
|
|
|
|
Pry.config.command_prefix = '%'
|
2018-11-04 04:34:24 -05:00
|
|
|
cmd = @set.command('colon', 'Sergeant Fred', use_prefix: false) {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('colon')).to eq cmd
|
2014-02-15 09:37:07 -05:00
|
|
|
ensure
|
|
|
|
Pry.config.command_prefix = ''
|
|
|
|
end
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
2012-02-11 18:15:22 -05:00
|
|
|
|
|
|
|
it "should find the command that has the longest match" do
|
2018-11-04 04:34:24 -05:00
|
|
|
@set.command(/\.(.*)/) {}
|
|
|
|
cmd2 = @set.command(/\.\|\|(.*)/) {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('.||')).to eq cmd2
|
2012-02-11 18:15:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should find the command that has the longest name" do
|
2018-11-04 04:34:24 -05:00
|
|
|
@set.command(/\.(.*)/) {}
|
|
|
|
cmd2 = @set.command('.||') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.find_command('.||')).to eq cmd2
|
2012-02-11 18:15:22 -05:00
|
|
|
end
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.valid_command?' do
|
|
|
|
it 'should be true for commands that can be found' do
|
2015-01-22 16:52:20 -05:00
|
|
|
@set.command('archchancellor')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.valid_command?('archchancellor of_the?(:University)')).to eq true
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be false for commands that can\'' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.valid_command?('def monkey(ape)')).to eq false
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
2012-01-02 20:47:15 -05:00
|
|
|
|
|
|
|
it 'should not cause argument interpolation' do
|
2015-01-22 16:52:20 -05:00
|
|
|
@set.command('hello')
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { @set.valid_command?('hello #{raise "futz"}') }.to_not raise_error
|
2012-01-02 20:47:15 -05:00
|
|
|
end
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.process_line' do
|
|
|
|
it 'should return Result.new(false) if there is no matching command' do
|
|
|
|
result = @set.process_line('1 + 42')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(result.command?).to eq false
|
|
|
|
expect(result.void_command?).to eq false
|
|
|
|
expect(result.retval).to eq nil
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return Result.new(true, VOID) if the command is not keep_retval' do
|
2012-01-21 18:17:43 -05:00
|
|
|
@set.create_command('mrs-cake') do
|
2012-01-02 19:04:47 -05:00
|
|
|
def process; 42; end
|
|
|
|
end
|
|
|
|
|
|
|
|
result = @set.process_line('mrs-cake')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(result.command?).to eq true
|
|
|
|
expect(result.void_command?).to eq true
|
|
|
|
expect(result.retval).to eq Pry::Command::VOID_VALUE
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return Result.new(true, retval) if the command is keep_retval' do
|
2018-10-12 15:09:29 -04:00
|
|
|
@set.create_command('magrat', 'the maiden', keep_retval: true) do
|
2012-01-02 19:04:47 -05:00
|
|
|
def process; 42; end
|
|
|
|
end
|
|
|
|
|
|
|
|
result = @set.process_line('magrat')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(result.command?).to eq true
|
|
|
|
expect(result.void_command?).to eq false
|
|
|
|
expect(result.retval).to eq 42
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should pass through context' do
|
|
|
|
ctx = {
|
2018-10-12 15:09:29 -04:00
|
|
|
eval_string: "bloomers",
|
|
|
|
pry_instance: Object.new,
|
|
|
|
output: StringIO.new,
|
|
|
|
target: binding
|
2012-01-02 19:04:47 -05:00
|
|
|
}
|
2014-09-12 12:40:37 -04:00
|
|
|
|
|
|
|
inside = inner_scope do |probe|
|
|
|
|
@set.create_command('agnes') do
|
|
|
|
define_method(:process, &probe)
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
2014-09-12 12:40:37 -04:00
|
|
|
|
|
|
|
@set.process_line('agnes', ctx)
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
2014-09-12 12:40:37 -04:00
|
|
|
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])
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add command_set to context' do
|
2014-09-12 12:40:37 -04:00
|
|
|
inside = inner_scope do |probe|
|
|
|
|
@set.create_command(/nann+y ogg+/) do
|
|
|
|
define_method(:process, &probe)
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
2014-09-12 12:40:37 -04:00
|
|
|
|
|
|
|
@set.process_line('nannnnnny oggggg')
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
|
2014-09-12 12:40:37 -04:00
|
|
|
expect(inside.command_set).to eq(@set)
|
2012-01-02 19:04:47 -05:00
|
|
|
end
|
|
|
|
end
|
2012-08-21 01:12:03 -04:00
|
|
|
|
2012-09-06 01:39:29 -04:00
|
|
|
if defined?(Bond)
|
|
|
|
describe '.complete' do
|
|
|
|
it "should list all command names" do
|
2018-11-04 04:34:24 -05:00
|
|
|
@set.create_command('susan') {}
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.complete('sus')).to.include 'susan '
|
2012-09-06 01:39:29 -04:00
|
|
|
end
|
2012-08-21 01:12:03 -04:00
|
|
|
|
2012-09-06 01:39:29 -04:00
|
|
|
it "should delegate to commands" do
|
2018-11-04 04:34:24 -05:00
|
|
|
@set.create_command('susan') { def complete(_search); ['--foo']; end }
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@set.complete('susan ')).to eq ['--foo']
|
2012-09-06 01:39:29 -04:00
|
|
|
end
|
2012-08-21 01:12:03 -04:00
|
|
|
end
|
|
|
|
end
|
2011-05-06 06:43:08 -04:00
|
|
|
end
|