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

added tests for new command interpolation behaviour (test_command_processor.rb)

This commit is contained in:
John Mair 2011-06-09 02:44:51 +12:00
parent 0c641f083e
commit 21a143ebcf

View file

@ -1,7 +1,6 @@
require 'helper'
describe "Pry::CommandProcessor" do
before do
@pry = Pry.new
@pry.commands = Pry::CommandSet.new
@ -12,9 +11,21 @@ describe "Pry::CommandProcessor" do
@pry.commands = Pry::CommandSet.new
end
it 'should accurately determine if a command is valid' do
@pry.commands.command("test-command") {}
valid = @command_processor.valid_command? "test-command"
valid.should == true
valid = @command_processor.valid_command? "blah"
valid.should == false
a = "test-command"
lambda { @command_processor.valid_command? '#{a}' }.should.raise NameError
end
it 'should correctly match a simple string command' do
@pry.commands.command("test-command") {}
command, captures, pos = @command_processor.command_matched "test-command"
command, captures, pos = @command_processor.command_matched "test-command", binding
command.name.should == "test-command"
captures.should == []
@ -23,7 +34,7 @@ describe "Pry::CommandProcessor" do
it 'should correctly match a simple string command with parameters' do
@pry.commands.command("test-command") { |arg|}
command, captures, pos = @command_processor.command_matched "test-command hello"
command, captures, pos = @command_processor.command_matched "test-command hello", binding
command.name.should == "test-command"
captures.should == []
@ -31,7 +42,7 @@ describe "Pry::CommandProcessor" do
end
it 'should not match when the relevant command does not exist' do
command, captures, pos = @command_processor.command_matched "test-command"
command, captures, pos = @command_processor.command_matched "test-command", binding
command.should == nil
captures.should == nil
@ -39,7 +50,7 @@ describe "Pry::CommandProcessor" do
it 'should correctly match a regex command' do
@pry.commands.command(/rue(.?)/) { }
command, captures, pos = @command_processor.command_matched "rue hello"
command, captures, pos = @command_processor.command_matched "rue hello", binding
command.name.should == /rue(.?)/
captures.should == [""]
@ -48,7 +59,7 @@ describe "Pry::CommandProcessor" do
it 'should correctly match a regex command and extract the capture groups' do
@pry.commands.command(/rue(.?)/) { }
command, captures, pos = @command_processor.command_matched "rue5 hello"
command, captures, pos = @command_processor.command_matched "rue5 hello", binding
command.name.should == /rue(.?)/
captures.should == ["5"]
@ -57,7 +68,7 @@ describe "Pry::CommandProcessor" do
it 'should correctly match a string command with spaces in its name' do
@pry.commands.command("test command") {}
command, captures, pos = @command_processor.command_matched "test command"
command, captures, pos = @command_processor.command_matched "test command", binding
command.name.should == "test command"
captures.should == []
@ -66,7 +77,7 @@ describe "Pry::CommandProcessor" do
it 'should correctly match a string command with spaces in its name with parameters' do
@pry.commands.command("test command") {}
command, captures, pos = @command_processor.command_matched "test command param1 param2"
command, captures, pos = @command_processor.command_matched "test command param1 param2", binding
command.name.should == "test command"
captures.should == []
@ -78,7 +89,7 @@ describe "Pry::CommandProcessor" do
@pry.commands.command(regex_command_name) {}
sample_text = "test friendship command"
command, captures, pos = @command_processor.command_matched sample_text
command, captures, pos = @command_processor.command_matched sample_text, binding
command.name.should == regex_command_name
captures.should == ["friendship"]
@ -90,10 +101,33 @@ describe "Pry::CommandProcessor" do
@pry.commands.command(regex_command_name) {}
sample_text = ".cd ~/pry"
command, captures, pos = @command_processor.command_matched sample_text
command, captures, pos = @command_processor.command_matched sample_text, binding
command.name.should == regex_command_name
captures.should == ["cd ~/pry"]
pos.should == sample_text.size
end
it 'should correctly match a command whose name is interpolated' do
@pry.commands.command("blah") {}
a = "bl"
b = "ah"
command, captures, pos = @command_processor.command_matched "#{a}#{b}", binding
command.name.should == "blah"
captures.should == []
pos.should == command.name.length
end
it 'should NOT match a command whose name is interpolated when :interpolate => false' do
@pry.commands.command("boast", "", :interpolate => false) {}
a = "boa"
b = "st"
# remember to use '' instead of "" when testing interpolation or
# you'll cause yourself incredible confusion
command, captures, pos = @command_processor.command_matched '#{a}#{b}', binding
command.should == nil
end
end