2011-12-10 10:09:49 -05:00
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
describe Pry::Hooks do
|
|
|
|
before do
|
|
|
|
Pry::CLI.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "parsing options" do
|
|
|
|
it 'should raise if no options defined' do
|
|
|
|
lambda { Pry::CLI.parse_options(["--nothing"]) }.should.raise Pry::CLI::NoOptionsError
|
|
|
|
end
|
2013-09-05 20:11:29 -04:00
|
|
|
|
|
|
|
it "should remove args from ARGV by default" do
|
|
|
|
ARGV << '-v'
|
|
|
|
Pry::CLI.add_options do
|
|
|
|
on :v, "Display the Pry version" do
|
|
|
|
# irrelevant
|
|
|
|
end
|
|
|
|
end.parse_options
|
|
|
|
ARGV.include?('-v').should == false
|
|
|
|
end
|
2011-12-10 10:09:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "adding options" do
|
|
|
|
it "should be able to add an option" do
|
|
|
|
run = false
|
|
|
|
|
|
|
|
Pry::CLI.add_options do
|
|
|
|
on :optiontest, "A test option" do
|
|
|
|
run = true
|
|
|
|
end
|
|
|
|
end.parse_options(["--optiontest"])
|
|
|
|
|
|
|
|
run.should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be able to add multiple options" do
|
|
|
|
run = false
|
|
|
|
run2 = false
|
|
|
|
|
|
|
|
Pry::CLI.add_options do
|
|
|
|
on :optiontest, "A test option" do
|
|
|
|
run = true
|
|
|
|
end
|
|
|
|
end.add_options do
|
|
|
|
on :optiontest2, "Another test option" do
|
|
|
|
run2 = true
|
|
|
|
end
|
|
|
|
end.parse_options(["--optiontest", "--optiontest2"])
|
|
|
|
|
2013-11-09 22:14:20 -05:00
|
|
|
run.should.be.true
|
|
|
|
run2.should.be.true
|
2011-12-10 10:09:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "processing options" do
|
|
|
|
it "should be able to process an option" do
|
|
|
|
run = false
|
|
|
|
|
|
|
|
Pry::CLI.add_options do
|
|
|
|
on :optiontest, "A test option"
|
2014-01-11 08:42:25 -05:00
|
|
|
end.add_option_processor do |opts|
|
2011-12-10 10:09:49 -05:00
|
|
|
run = true if opts.present?(:optiontest)
|
|
|
|
end.parse_options(["--optiontest"])
|
|
|
|
|
|
|
|
run.should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be able to process multiple options" do
|
|
|
|
run = false
|
|
|
|
run2 = false
|
|
|
|
|
|
|
|
Pry::CLI.add_options do
|
|
|
|
on :optiontest, "A test option"
|
|
|
|
on :optiontest2, "Another test option"
|
2014-01-11 08:42:25 -05:00
|
|
|
end.add_option_processor do |opts|
|
2011-12-10 10:09:49 -05:00
|
|
|
run = true if opts.present?(:optiontest)
|
2014-01-11 08:42:25 -05:00
|
|
|
end.add_option_processor do |opts|
|
2011-12-10 10:09:49 -05:00
|
|
|
run2 = true if opts.present?(:optiontest2)
|
|
|
|
end.parse_options(["--optiontest", "--optiontest2"])
|
|
|
|
|
|
|
|
run.should == true
|
|
|
|
run2.should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|