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

55 lines
1.6 KiB
Ruby
Raw Normal View History

describe "help" do
2012-02-23 02:56:25 -05:00
before do
@oldset = Pry.config.commands
@set = Pry.config.commands = Pry::CommandSet.new do
import Pry::Commands
2012-02-23 02:56:25 -05:00
end
end
after do
Pry.config.commands = @oldset
end
it 'should display help for a specific command' do
2015-03-10 16:49:29 -04:00
expect(pry_eval('help ls')).to match(/Usage: ls/)
2012-02-23 02:56:25 -05:00
end
it 'should display help for a regex command with a "listing"' do
@set.command(/bar(.*)/, "Test listing", listing: "foo") { ; }
2015-03-10 16:49:29 -04:00
expect(pry_eval('help foo')).to match(/Test listing/)
2012-02-23 02:56:25 -05:00
end
it 'should display help for a command with a spaces in its name' do
@set.command('cmd with spaces', 'desc of a cmd with spaces') {}
2015-03-10 16:49:29 -04:00
expect(pry_eval('help "cmd with spaces"')).to match(/desc of a cmd with spaces/)
2012-02-23 02:56:25 -05:00
end
it 'should display help for all commands with a description' do
@set.command(/bar(.*)/, "Test listing", listing: "foo") { ; }
@set.command('b', 'description for b', listing: 'foo') {}
@set.command('c') {}
@set.command('d', '') {}
2012-02-23 02:56:25 -05:00
output = pry_eval('help')
2015-03-10 16:49:29 -04:00
expect(output).to match(/Test listing/)
expect(output).to match(/Description for b/)
expect(output).to match(/No description/)
2012-02-23 02:56:25 -05:00
end
it "should sort the output of the 'help' command" do
@set.command('faa', 'Fooerizes') {}
@set.command('gaa', 'Gooerizes') {}
@set.command('maa', 'Mooerizes') {}
@set.command('baa', 'Booerizes') {}
2012-02-23 02:56:25 -05:00
doc = pry_eval('help')
2012-02-23 02:56:25 -05:00
order = [doc.index("baa"),
doc.index("faa"),
doc.index("gaa"),
doc.index("maa")]
2012-02-23 02:56:25 -05:00
2015-03-10 16:49:29 -04:00
expect(order).to eq(order.sort)
2012-02-23 02:56:25 -05:00
end
end