diff --git a/lib/pry/command.rb b/lib/pry/command.rb index 99bde110..4e213f39 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -166,7 +166,7 @@ class Pry prefix = convert_to_regex(Pry.config.command_prefix) prefix = "(?:#{prefix})?" unless options[:use_prefix] - /^#{prefix}#{convert_to_regex(match)}(?!\S)/ + /\A#{prefix}#{convert_to_regex(match)}(?!\S)/ end def convert_to_regex(obj) diff --git a/lib/pry/testable/pry_tester.rb b/lib/pry/testable/pry_tester.rb index 55f0b558..2bd9b875 100644 --- a/lib/pry/testable/pry_tester.rb +++ b/lib/pry/testable/pry_tester.rb @@ -29,7 +29,15 @@ class Pry if @pry.process_command(str) last_command_result_or_output else - @pry.evaluate_ruby(str) + # Check if this is a multiline paste. + begin + complete_expr = Pry::Code.complete_expression?(str) + rescue SyntaxError => exception + @pry.output.puts( + "SyntaxError: #{exception.message.sub(/.*syntax error, */m, '')}" + ) + end + @pry.evaluate_ruby(str) if complete_expr end end diff --git a/spec/command_integration_spec.rb b/spec/command_integration_spec.rb index 7579da62..cca00136 100644 --- a/spec/command_integration_spec.rb +++ b/spec/command_integration_spec.rb @@ -456,7 +456,7 @@ describe "commands" do end end - expect(pry_tester(commands: klass).eval("def yo\nhello\n")).to eq 7 + expect(pry_tester(commands: klass).eval("def yo", "hello")).to eq 7 end it( @@ -469,7 +469,7 @@ describe "commands" do end end - expect(pry_tester(commands: klass).eval("def yo\nhello\n")).to eq 5 + expect(pry_tester(commands: klass).eval("def yo", "hello\n")).to eq 5 end it 'should set the commands default, and the default should be overridable' do diff --git a/spec/command_spec.rb b/spec/command_spec.rb index b676be81..d56bc09a 100644 --- a/spec/command_spec.rb +++ b/spec/command_spec.rb @@ -342,7 +342,7 @@ RSpec.describe Pry::Command do before { subject.command_options(use_prefix: true) } it "returns a Regexp without a prefix" do - expect(subject.command_regex).to eq(/^test\-command(?!\S)/) + expect(subject.command_regex).to eq(/\Atest\-command(?!\S)/) end end @@ -350,7 +350,7 @@ RSpec.describe Pry::Command do before { subject.command_options(use_prefix: false) } it "returns a Regexp with a prefix" do - expect(subject.command_regex).to eq(/^(?:)?test\-command(?!\S)/) + expect(subject.command_regex).to eq(/\A(?:)?test\-command(?!\S)/) end end end