mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
5cd65d3c0e
* Add ability to forward ARGV to a Pry session when using `bin/pry` Fixes https://github.com/pry/pry/issues/1901
84 lines
2.1 KiB
Ruby
84 lines
2.1 KiB
Ruby
RSpec.describe Pry::CLI do
|
|
before do
|
|
Pry::CLI.reset
|
|
end
|
|
|
|
describe "parsing options" do
|
|
it 'should raise if no options defined' do
|
|
expect { Pry::CLI.parse_options(["--nothing"]) }.to raise_error Pry::CLI::NoOptionsError
|
|
end
|
|
|
|
it "should remove args from ARGV by default" do
|
|
argv = ['filename', '-v']
|
|
Pry::CLI.add_options do
|
|
on :v, "Display the Pry version" do
|
|
# irrelevant
|
|
end
|
|
end.parse_options(argv)
|
|
expect(argv.include?('-v')).to eq false
|
|
end
|
|
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"])
|
|
|
|
expect(run).to eq 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"])
|
|
|
|
expect(run).to equal true
|
|
expect(run2).to equal true
|
|
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"
|
|
end.add_option_processor do |opts|
|
|
run = true if opts.present?(:optiontest)
|
|
end.parse_options(["--optiontest"])
|
|
|
|
expect(run).to eq 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"
|
|
end.add_option_processor do |opts|
|
|
run = true if opts.present?(:optiontest)
|
|
end.add_option_processor do |opts|
|
|
run2 = true if opts.present?(:optiontest2)
|
|
end.parse_options(["--optiontest", "--optiontest2"])
|
|
|
|
expect(run).to eq true
|
|
expect(run2).to eq true
|
|
end
|
|
end
|
|
end
|