2014-03-14 00:31:24 -04:00
|
|
|
require_relative 'helper'
|
2012-06-11 09:36:16 -04:00
|
|
|
|
2011-11-26 02:44:08 -05:00
|
|
|
describe Pry do
|
2012-06-11 09:36:16 -04:00
|
|
|
before do
|
|
|
|
@str_output = StringIO.new
|
|
|
|
end
|
2011-11-26 02:44:08 -05:00
|
|
|
|
|
|
|
[
|
|
|
|
["p = '", "'"],
|
|
|
|
["def", "a", "(); end"],
|
|
|
|
["p = <<FOO", "lots", "and", "lots of", "foo", "FOO"],
|
|
|
|
["[", ":lets,", "'list',", "[/nested/", "], things ]"],
|
|
|
|
["abc =~ /hello", "/"],
|
2011-11-26 03:37:47 -05:00
|
|
|
["issue = %W/", "343/"],
|
2011-11-26 02:44:08 -05:00
|
|
|
["pouts(<<HI, 'foo", "bar", "HI", "baz')"],
|
|
|
|
].each do |foo|
|
|
|
|
it "should not raise an error on broken lines: #{foo.join("\\n")}" do
|
2012-06-11 09:36:16 -04:00
|
|
|
redirect_pry_io(InputTester.new(*foo), @str_output) do
|
2011-11-26 02:44:08 -05:00
|
|
|
Pry.start
|
|
|
|
end
|
|
|
|
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
@str_output.string.should_not =~ /SyntaxError/
|
2011-11-26 02:44:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["end"],
|
|
|
|
["puts )("],
|
|
|
|
["1 1"],
|
2012-04-08 21:45:52 -04:00
|
|
|
["puts :"]
|
|
|
|
] + (Pry::Helpers::BaseHelpers.rbx? ? [] : [
|
|
|
|
["def", "method(1"], # in this case the syntax error is "expecting ')'".
|
|
|
|
["o = Object.new.tap{ def o.render;","'MEH'", "}"] # in this case the syntax error is "expecting keyword_end".
|
|
|
|
]).compact.each do |foo|
|
2011-11-26 02:44:08 -05:00
|
|
|
it "should raise an error on invalid syntax like #{foo.inspect}" do
|
2012-06-11 09:36:16 -04:00
|
|
|
redirect_pry_io(InputTester.new(*foo), @str_output) do
|
2011-11-26 02:44:08 -05:00
|
|
|
Pry.start
|
|
|
|
end
|
2012-06-11 09:36:16 -04:00
|
|
|
|
|
|
|
@str_output.string.should =~ /SyntaxError/
|
2011-11-26 02:44:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not intefere with syntax errors explicitly raised" do
|
2012-06-11 09:36:16 -04:00
|
|
|
redirect_pry_io(InputTester.new(%q{raise SyntaxError, "unexpected $end"}), @str_output) do
|
2011-11-26 02:44:08 -05:00
|
|
|
Pry.start
|
|
|
|
end
|
2012-06-11 09:36:16 -04:00
|
|
|
|
|
|
|
@str_output.string.should =~ /SyntaxError/
|
2011-11-26 02:44:08 -05:00
|
|
|
end
|
2012-01-06 12:33:37 -05:00
|
|
|
|
|
|
|
it "should allow trailing , to continue the line" do
|
|
|
|
pry = Pry.new
|
2012-04-10 09:39:29 -04:00
|
|
|
Pry::Code.complete_expression?("puts 1, 2,").should == false
|
2012-01-06 12:33:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should complete an expression that contains a line ending with a ," do
|
|
|
|
pry = Pry.new
|
2012-04-10 09:39:29 -04:00
|
|
|
Pry::Code.complete_expression?("puts 1, 2,\n3").should == true
|
2012-01-06 12:33:37 -05:00
|
|
|
end
|
2012-01-13 02:21:21 -05:00
|
|
|
|
2012-08-08 00:03:51 -04:00
|
|
|
it "should not suppress the error output if the line ends in ;" do
|
|
|
|
mock_pry("raise RuntimeError, 'foo';").should =~ /RuntimeError/
|
|
|
|
end
|
|
|
|
|
2012-01-13 02:21:21 -05:00
|
|
|
it "should not clobber _ex_ on a SyntaxError in the repl" do
|
2012-08-08 00:03:51 -04:00
|
|
|
mock_pry("raise RuntimeError, 'foo'", "puts foo)", "_ex_.is_a?(RuntimeError)").should =~ /^RuntimeError.*\nSyntaxError.*\n=> true/m
|
2012-01-13 02:21:21 -05:00
|
|
|
end
|
2012-07-18 12:24:31 -04:00
|
|
|
|
|
|
|
it "should allow whitespace delimeted strings" do
|
|
|
|
mock_pry('"%s" %% foo ').should =~ /"foo"/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow newline delimeted strings" do
|
|
|
|
mock_pry('"%s" %%','foo').should =~ /"foo"/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow whitespace delimeted strings ending on the first char of a line" do
|
|
|
|
mock_pry('"%s" %% ', ' #done!').should =~ /"\\n"/
|
|
|
|
end
|
2011-11-26 02:44:08 -05:00
|
|
|
end
|