mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
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.
This commit is contained in:
parent
c6f8d5c632
commit
144d32e1d6
51 changed files with 277 additions and 456 deletions
3
Gemfile
3
Gemfile
|
@ -11,8 +11,7 @@ group :development do
|
|||
end
|
||||
|
||||
group :test do
|
||||
gem 'bacon', '~> 1.2'
|
||||
gem 'mocha', '~> 1.0', require: "mocha/api"
|
||||
gem 'rspec', '~> 3.0'
|
||||
end
|
||||
|
||||
group :development, :test do
|
||||
|
|
4
Rakefile
4
Rakefile
|
@ -11,8 +11,8 @@ desc "Set up and run tests"
|
|||
task :default => [:test]
|
||||
|
||||
def run_specs paths
|
||||
quiet = ENV['VERBOSE'] ? '' : '-q'
|
||||
exec "bacon -Ispec -rubygems #{quiet} #{paths.join ' '}"
|
||||
format = ENV['VERBOSE'] ? '--format documentation ' : ''
|
||||
sh "rspec #{format}#{paths.join ' '}"
|
||||
end
|
||||
|
||||
desc "Run tests"
|
||||
|
|
|
@ -7,17 +7,17 @@ describe Pry::Hooks do
|
|||
|
||||
describe "parsing options" do
|
||||
it 'should raise if no options defined' do
|
||||
lambda { Pry::CLI.parse_options(["--nothing"]) }.should.raise Pry::CLI::NoOptionsError
|
||||
expect { Pry::CLI.parse_options(["--nothing"]) }.to raise_error Pry::CLI::NoOptionsError
|
||||
end
|
||||
|
||||
it "should remove args from ARGV by default" do
|
||||
ARGV << '-v'
|
||||
argv = ['filename', '-v']
|
||||
Pry::CLI.add_options do
|
||||
on :v, "Display the Pry version" do
|
||||
# irrelevant
|
||||
end
|
||||
end.parse_options
|
||||
ARGV.include?('-v').should == false
|
||||
end.parse_options(argv)
|
||||
argv.include?('-v').should == false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -48,8 +48,8 @@ describe Pry::Hooks do
|
|||
end
|
||||
end.parse_options(["--optiontest", "--optiontest2"])
|
||||
|
||||
run.should.be.true
|
||||
run2.should.be.true
|
||||
run.should equal true
|
||||
run2.should equal true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -24,9 +24,9 @@ describe Pry::Code do
|
|||
end
|
||||
|
||||
should 'raise an error if the file doesn\'t exist' do
|
||||
proc do
|
||||
expect do
|
||||
Pry::Code.from_file('/knalkjsdnalsd/alkjdlkq')
|
||||
end.should.raise(MethodSource::SourceNotFoundError)
|
||||
end.to raise_error MethodSource::SourceNotFoundError
|
||||
end
|
||||
|
||||
should 'check for files relative to origin pwd' do
|
||||
|
@ -194,7 +194,7 @@ describe Pry::Code do
|
|||
should 'disable line numbers when falsy' do
|
||||
@code = @code.with_line_numbers
|
||||
@code = @code.with_line_numbers(false)
|
||||
@code.should.not =~ /1:/
|
||||
@code.should_not =~ /1:/
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ describe "commands" do
|
|||
p.eval "def hello\npeter pan\n"
|
||||
p.run_command "amend-line !"
|
||||
p.eval_string.should =~ /def hello/
|
||||
p.eval_string.should.not =~ /peter pan/
|
||||
p.eval_string.should_not =~ /peter pan/
|
||||
end
|
||||
|
||||
it 'should run a command in the context of a session' do
|
||||
|
@ -248,7 +248,7 @@ describe "commands" do
|
|||
pry
|
||||
end
|
||||
|
||||
@str_output.string.should.not =~ /SyntaxError/
|
||||
@str_output.string.should_not =~ /SyntaxError/
|
||||
end
|
||||
|
||||
it 'should NOT interpolate ruby code into commands if :interpolate => false' do
|
||||
|
@ -264,13 +264,8 @@ describe "commands" do
|
|||
|
||||
it 'should NOT try to interpolate pure ruby code (no commands) ' do
|
||||
# These should raise RuntimeError instead of NameError
|
||||
proc {
|
||||
pry_eval 'raise \'#{aggy}\''
|
||||
}.should.raise(RuntimeError)
|
||||
|
||||
proc {
|
||||
pry_eval 'raise #{aggy}'
|
||||
}.should.raise(RuntimeError)
|
||||
expect { pry_eval 'raise \'#{aggy}\'' }.to raise_error RuntimeError
|
||||
expect { pry_eval 'raise #{aggy}' }.to raise_error RuntimeError
|
||||
|
||||
pry_eval('format \'#{my_var}\'').should == "\#{my_var}"
|
||||
end
|
||||
|
@ -488,7 +483,7 @@ describe "commands" do
|
|||
desc "help", "blah"
|
||||
end
|
||||
commands = klass.to_hash
|
||||
commands["help"].description.should.not == orig
|
||||
commands["help"].description.should_not == orig
|
||||
commands["help"].description.should == "blah"
|
||||
end
|
||||
|
||||
|
|
|
@ -15,16 +15,16 @@ describe Pry::CommandSet do
|
|||
|
||||
describe "[]=" do
|
||||
it "removes a command from the command set" do
|
||||
@set["help"].should.not == nil
|
||||
@set["help"].should_not == nil
|
||||
@set["help"] = nil
|
||||
@set["help"].should == nil
|
||||
lambda { @set.run_command(TOPLEVEL_BINDING, "help") }.should.raise Pry::NoCommandError
|
||||
expect { @set.run_command(TOPLEVEL_BINDING, "help") }.to raise_error Pry::NoCommandError
|
||||
end
|
||||
|
||||
it "replaces a command" do
|
||||
old_help = @set["help"]
|
||||
@set["help"] = @set["pry-version"]
|
||||
@set["help"].should.not == old_help
|
||||
@set["help"].should_not == old_help
|
||||
end
|
||||
|
||||
it "rebinds the command with key" do
|
||||
|
@ -33,7 +33,7 @@ describe Pry::CommandSet do
|
|||
end
|
||||
|
||||
it "raises a TypeError when command is not a subclass of Pry::Command" do
|
||||
lambda { @set["help"] = "hello" }.should.raise TypeError
|
||||
expect { @set["help"] = "hello" }.to raise_error TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -67,27 +67,21 @@ describe Pry::CommandSet do
|
|||
|
||||
it 'should raise an error when calling an undefined command' do
|
||||
@set.command('foo') {}
|
||||
lambda {
|
||||
@set.run_command @ctx, 'bar'
|
||||
}.should.raise(Pry::NoCommandError)
|
||||
expect { @set.run_command @ctx, 'bar' }.to raise_error Pry::NoCommandError
|
||||
end
|
||||
|
||||
it 'should be able to remove its own commands' do
|
||||
@set.command('foo') {}
|
||||
@set.delete 'foo'
|
||||
|
||||
lambda {
|
||||
@set.run_command @ctx, 'foo'
|
||||
}.should.raise(Pry::NoCommandError)
|
||||
expect { @set.run_command @ctx, 'foo' }.to raise_error Pry::NoCommandError
|
||||
end
|
||||
|
||||
it 'should be able to remove its own commands, by listing name' do
|
||||
@set.command(/^foo1/, 'desc', :listing => 'foo') {}
|
||||
@set.delete 'foo'
|
||||
|
||||
lambda {
|
||||
@set.run_command @ctx, /^foo1/
|
||||
}.should.raise(Pry::NoCommandError)
|
||||
expect { @set.run_command @ctx, /^foo1/ }.to raise_error Pry::NoCommandError
|
||||
end
|
||||
|
||||
it 'should be able to import some commands from other sets' do
|
||||
|
@ -103,9 +97,7 @@ describe Pry::CommandSet do
|
|||
@set.run_command @ctx, 'foo'
|
||||
run.should == true
|
||||
|
||||
lambda {
|
||||
@set.run_command @ctx, 'bar'
|
||||
}.should.raise(Pry::NoCommandError)
|
||||
expect { @set.run_command @ctx, 'bar' }.to raise_error Pry::NoCommandError
|
||||
end
|
||||
|
||||
it 'should return command set after import' do
|
||||
|
@ -211,7 +203,7 @@ describe Pry::CommandSet do
|
|||
@set['bar'].options[:interpolate].should == @set['foo'].options[:interpolate]
|
||||
|
||||
# however some options should not be inherited
|
||||
@set['bar'].options[:listing].should.not == @set['foo'].options[:listing]
|
||||
@set['bar'].options[:listing].should_not == @set['foo'].options[:listing]
|
||||
@set['bar'].options[:listing].should == "bar"
|
||||
end
|
||||
|
||||
|
@ -289,22 +281,19 @@ describe Pry::CommandSet do
|
|||
end
|
||||
|
||||
it 'should be able to have its own helpers' do
|
||||
@set.command('foo') do
|
||||
should.respond_to :my_helper
|
||||
end
|
||||
|
||||
@set.helpers do
|
||||
def my_helper; end
|
||||
end
|
||||
@set.command('foo') { my_helper }
|
||||
@set.helpers { def my_helper; end }
|
||||
|
||||
@set.run_command(@ctx, 'foo')
|
||||
Pry::Command.subclass('foo', '', {}, Module.new).new({:target => binding}).should.not.respond_to :my_helper
|
||||
Pry::Command.subclass('foo', '', {}, Module.new)
|
||||
.new({:target => binding})
|
||||
.should_not(respond_to :my_helper)
|
||||
end
|
||||
|
||||
it 'should not recreate a new helper module when helpers is called' do
|
||||
@set.command('foo') do
|
||||
should.respond_to :my_helper
|
||||
should.respond_to :my_other_helper
|
||||
my_helper
|
||||
my_other_helper
|
||||
end
|
||||
|
||||
@set.helpers do
|
||||
|
@ -326,7 +315,7 @@ describe Pry::CommandSet do
|
|||
end
|
||||
|
||||
@set.import imported_set
|
||||
@set.command('foo') { should.respond_to :imported_helper_method }
|
||||
@set.command('foo') { imported_helper_method }
|
||||
@set.run_command(@ctx, 'foo')
|
||||
end
|
||||
|
||||
|
@ -340,7 +329,7 @@ describe Pry::CommandSet do
|
|||
end
|
||||
|
||||
@set.import_from imported_set, 'bar'
|
||||
@set.command('foo') { should.respond_to :imported_helper_method }
|
||||
@set.command('foo') { imported_helper_method }
|
||||
@set.run_command(@ctx, 'foo')
|
||||
end
|
||||
|
||||
|
@ -358,9 +347,7 @@ describe Pry::CommandSet do
|
|||
@ctx[:command_set] = @set
|
||||
@ctx[:output] = StringIO.new
|
||||
|
||||
lambda {
|
||||
@set.run_command(@ctx, 'help')
|
||||
}.should.not.raise
|
||||
expect { @set.run_command(@ctx, 'help') }.to_not raise_error
|
||||
end
|
||||
|
||||
|
||||
|
@ -382,13 +369,13 @@ describe Pry::CommandSet do
|
|||
end
|
||||
|
||||
it 'should raise exception trying to rename non-existent command' do
|
||||
lambda { @set.rename_command('bar', 'foo') }.should.raise ArgumentError
|
||||
expect { @set.rename_command('bar', 'foo') }.to raise_error ArgumentError
|
||||
end
|
||||
|
||||
it 'should make old command name inaccessible' do
|
||||
@set.command('foo') { }
|
||||
@set.rename_command('bar', 'foo')
|
||||
lambda { @set.run_command(@ctx, 'foo') }.should.raise Pry::NoCommandError
|
||||
expect { @set.run_command(@ctx, 'foo') }.to raise_error Pry::NoCommandError
|
||||
end
|
||||
|
||||
it 'should be able to pass in options when renaming command' do
|
||||
|
@ -592,9 +579,7 @@ describe Pry::CommandSet do
|
|||
|
||||
it 'should not cause argument interpolation' do
|
||||
cmd = @set.command('hello')
|
||||
lambda {
|
||||
@set.valid_command?('hello #{raise "futz"}')
|
||||
}.should.not.raise
|
||||
expect { @set.valid_command?('hello #{raise "futz"}') }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,9 +22,7 @@ describe "Pry::Command" do
|
|||
#
|
||||
end
|
||||
|
||||
lambda {
|
||||
mock_command(cmd, %w())
|
||||
}.should.raise(Pry::CommandError)
|
||||
expect { mock_command(cmd, %w()) }.to raise_error Pry::CommandError
|
||||
end
|
||||
|
||||
it 'should return VOID without keep_retval' do
|
||||
|
@ -198,9 +196,7 @@ describe "Pry::Command" do
|
|||
end
|
||||
end
|
||||
|
||||
lambda {
|
||||
mock_command(cmd)
|
||||
}.should.raise(Pry::CommandError)
|
||||
expect { mock_command(cmd) }.to raise_error Pry::CommandError
|
||||
end
|
||||
|
||||
it 'should work if neither options, nor setup is overridden' do
|
||||
|
@ -402,10 +398,7 @@ describe "Pry::Command" do
|
|||
|
||||
it "should raise an error if the line doesn't match the command" do
|
||||
cmd = @set.command 'grunthos', 'the flatulent'
|
||||
|
||||
lambda {
|
||||
cmd.new.process_line %(grumpos)
|
||||
}.should.raise(Pry::CommandError)
|
||||
expect { cmd.new.process_line %(grumpos) }.to raise_error Pry::CommandError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -619,9 +612,7 @@ describe "Pry::Command" do
|
|||
end
|
||||
@out = StringIO.new
|
||||
|
||||
proc {
|
||||
@t.eval 'walking-spanish | { :jesus }'
|
||||
}.should.raise(NoMethodError)
|
||||
expect { @t.eval 'walking-spanish | { :jesus }' }.to raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
it "should expose block in command_block method" do
|
||||
|
|
|
@ -117,7 +117,7 @@ describe "amend-line" do
|
|||
error = e
|
||||
end
|
||||
|
||||
error.should.not.be.nil
|
||||
error.should_not equal nil
|
||||
error.message.should =~ /No input to amend/
|
||||
end
|
||||
|
||||
|
|
|
@ -5,11 +5,7 @@ describe Pry::Command::Cat::FileFormatter do
|
|||
before do
|
||||
@p = Pry.new
|
||||
@opt = Slop.new
|
||||
Pry::Code.stubs(:from_file)
|
||||
end
|
||||
|
||||
after do
|
||||
Pry::Code.unstub(:from_file)
|
||||
expect(Pry::Code).to receive(:from_file)
|
||||
end
|
||||
|
||||
describe "windows filesystem" do
|
||||
|
|
|
@ -17,9 +17,7 @@ describe "cat" do
|
|||
|
||||
describe "on receiving a file that does not exist" do
|
||||
it 'should display an error message' do
|
||||
proc {
|
||||
@t.eval 'cat supercalifragilicious66'
|
||||
}.should.raise(StandardError).message.should =~ /Cannot open/
|
||||
expect { @t.eval 'cat supercalifragilicious66' }.to raise_error(StandardError, /Cannot open/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -135,9 +133,7 @@ describe "cat" do
|
|||
|
||||
it 'should show error when backtrace level out of bounds' do
|
||||
@t.last_exception = mock_exception('x', 'x', 'x')
|
||||
proc {
|
||||
@t.eval('cat --ex 3')
|
||||
}.should.raise(Pry::CommandError).message.should =~ /out of bounds/
|
||||
expect { @t.eval('cat --ex 3') }.to raise_error(Pry::CommandError, /out of bounds/)
|
||||
end
|
||||
|
||||
it 'each successive cat --ex should show the next level of backtrace, and going past the final level should return to the first' do
|
||||
|
|
|
@ -28,7 +28,7 @@ describe 'cd' do
|
|||
|
||||
describe 'state' do
|
||||
it 'should not to be set up in fresh instance' do
|
||||
@t.command_state.should.be.nil
|
||||
@t.command_state.should equal nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,9 +44,7 @@ describe 'cd' do
|
|||
|
||||
describe 'when an error was raised' do
|
||||
it 'should not toggle and should keep correct stacks' do
|
||||
proc {
|
||||
@t.eval 'cd %'
|
||||
}.should.raise(Pry::CommandError)
|
||||
expect { @t.eval 'cd %' }.to raise_error Pry::CommandError
|
||||
|
||||
@t.old_stack.should == []
|
||||
@t.assert_binding_stack [@o]
|
||||
|
@ -233,9 +231,7 @@ describe 'cd' do
|
|||
end
|
||||
|
||||
it 'should not cd into complex input when it encounters an exception' do
|
||||
proc {
|
||||
@t.eval 'cd 1/2/swoop_a_doop/3'
|
||||
}.should.raise(Pry::CommandError)
|
||||
expect { @t.eval 'cd 1/2/swoop_a_doop/3' }.to raise_error Pry::CommandError
|
||||
|
||||
@t.assert_binding_stack [@o]
|
||||
end
|
||||
|
@ -252,8 +248,6 @@ describe 'cd' do
|
|||
|
||||
# Regression test for ticket #516.
|
||||
it 'should be able to cd into the Object BasicObject' do
|
||||
proc {
|
||||
@t.eval 'cd BasicObject.new'
|
||||
}.should.not.raise
|
||||
expect { @t.eval 'cd BasicObject.new' }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,16 +10,12 @@ describe "disable-pry" do
|
|||
end
|
||||
|
||||
it 'should quit the current session' do
|
||||
lambda{
|
||||
@t.process_command 'disable-pry'
|
||||
}.should.throw(:breakout)
|
||||
expect { @t.process_command 'disable-pry' }.to throw_symbol :breakout
|
||||
end
|
||||
|
||||
it "should set DISABLE_PRY" do
|
||||
ENV['DISABLE_PRY'].should == nil
|
||||
lambda{
|
||||
@t.process_command 'disable-pry'
|
||||
}.should.throw(:breakout)
|
||||
expect { @t.process_command 'disable-pry' }.to throw_symbol :breakout
|
||||
ENV['DISABLE_PRY'].should == 'true'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,10 +38,7 @@ describe "edit" do
|
|||
it "should not allow patching any known kind of file" do
|
||||
["file.rb", "file.c", "file.py", "file.yml", "file.gemspec",
|
||||
"/tmp/file", "\\\\Temp\\\\file"].each do |file|
|
||||
proc {
|
||||
pry_eval "edit -p #{file}"
|
||||
}.should.raise(NotImplementedError).
|
||||
message.should =~ /Cannot yet patch false objects!/
|
||||
expect { pry_eval "edit -p #{file}" }.to raise_error(NotImplementedError, /Cannot yet patch false objects!/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -200,7 +197,7 @@ describe "edit" do
|
|||
nil
|
||||
}
|
||||
|
||||
defined?(FOO).should.be.nil
|
||||
defined?(FOO).should equal nil
|
||||
|
||||
@t.eval 'edit --ex'
|
||||
|
||||
|
@ -234,11 +231,11 @@ describe "edit" do
|
|||
nil
|
||||
}
|
||||
|
||||
defined?(FOO2).should.be.nil
|
||||
defined?(FOO2).should equal nil
|
||||
|
||||
@t.eval 'edit -n --ex'
|
||||
|
||||
defined?(FOO2).should.be.nil
|
||||
defined?(FOO2).should equal nil
|
||||
end
|
||||
|
||||
describe "with --patch" do
|
||||
|
@ -250,7 +247,7 @@ describe "edit" do
|
|||
nil
|
||||
}
|
||||
|
||||
defined?(FOO3).should.be.nil
|
||||
defined?(FOO3).should equal nil
|
||||
|
||||
@t.eval 'edit --ex --patch'
|
||||
|
||||
|
@ -299,9 +296,7 @@ describe "edit" do
|
|||
end
|
||||
|
||||
it 'should display error message when backtrace level is invalid' do
|
||||
proc {
|
||||
@t.eval 'edit -n --ex 4'
|
||||
}.should.raise(Pry::CommandError)
|
||||
expect { @t.eval 'edit -n --ex 4' }.to raise_error Pry::CommandError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -394,17 +389,11 @@ describe "edit" do
|
|||
end
|
||||
|
||||
it "should not work with a filename" do
|
||||
proc {
|
||||
pry_eval 'edit ruby.rb -i'
|
||||
}.should.raise(Pry::CommandError).
|
||||
message.should =~ /Only one of --ex, --temp, --in, --method and FILE/
|
||||
expect { pry_eval 'edit ruby.rb -i' }.to raise_error(Pry::CommandError, /Only one of --ex, --temp, --in, --method and FILE/)
|
||||
end
|
||||
|
||||
it "should not work with nonsense" do
|
||||
proc {
|
||||
pry_eval 'edit --in three'
|
||||
}.should.raise(Pry::CommandError).
|
||||
message.should =~ /Not a valid range: three/
|
||||
expect { pry_eval 'edit --in three' }.to raise_error(Pry::CommandError, /Not a valid range: three/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -702,12 +691,12 @@ describe "edit" do
|
|||
@t = pry_tester
|
||||
class BinkyWink
|
||||
eval %{
|
||||
def tits_macgee
|
||||
def m1
|
||||
binding
|
||||
end
|
||||
}
|
||||
|
||||
def tots_macgee
|
||||
def m2
|
||||
:jeremy_jones
|
||||
binding
|
||||
end
|
||||
|
@ -720,28 +709,26 @@ describe "edit" do
|
|||
|
||||
it 'should edit method context' do
|
||||
Pry.config.editor = lambda do |file, line|
|
||||
[file, line].should == BinkyWink.instance_method(:tots_macgee).source_location
|
||||
[file, line].should == BinkyWink.instance_method(:m2).source_location
|
||||
nil
|
||||
end
|
||||
|
||||
t = pry_tester(BinkyWink.new.tots_macgee)
|
||||
t = pry_tester(BinkyWink.new.m2)
|
||||
t.process_command "edit -m -n"
|
||||
end
|
||||
|
||||
it 'errors when cannot find method context' do
|
||||
Pry.config.editor = lambda do |file, line|
|
||||
[file, line].should == BinkyWink.instance_method(:tits_macgee).source_location
|
||||
[file, line].should == BinkyWink.instance_method(:m1).source_location
|
||||
nil
|
||||
end
|
||||
|
||||
t = pry_tester(BinkyWink.new.tits_macgee)
|
||||
lambda { t.process_command "edit -m -n" }.should.
|
||||
raise(Pry::CommandError).message.should.match(/Cannot find a file for/)
|
||||
t = pry_tester(BinkyWink.new.m1)
|
||||
expect { t.process_command "edit -m -n" }.to raise_error(Pry::CommandError, /Cannot find a file for/)
|
||||
end
|
||||
|
||||
it 'errors when a filename arg is passed with --method' do
|
||||
lambda { @t.process_command "edit -m Pry#repl" }.should.
|
||||
raise(Pry::CommandError).message.should.match(/Only one of/)
|
||||
expect { @t.process_command "edit -m Pry#repl" }.to raise_error(Pry::CommandError, /Only one of/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -750,7 +737,7 @@ describe "edit" do
|
|||
@t = pry_tester
|
||||
class TrinkyDink
|
||||
eval %{
|
||||
def claudia_linklater
|
||||
def m
|
||||
end
|
||||
}
|
||||
end
|
||||
|
@ -761,8 +748,7 @@ describe "edit" do
|
|||
end
|
||||
|
||||
it 'should display a nice error message when cannot open a file' do
|
||||
lambda { @t.process_command "edit TrinkyDink#claudia_linklater" }.should.
|
||||
raise(Pry::CommandError).message.should.match(/Cannot find a file for/)
|
||||
expect { @t.process_command "edit TrinkyDink#m" }.to raise_error(Pry::CommandError, /Cannot find a file for/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,24 +4,24 @@ describe "exit-all" do
|
|||
before { @pry = Pry.new }
|
||||
|
||||
it "should break out of the repl and return nil" do
|
||||
@pry.eval("exit-all").should.be.false
|
||||
@pry.exit_value.should.be.nil
|
||||
@pry.eval("exit-all").should equal false
|
||||
@pry.exit_value.should equal nil
|
||||
end
|
||||
|
||||
it "should break out of the repl wth a user specified value" do
|
||||
@pry.eval("exit-all 'message'").should.be.false
|
||||
@pry.eval("exit-all 'message'").should equal false
|
||||
@pry.exit_value.should == "message"
|
||||
end
|
||||
|
||||
it "should break out of the repl even if multiple bindings still on stack" do
|
||||
["cd 1", "cd 2"].each { |line| @pry.eval(line).should.be.true }
|
||||
@pry.eval("exit-all 'message'").should.be.false
|
||||
["cd 1", "cd 2"].each { |line| @pry.eval(line).should equal true }
|
||||
@pry.eval("exit-all 'message'").should equal false
|
||||
@pry.exit_value.should == "message"
|
||||
end
|
||||
|
||||
it "should have empty binding_stack after breaking out of the repl" do
|
||||
["cd 1", "cd 2"].each { |line| @pry.eval(line).should.be.true }
|
||||
@pry.eval("exit-all").should.be.false
|
||||
@pry.binding_stack.should.be.empty
|
||||
["cd 1", "cd 2"].each { |line| @pry.eval(line).should equal true }
|
||||
@pry.eval("exit-all").should equal false
|
||||
@pry.binding_stack.should be_empty
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,9 +2,7 @@ require_relative '../helper'
|
|||
|
||||
describe "exit-program" do
|
||||
it 'should raise SystemExit' do
|
||||
proc {
|
||||
pry_eval('exit-program')
|
||||
}.should.raise SystemExit
|
||||
expect { pry_eval('exit-program') }.to raise_error SystemExit
|
||||
end
|
||||
|
||||
it 'should exit the program with the provided value' do
|
||||
|
|
|
@ -11,18 +11,18 @@ describe "exit" do
|
|||
end
|
||||
|
||||
it "should break out of the repl when binding_stack has only one binding" do
|
||||
@pry.eval("exit").should.be.false
|
||||
@pry.exit_value.should.be.nil
|
||||
@pry.eval("exit").should equal false
|
||||
@pry.exit_value.should equal nil
|
||||
end
|
||||
|
||||
it "should break out of the repl and return user-given value" do
|
||||
@pry.eval("exit :john").should.be.false
|
||||
@pry.eval("exit :john").should equal false
|
||||
@pry.exit_value.should == :john
|
||||
end
|
||||
|
||||
it "should break out of the repl even after an exception" do
|
||||
@pry.eval "exit = 42"
|
||||
@pry.output.string.should =~ /^SyntaxError/
|
||||
@pry.eval("exit").should.be.false
|
||||
@pry.eval("exit").should equal false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require_relative '../helper'
|
||||
|
||||
MyKlass = Class.new do
|
||||
describe "find-method" do
|
||||
MyKlass = Class.new do
|
||||
def hello
|
||||
"timothy"
|
||||
end
|
||||
|
@ -13,29 +14,28 @@ MyKlass = Class.new do
|
|||
def tea_time?
|
||||
"polly"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "find-method" do
|
||||
describe "find matching methods by name regex (-n option)" do
|
||||
it "should find a method by regex" do
|
||||
pry_eval("find-method hell MyKlass").should =~
|
||||
pry_eval(binding, "find-method hell MyKlass").should =~
|
||||
/MyKlass.*?hello/m
|
||||
end
|
||||
|
||||
it "should NOT match a method that does not match the regex" do
|
||||
pry_eval("find-method hell MyKlass").should.not =~
|
||||
pry_eval(binding, "find-method hell MyKlass").should_not =~
|
||||
/MyKlass.*?goodbye/m
|
||||
end
|
||||
end
|
||||
|
||||
describe "find matching methods by content regex (-c option)" do
|
||||
it "should find a method by regex" do
|
||||
pry_eval("find-method -c timothy MyKlass").should =~
|
||||
pry_eval(binding, "find-method -c timothy MyKlass").should =~
|
||||
/MyKlass.*?hello/m
|
||||
end
|
||||
|
||||
it "should NOT match a method that does not match the regex" do
|
||||
pry_eval("find-method timothy MyKlass").should.not =~
|
||||
pry_eval(binding, "find-method timothy MyKlass").should_not =~
|
||||
/MyKlass.*?goodbye/m
|
||||
end
|
||||
end
|
||||
|
@ -46,18 +46,16 @@ describe "find-method" do
|
|||
raise "mooo"
|
||||
end
|
||||
|
||||
pry_eval("find-method -c timothy MyKlass").should =~
|
||||
pry_eval(binding, "find-method -c timothy MyKlass").should =~
|
||||
/MyKlass.*?hello/m
|
||||
end
|
||||
|
||||
it "should escape regexes correctly" do
|
||||
good = /tea_time\?/
|
||||
bad = /tea_tim\?/
|
||||
pry_eval('find-method tea_time? MyKlass').should =~ good
|
||||
pry_eval('find-method tea_time? MyKlass').should =~ good
|
||||
pry_eval('find-method tea_time\? MyKlass').should.not =~ bad
|
||||
pry_eval('find-method tea_time\? MyKlass').should =~ good
|
||||
pry_eval(binding, 'find-method tea_time? MyKlass').should =~ good
|
||||
pry_eval(binding, 'find-method tea_time? MyKlass').should =~ good
|
||||
pry_eval(binding, 'find-method tea_time\? MyKlass').should_not =~ bad
|
||||
pry_eval(binding, 'find-method tea_time\? MyKlass').should =~ good
|
||||
end
|
||||
end
|
||||
|
||||
Object.remove_const(:MyKlass)
|
||||
|
|
|
@ -2,24 +2,22 @@ require_relative '../helper'
|
|||
|
||||
describe "gem-list" do
|
||||
it 'should not raise when invoked' do
|
||||
proc {
|
||||
pry_eval(self, 'gem-list')
|
||||
}.should.not.raise
|
||||
expect { pry_eval(self, 'gem-list') }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'should work arglessly' do
|
||||
list = pry_eval('gem-list')
|
||||
list.should =~ /slop \(/
|
||||
list.should =~ /bacon \(/
|
||||
list.should =~ /rspec \(/
|
||||
end
|
||||
|
||||
it 'should find arg' do
|
||||
prylist = pry_eval('gem-list slop')
|
||||
prylist.should =~ /slop \(/
|
||||
prylist.should.not =~ /bacon/
|
||||
prylist.should_not =~ /rspec/
|
||||
end
|
||||
|
||||
it 'should return non-results as silence' do
|
||||
pry_eval('gem-list aoeuoueouaou').should.empty?
|
||||
pry_eval('gem-list aoeuoueouaou').should be_empty
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,6 +27,6 @@ describe 'gist' do
|
|||
|
||||
it 'nominally logs in' do
|
||||
pry_eval 'gist --login'
|
||||
Pad.gist_calls[:login!].should.not.be.nil
|
||||
Pad.gist_calls[:login!].should_not be_nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -152,18 +152,15 @@ describe "hist" do
|
|||
it "should raise CommandError when index of `--replay` points out to another `hist --replay`" do
|
||||
@t.eval ":banzai"
|
||||
@t.eval "hist --replay 1"
|
||||
lambda do
|
||||
@t.eval "hist --replay 2"
|
||||
end.should.raise(Pry::CommandError, /Replay index 4 points out to another replay call: `hist --replay 1`/)
|
||||
|
||||
expect { @t.eval "hist --replay 2" }.to raise_error(Pry::CommandError, /Replay index 2 points out to another replay call: `hist --replay 1`/)
|
||||
end
|
||||
|
||||
it "should disallow execution of `--replay <i>` when CommandError raised" do
|
||||
@t.eval "a = 0"
|
||||
@t.eval "a += 1"
|
||||
@t.eval "hist --replay 2"
|
||||
lambda{
|
||||
@t.eval "hist --replay 3"
|
||||
}.should.raise(Pry::CommandError)
|
||||
expect { @t.eval "hist --replay 3" }.to raise_error Pry::CommandError
|
||||
@t.eval("a").should == 2
|
||||
@t.eval("hist").lines.to_a.size.should == 5
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ require_relative '../helper'
|
|||
describe "ls" do
|
||||
describe "below ceiling" do
|
||||
it "should stop before Object by default" do
|
||||
pry_eval("cd Class.new{ def goo; end }.new", "ls").should.not =~ /Object/
|
||||
pry_eval("cd Class.new{ def goo; end }", "ls -M").should.not =~ /Object/
|
||||
pry_eval("cd Class.new{ def goo; end }.new", "ls").should_not =~ /Object/
|
||||
pry_eval("cd Class.new{ def goo; end }", "ls -M").should_not =~ /Object/
|
||||
end
|
||||
|
||||
it "should include object if -v is given" do
|
||||
|
@ -23,8 +23,8 @@ describe "ls" do
|
|||
end
|
||||
|
||||
it "should not include super-classes when -q is given" do
|
||||
pry_eval("cd Class.new(Class.new{ def goo; end }).new", "ls -q").should.not =~ /goo/
|
||||
pry_eval("cd Class.new(Class.new{ def goo; end })", "ls -M -q").should.not =~ /goo/
|
||||
pry_eval("cd Class.new(Class.new{ def goo; end }).new", "ls -q").should_not =~ /goo/
|
||||
pry_eval("cd Class.new(Class.new{ def goo; end })", "ls -M -q").should_not =~ /goo/
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -60,8 +60,8 @@ describe "ls" do
|
|||
end
|
||||
|
||||
it "should not show protected/private by default" do
|
||||
pry_eval("ls -M Class.new{ def goo; end; private :goo }").should.not =~ /goo/
|
||||
pry_eval("ls Class.new{ def goo; end; protected :goo }.new").should.not =~ /goo/
|
||||
pry_eval("ls -M Class.new{ def goo; end; private :goo }").should_not =~ /goo/
|
||||
pry_eval("ls Class.new{ def goo; end; protected :goo }.new").should_not =~ /goo/
|
||||
end
|
||||
|
||||
it "should show public methods with -p" do
|
||||
|
@ -93,12 +93,11 @@ describe "ls" do
|
|||
end
|
||||
end
|
||||
|
||||
test.should.not.raise
|
||||
expect(test).to_not raise_error
|
||||
end
|
||||
|
||||
it "should show error message when instance is given with -M option" do
|
||||
error = lambda{ pry_eval("ls -M String.new") }.should.raise(Pry::CommandError)
|
||||
error.message.should.match(/-M only makes sense with a Module or a Class/)
|
||||
expect { pry_eval("ls -M String.new") }.to raise_error(Pry::CommandError, /-M only makes sense with a Module or a Class/)
|
||||
end
|
||||
|
||||
|
||||
|
@ -114,12 +113,12 @@ describe "ls" do
|
|||
describe 'with -l' do
|
||||
it 'should find locals and sort by descending size' do
|
||||
result = pry_eval("aa = 'asdf'; bb = 'xyz'", 'ls -l')
|
||||
result.should.not =~ /=>/
|
||||
result.should.not =~ /0x\d{5}/
|
||||
result.should_not =~ /=>/
|
||||
result.should_not =~ /0x\d{5}/
|
||||
result.should =~ /asdf.*xyz/m
|
||||
end
|
||||
it 'should not list pry noise' do
|
||||
pry_eval('ls -l').should.not =~ /_(?:dir|file|ex|pry|out|in)_/
|
||||
pry_eval('ls -l').should_not =~ /_(?:dir|file|ex|pry|out|in)_/
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -145,7 +144,7 @@ describe "ls" do
|
|||
end
|
||||
|
||||
it "should behave normally when invoked on Module itself" do
|
||||
pry_eval("ls Module").should.not =~ /Pry/
|
||||
pry_eval("ls Module").should_not =~ /Pry/
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -162,7 +161,7 @@ describe "ls" do
|
|||
end
|
||||
|
||||
it "should not show constants defined on parent modules by default" do
|
||||
pry_eval("class TempFoo2; LHGRAB = 1; end; class TempFoo3 < TempFoo2; BARGHL = 1; end", "ls TempFoo3").should.not =~ /LHGRAB/
|
||||
pry_eval("class TempFoo2; LHGRAB = 1; end; class TempFoo3 < TempFoo2; BARGHL = 1; end", "ls TempFoo3").should_not =~ /LHGRAB/
|
||||
end
|
||||
|
||||
it "should show constants defined on ancestors with -v" do
|
||||
|
@ -171,7 +170,7 @@ describe "ls" do
|
|||
|
||||
it "should not autoload constants!" do
|
||||
autoload :McflurgleTheThird, "/tmp/this-file-d000esnat-exist.rb"
|
||||
lambda{ pry_eval("ls -c") }.should.not.raise
|
||||
expect { pry_eval("ls -c") }.to_not raise_error
|
||||
end
|
||||
|
||||
it "should show constants for an object's class regardless of mixins" do
|
||||
|
@ -179,14 +178,14 @@ describe "ls" do
|
|||
"cd Pry.new",
|
||||
"extend Module.new",
|
||||
"ls -c"
|
||||
).should.match(/Method/)
|
||||
).should match(/Method/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "grep" do
|
||||
it "should reduce the number of outputted things" do
|
||||
pry_eval("ls -c Object").should =~ /ArgumentError/
|
||||
pry_eval("ls -c Object --grep Run").should.not =~ /ArgumentError/
|
||||
pry_eval("ls -c Object --grep Run").should_not =~ /ArgumentError/
|
||||
end
|
||||
|
||||
it "should still output matching things" do
|
||||
|
@ -234,7 +233,7 @@ describe "ls" do
|
|||
describe 'on java objects' do
|
||||
it 'should omit java-esque aliases by default' do
|
||||
pry_eval('ls java.lang.Thread.current_thread').should =~ /\bthread_group\b/
|
||||
pry_eval('ls java.lang.Thread.current_thread').should.not =~ /\bgetThreadGroup\b/
|
||||
pry_eval('ls java.lang.Thread.current_thread').should_not =~ /\bgetThreadGroup\b/
|
||||
end
|
||||
|
||||
it 'should include java-esque aliases if requested' do
|
||||
|
|
|
@ -101,7 +101,7 @@ describe "play" do
|
|||
end
|
||||
|
||||
it 'has pretty error messages when -d cant find object' do
|
||||
lambda { @t.process_command "play -d sdfsdf" }.should.raise(Pry::CommandError).message.should.match(/Cannot locate/)
|
||||
expect { @t.process_command "play -d sdfsdf" }.to raise_error(Pry::CommandError, /Cannot locate/)
|
||||
end
|
||||
|
||||
it 'should play a method (a single line)' do
|
||||
|
|
|
@ -13,13 +13,13 @@ describe "raise-up" do
|
|||
|
||||
it "should raise the exception with raise-up" do
|
||||
redirect_pry_io(InputTester.new("raise NoMethodError", "raise-up NoMethodError")) do
|
||||
lambda { Object.new.pry }.should.raise NoMethodError
|
||||
expect { Object.new.pry }.to raise_error NoMethodError
|
||||
end
|
||||
end
|
||||
|
||||
it "should raise an unamed exception with raise-up" do
|
||||
redirect_pry_io(InputTester.new("raise 'stop'","raise-up 'noreally'")) do
|
||||
lambda { Object.new.pry }.should.raise RuntimeError, "noreally"
|
||||
expect { Object.new.pry }.to raise_error(RuntimeError, "noreally")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,7 @@ describe "raise-up" do
|
|||
end
|
||||
|
||||
it "should raise the most recently raised exception" do
|
||||
lambda { mock_pry("raise NameError, 'homographery'","raise-up") }.should.raise NameError, 'homographery'
|
||||
expect { mock_pry("raise NameError, 'homographery'","raise-up") }.to raise_error(NameError, 'homographery')
|
||||
end
|
||||
|
||||
it "should allow you to cd up and (eventually) out" do
|
||||
|
@ -42,7 +42,7 @@ describe "raise-up" do
|
|||
"deep = :deep", "cd deep","Pad.deep = self",
|
||||
"raise-up NoMethodError", "raise-up", @outer,
|
||||
"raise-up", "exit-all")) do
|
||||
lambda { Pry.start(:outer) }.should.raise NoMethodError
|
||||
expect { Pry.start(:outer) }.to raise_error NoMethodError
|
||||
end
|
||||
|
||||
Pad.deep.should == :deep
|
||||
|
@ -51,6 +51,6 @@ describe "raise-up" do
|
|||
end
|
||||
|
||||
it "should jump immediately out of nested contexts with !" do
|
||||
lambda { mock_pry("cd 1", "cd 2", "cd 3", "raise-up! 'fancy that...'") }.should.raise RuntimeError, 'fancy that...'
|
||||
expect { mock_pry("cd 1", "cd 2", "cd 3", "raise-up! 'fancy that...'") }.to raise_error(RuntimeError, 'fancy that...')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,19 +3,19 @@ require_relative '../helper'
|
|||
describe "reload_code" do
|
||||
describe "reload_current_file" do
|
||||
it 'raises an error source code not found' do
|
||||
proc do
|
||||
expect do
|
||||
eval <<-RUBY, TOPLEVEL_BINDING, 'does_not_exist.rb', 1
|
||||
pry_eval(binding, "reload-code")
|
||||
RUBY
|
||||
end.should.raise(Pry::CommandError)
|
||||
end.to raise_error(Pry::CommandError)
|
||||
end
|
||||
|
||||
it 'raises an error when class not found' do
|
||||
proc do
|
||||
expect do
|
||||
pry_eval(
|
||||
"cd Class.new(Class.new{ def goo; end; public :goo })",
|
||||
"reload-code")
|
||||
end.should.raise(Pry::CommandError)
|
||||
end.to raise_error(Pry::CommandError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,11 +14,11 @@ describe "Command::ShellCommand" do
|
|||
|
||||
describe ".cd" do
|
||||
before do
|
||||
Dir.stubs(:chdir)
|
||||
allow(Dir).to receive(:chdir)
|
||||
end
|
||||
|
||||
it "saves the current working directory" do
|
||||
Dir.stubs(:pwd).returns("initial_path")
|
||||
expect(Dir).to receive(:pwd).at_least(:once).and_return("initial_path") # called once in MRI, 2x in RBX
|
||||
|
||||
@t.eval ".cd new_path"
|
||||
@t.command_state.old_pwd.should == "initial_path"
|
||||
|
@ -26,14 +26,14 @@ describe "Command::ShellCommand" do
|
|||
|
||||
describe "given a path" do
|
||||
it "sends the path to File.expand_path" do
|
||||
Dir.expects(:chdir).with(File.expand_path("new_path"))
|
||||
expect(Dir).to receive(:chdir).with(File.expand_path("new_path"))
|
||||
@t.eval ".cd new_path"
|
||||
end
|
||||
end
|
||||
|
||||
describe "given an empty string" do
|
||||
it "sends ~ to File.expand_path" do
|
||||
Dir.expects(:chdir).with(File.expand_path("~"))
|
||||
expect(Dir).to receive(:chdir).with(File.expand_path("~"))
|
||||
@t.eval ".cd "
|
||||
end
|
||||
end
|
||||
|
@ -41,19 +41,18 @@ describe "Command::ShellCommand" do
|
|||
describe "given a dash" do
|
||||
describe "given no prior directory" do
|
||||
it "raises the correct error" do
|
||||
lambda { @t.eval ".cd -" }.should.raise(StandardError).
|
||||
message.should == "No prior directory available"
|
||||
expect { @t.eval ".cd -" }.to raise_error(StandardError, "No prior directory available")
|
||||
end
|
||||
end
|
||||
|
||||
describe "given a prior directory" do
|
||||
it "sends the user's last pry working directory to File.expand_path" do
|
||||
Dir.stubs(:pwd).returns("initial_path")
|
||||
expect(Dir).to receive(:pwd).at_least(:twice).and_return("initial_path") # called 2x in MRI, 3x in RBX
|
||||
|
||||
Dir.expects(:chdir).with(File.expand_path("new_path"))
|
||||
expect(Dir).to receive(:chdir).with(File.expand_path("new_path"))
|
||||
@t.eval ".cd new_path"
|
||||
|
||||
Dir.expects(:chdir).with(File.expand_path("initial_path"))
|
||||
expect(Dir).to receive(:chdir).with(File.expand_path("initial_path"))
|
||||
@t.eval ".cd -"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ describe "show-doc" do
|
|||
end
|
||||
|
||||
it 'should raise exception when cannot find docs' do
|
||||
lambda { pry_eval(binding, "show-doc @o.no_docs") }.should.raise(Pry::CommandError)
|
||||
expect { pry_eval(binding, "show-doc @o.no_docs") }.to raise_error Pry::CommandError
|
||||
end
|
||||
|
||||
it 'should output a method\'s documentation with line numbers' do
|
||||
|
@ -130,7 +130,7 @@ describe "show-doc" do
|
|||
Pry.config.color = true
|
||||
# I don't want the test to rely on which colour codes are there, just to
|
||||
# assert that "something" is being colourized.
|
||||
t.eval("show-doc c#initialize").should.not =~ /c.new :foo/
|
||||
t.eval("show-doc c#initialize").should_not =~ /c.new :foo/
|
||||
ensure
|
||||
Pry.config.color = false
|
||||
end
|
||||
|
@ -150,7 +150,7 @@ describe "show-doc" do
|
|||
Pry.config.color = true
|
||||
# I don't want the test to rely on which colour codes are there, just to
|
||||
# assert that "something" is being colourized.
|
||||
t.eval("show-doc c#initialize").should.not =~ /c.new\(:foo\)/
|
||||
t.eval("show-doc c#initialize").should_not =~ /c.new\(:foo\)/
|
||||
ensure
|
||||
Pry.config.color = false
|
||||
end
|
||||
|
@ -171,7 +171,7 @@ describe "show-doc" do
|
|||
t = pry_tester(binding)
|
||||
Pry.config.color = true
|
||||
t.eval("show-doc c#decolumnize").should =~ /ls -l \$HOME/
|
||||
t.eval("show-doc c#decolumnize").should.not =~ /`ls -l \$HOME`/
|
||||
t.eval("show-doc c#decolumnize").should_not =~ /`ls -l \$HOME`/
|
||||
ensure
|
||||
Pry.config.color = false
|
||||
end
|
||||
|
@ -336,7 +336,7 @@ describe "show-doc" do
|
|||
end
|
||||
|
||||
result = pry_eval('show-doc Aarrrrrghh')
|
||||
result.should.not =~ /available monkeypatches/
|
||||
result.should_not =~ /available monkeypatches/
|
||||
Object.remove_const(:Aarrrrrghh)
|
||||
end
|
||||
end
|
||||
|
@ -390,7 +390,7 @@ describe "show-doc" do
|
|||
it 'should return doc for first valid module' do
|
||||
result = pry_eval("show-doc TestHost::M")
|
||||
result.should =~ /goodbye/
|
||||
result.should.not =~ /hello/
|
||||
result.should_not =~ /hello/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -490,8 +490,7 @@ describe "show-doc" do
|
|||
|
||||
it 'errors when class has no superclass to show' do
|
||||
t = pry_tester
|
||||
lambda { t.process_command "show-doc Jesus::Brian" }.should.raise(Pry::CommandError).message.
|
||||
should =~ /Couldn't locate/
|
||||
expect { t.process_command "show-doc Jesus::Brian" }.to raise_error(Pry::CommandError, /Couldn't locate/)
|
||||
end
|
||||
|
||||
it 'shows warning when reverting to superclass docs' do
|
||||
|
@ -552,8 +551,7 @@ describe "show-doc" do
|
|||
|
||||
it 'errors when module has no included module to show' do
|
||||
t = pry_tester
|
||||
lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
|
||||
should =~ /Couldn't locate/
|
||||
expect { t.process_command "show-source Jesus::Zeta" }.to raise_error(Pry::CommandError, /Couldn't locate/)
|
||||
end
|
||||
|
||||
it 'shows nth level included module doc (when no intermediary modules have code either)' do
|
||||
|
|
|
@ -91,9 +91,7 @@ describe "show-source" do
|
|||
it "should not find instance methods with self.moo" do
|
||||
c = Class.new{ def moo; "ve over!"; end }
|
||||
|
||||
proc {
|
||||
pry_eval(binding, 'cd c', 'show-source self.moo')
|
||||
}.should.raise(Pry::CommandError).message.should =~ /Couldn't locate/
|
||||
expect { pry_eval(binding, 'cd c', 'show-source self.moo') }.to raise_error(Pry::CommandError, /Couldn't locate/)
|
||||
end
|
||||
|
||||
it "should find normal methods with self.moo" do
|
||||
|
@ -105,9 +103,7 @@ describe "show-source" do
|
|||
it "should not find normal methods with self#moo" do
|
||||
c = Class.new{ def self.moo; "ve over!"; end }
|
||||
|
||||
proc {
|
||||
pry_eval(binding, 'cd c', 'show-source self#moo')
|
||||
}.should.raise(Pry::CommandError).message.should =~ /Couldn't locate/
|
||||
expect { pry_eval(binding, 'cd c', 'show-source self#moo') }.to raise_error(Pry::CommandError, /Couldn't locate/)
|
||||
end
|
||||
|
||||
it "should find normal methods (i.e non-instance methods) by default" do
|
||||
|
@ -146,9 +142,7 @@ describe "show-source" do
|
|||
it "should raise a CommandError when super method doesn't exist" do
|
||||
def @o.foo(*bars); end
|
||||
|
||||
proc {
|
||||
pry_eval(binding, "show-source --super @o.foo")
|
||||
}.should.raise(Pry::CommandError).message.should =~ /No superclass found/
|
||||
expect { pry_eval(binding, "show-source --super @o.foo") }.to raise_error(Pry::CommandError, /No superclass found/)
|
||||
end
|
||||
|
||||
it "should output the source of a method defined inside Pry" do
|
||||
|
@ -277,7 +271,7 @@ describe "show-source" do
|
|||
|
||||
it "source of variable should take precedence over method that is being shadowed" do
|
||||
source = @t.eval('show-source hello')
|
||||
source.should.not =~ /def hello/
|
||||
source.should_not =~ /def hello/
|
||||
source.should =~ /proc \{ ' smile ' \}/
|
||||
end
|
||||
|
||||
|
@ -519,7 +513,7 @@ describe "show-source" do
|
|||
end
|
||||
|
||||
result = pry_eval('show-source Aarrrrrghh')
|
||||
result.should.not =~ /available monkeypatches/
|
||||
result.should_not =~ /available monkeypatches/
|
||||
Object.remove_const(:Aarrrrrghh)
|
||||
end
|
||||
end
|
||||
|
@ -557,16 +551,13 @@ describe "show-source" do
|
|||
end
|
||||
|
||||
it 'should be unable to find module source if no methods defined' do
|
||||
proc {
|
||||
pry_eval(TestHost::C, 'show-source')
|
||||
}.should.raise(Pry::CommandError).
|
||||
message.should =~ /Couldn't locate/
|
||||
expect { pry_eval(TestHost::C, 'show-source') }.to raise_error(Pry::CommandError, /Couldn't locate/)
|
||||
end
|
||||
|
||||
it 'should display method code (rather than class) if Pry started inside method binding' do
|
||||
out = TestHost::D.invoked_in_method
|
||||
out.should =~ /invoked_in_method/
|
||||
out.should.not =~ /module D/
|
||||
out.should_not =~ /module D/
|
||||
end
|
||||
|
||||
it 'should display class source when inside instance' do
|
||||
|
@ -607,7 +598,7 @@ describe "show-source" do
|
|||
it 'should return source for first valid module' do
|
||||
out = pry_eval('show-source BabyDuck::Muesli')
|
||||
out.should =~ /def d; end/
|
||||
out.should.not =~ /def a; end/
|
||||
out.should_not =~ /def a; end/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -743,13 +734,12 @@ describe "show-source" do
|
|||
it 'ignores included modules' do
|
||||
t = pry_tester
|
||||
t.process_command "show-source Jesus::Jangle"
|
||||
t.last_output.should.not =~ /lillybing/
|
||||
t.last_output.should_not =~ /lillybing/
|
||||
end
|
||||
|
||||
it 'errors when class has no superclass to show' do
|
||||
t = pry_tester
|
||||
lambda { t.process_command "show-source Jesus::Brian" }.should.raise(Pry::CommandError).message.
|
||||
should =~ /Couldn't locate/
|
||||
expect { t.process_command "show-source Jesus::Brian" }.to raise_error(Pry::CommandError, /Couldn't locate/)
|
||||
end
|
||||
|
||||
it 'shows warning when reverting to superclass code' do
|
||||
|
@ -808,8 +798,7 @@ describe "show-source" do
|
|||
|
||||
it 'errors when module has no included module to show' do
|
||||
t = pry_tester
|
||||
lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
|
||||
should =~ /Couldn't locate/
|
||||
expect { t.process_command "show-source Jesus::Zeta" }.to raise_error(Pry::CommandError, /Couldn't locate/)
|
||||
end
|
||||
|
||||
it 'shows nth level included module code (when no intermediary modules have code either)' do
|
||||
|
|
|
@ -113,7 +113,7 @@ describe "watch expression" do
|
|||
end
|
||||
|
||||
it "deletes delete" do
|
||||
eval('watch').should.not =~ /delete/
|
||||
eval('watch').should_not =~ /delete/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,9 +74,7 @@ describe "whereami" do
|
|||
END
|
||||
end
|
||||
|
||||
lambda{
|
||||
Cor.instance_method(:blimey!).source
|
||||
}.should.raise(MethodSource::SourceNotFoundError)
|
||||
expect { Cor.instance_method(:blimey!).source }.to raise_error MethodSource::SourceNotFoundError
|
||||
|
||||
Cor.new.blimey!.should =~ /Cor#blimey!.*Look at me/m
|
||||
Object.remove_const(:Cor)
|
||||
|
@ -199,7 +197,7 @@ describe "whereami" do
|
|||
def blimey!
|
||||
out = pry_eval(binding, 'whereami -n')
|
||||
out.should =~ /^\s*def/
|
||||
out.should.not =~ /\=\>/
|
||||
out.should_not =~ /\=\>/
|
||||
end
|
||||
end
|
||||
Cor.new.blimey!
|
||||
|
@ -214,10 +212,10 @@ describe "whereami" do
|
|||
:punk
|
||||
:sanders
|
||||
|
||||
out.should.not =~ /:litella/
|
||||
out.should_not =~ /:litella/
|
||||
out.should =~ /:pig/
|
||||
out.should =~ /:punk/
|
||||
out.should.not =~ /:sanders/
|
||||
out.should_not =~ /:sanders/
|
||||
|
||||
Pry.config.default_window_size = old_size
|
||||
end
|
||||
|
|
|
@ -30,12 +30,12 @@ describe Pry::InputCompleter do
|
|||
# another jruby hack :((
|
||||
if !Pry::Helpers::BaseHelpers.jruby?
|
||||
it "should not crash if there's a Module that has a symbolic name." do
|
||||
lambda{ Pry::InputCompleter.new(Readline).call "a.to_s.", :target => Pry.binding_for(Object.new) }.should.not.raise Exception
|
||||
expect { Pry::InputCompleter.new(Readline).call "a.to_s.", :target => Pry.binding_for(Object.new) }.not_to raise_error Exception
|
||||
end
|
||||
end
|
||||
|
||||
it 'should take parenthesis and other characters into account for symbols' do
|
||||
lambda { Pry::InputCompleter.new(Readline).call(":class)", :target => Pry.binding_for(Object.new)) }.should.not.raise(RegexpError)
|
||||
expect { Pry::InputCompleter.new(Readline).call ":class)", :target => Pry.binding_for(Object.new) }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'should complete instance variables' do
|
||||
|
@ -209,6 +209,6 @@ describe Pry::InputCompleter do
|
|||
|
||||
it 'should not return nil in its output' do
|
||||
pry = Pry.new
|
||||
Pry::InputCompleter.new(Readline, pry).call("pry.", :target => binding).should.not.include nil
|
||||
Pry::InputCompleter.new(Readline, pry).call("pry.", :target => binding).should_not include nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ describe Pry::Config do
|
|||
it "raises an ArgumentError on assignment of a reserved key" do
|
||||
local = Pry::Config.new
|
||||
Pry::Config::RESERVED_KEYS.each do |key|
|
||||
should.raise(ArgumentError) { local[key] = 1 }
|
||||
expect { local[key] = 1 }.to raise_error ArgumentError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -112,7 +112,7 @@ describe Pry::Config do
|
|||
|
||||
it "compares equality against an object who does not implement #to_hash" do
|
||||
local1 = Pry::Config.new(nil)
|
||||
local1.should.not == Object.new
|
||||
local1.should_not == Object.new
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -136,7 +136,7 @@ describe Pry::Config do
|
|||
it "returns a duplicate of the lookup table" do
|
||||
local = Pry::Config.new(nil)
|
||||
local.to_hash.merge!("foo" => 42)
|
||||
local.foo.should.not == 42
|
||||
local.foo.should_not == 42
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -163,7 +163,7 @@ describe Pry::Config do
|
|||
end
|
||||
|
||||
it "raises a TypeError for objects who can't become a Hash" do
|
||||
should.raise(TypeError) { @config.merge!(Object.new) }
|
||||
expect { @config.merge!(Object.new) }.to raise_error TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ describe Pry::DEFAULT_CONTROL_D_HANDLER do
|
|||
describe 'at top-level session' do
|
||||
it 'should break out of a REPL loop' do
|
||||
instance = Pry.new
|
||||
instance.binding_stack.should.not.be.empty
|
||||
instance.eval(nil).should.be.false
|
||||
instance.binding_stack.should.be.empty
|
||||
instance.binding_stack.should_not be_empty
|
||||
instance.eval(nil).should equal false
|
||||
instance.binding_stack.should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -31,7 +31,7 @@ describe Pry::DEFAULT_CONTROL_D_HANDLER do
|
|||
t = pry_tester
|
||||
t.eval "cd Object.new"
|
||||
t.eval("_pry_.binding_stack.size").should == 2
|
||||
t.eval("_pry_.eval(nil)").should.be.true
|
||||
t.eval("_pry_.eval(nil)").should equal true
|
||||
t.eval("_pry_.binding_stack.size").should == 1
|
||||
end
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ describe Pry::Helpers::DocumentationHelpers do
|
|||
end
|
||||
|
||||
it "should syntax highlight indented code" do
|
||||
@helper.process_rdoc(" 4 + 4\n").should.not == " 4 + 4\n"
|
||||
@helper.process_rdoc(" 4 + 4\n").should_not == " 4 + 4\n"
|
||||
end
|
||||
|
||||
it "should highlight words surrounded by +s" do
|
||||
|
|
|
@ -7,13 +7,13 @@ describe "Pry.config.exception_whitelist" do
|
|||
|
||||
it 'should rescue all exceptions NOT specified on whitelist' do
|
||||
Pry.config.exception_whitelist.include?(NameError).should == false
|
||||
lambda { Pry.start(self, :input => StringIO.new("raise NameError\nexit"), :output => @str_output) }.should.not.raise NameError
|
||||
expect { Pry.start(self, :input => StringIO.new("raise NameError\nexit"), :output => @str_output) }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'should NOT rescue exceptions specified on whitelist' do
|
||||
old_whitelist = Pry.config.exception_whitelist
|
||||
Pry.config.exception_whitelist = [NameError]
|
||||
lambda { Pry.start(self, :input => StringIO.new("raise NameError"), :output => @str_output) }.should.raise NameError
|
||||
expect { Pry.start(self, :input => StringIO.new("raise NameError"), :output => @str_output) }.to raise_error NameError
|
||||
Pry.config.exception_whitelist = old_whitelist
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'bundler/setup'
|
||||
require 'pry/test/helper'
|
||||
Bundler.require :default, :test
|
||||
require_relative 'spec_helpers/bacon'
|
||||
require_relative 'spec_helpers/mock_pry'
|
||||
require_relative 'spec_helpers/repl_tester'
|
||||
|
||||
|
@ -32,3 +31,8 @@ if ENV["SET_TRACE_FUNC"]
|
|||
end
|
||||
|
||||
puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}"
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.alias_example_to :should
|
||||
config.include PryTestHelpers
|
||||
end
|
||||
|
|
|
@ -88,9 +88,8 @@ asfadsssaaad fasfaafdssd s
|
|||
end
|
||||
|
||||
it 'should not raise error' do
|
||||
should.not.raise(FloatDomainError) {
|
||||
Pry::Helpers.tablify(@out, @elem_len - 1)
|
||||
}
|
||||
expect { Pry::Helpers.tablify(@out, @elem_len - 1) }.not_to raise_error
|
||||
|
||||
end
|
||||
|
||||
it 'should format output as one column' do
|
||||
|
@ -99,7 +98,7 @@ asfadsssaaad fasfaafdssd s
|
|||
end
|
||||
end
|
||||
|
||||
describe 'decide between one-line or indented output' do
|
||||
Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'
|
||||
should 'decide between one-line or indented output' do
|
||||
Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == "head: ing\n"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -162,11 +162,11 @@ describe Pry do
|
|||
history = Pry::History.new(file_path: '~/test_history')
|
||||
error = Class.new(RuntimeError)
|
||||
|
||||
File.expects(:open).
|
||||
expect(File).to receive(:open).
|
||||
with(File.join(ENV['HOME'].to_s, "/test_history"), 'a', 0600).
|
||||
raises(error)
|
||||
and_raise(error)
|
||||
|
||||
-> { history.push 'a line' }.should.raise(error)
|
||||
expect { history.push 'a line' }.to raise_error error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ describe Pry::Hooks do
|
|||
it 'should not allow adding of a hook with a duplicate name' do
|
||||
@hooks.add_hook(:test_hook, :my_name) {}
|
||||
|
||||
lambda { @hooks.add_hook(:test_hook, :my_name) {} }.should.raise ArgumentError
|
||||
expect { @hooks.add_hook(:test_hook, :my_name) {} }.to raise_error
|
||||
end
|
||||
|
||||
it 'should create a new hook with a block' do
|
||||
|
@ -39,7 +39,7 @@ describe Pry::Hooks do
|
|||
end
|
||||
|
||||
it 'should raise if not given a block or any other object' do
|
||||
lambda { @hooks.add_hook(:test_hook, :my_name) }.should.raise ArgumentError
|
||||
expect { @hooks.add_hook(:test_hook, :my_name) }.to raise_error ArgumentError
|
||||
end
|
||||
|
||||
it 'should create multiple hooks for an event' do
|
||||
|
@ -69,7 +69,7 @@ describe Pry::Hooks do
|
|||
|
||||
h2.merge!(h1)
|
||||
h2.add_hook(:test_hook, :testing2) {}
|
||||
h2.get_hook(:test_hook, :testing2).should.not == h1.get_hook(:test_hook, :testing2)
|
||||
h2.get_hook(:test_hook, :testing2).should_not == h1.get_hook(:test_hook, :testing2)
|
||||
end
|
||||
|
||||
it 'should NOT overwrite hooks belonging to shared event in receiver' do
|
||||
|
@ -114,8 +114,8 @@ describe Pry::Hooks do
|
|||
h2 = Pry::Hooks.new
|
||||
|
||||
h3 = h2.merge(h1)
|
||||
h3.should.not == h1
|
||||
h3.should.not == h2
|
||||
h3.should_not == h1
|
||||
h3.should_not == h2
|
||||
end
|
||||
|
||||
it 'should contain hooks from original instance' do
|
||||
|
@ -158,7 +158,7 @@ describe Pry::Hooks do
|
|||
|
||||
hooks_dup.add_hook(:other_test_hook, :testing) { :okay_man }
|
||||
|
||||
hooks_dup.get_hook(:other_test_hook, :testing).should.not == @hooks.get_hook(:other_test_hook, :testing)
|
||||
hooks_dup.get_hook(:other_test_hook, :testing).should_not == @hooks.get_hook(:other_test_hook, :testing)
|
||||
end
|
||||
|
||||
it 'adding a new hook to dupped instance should not affect original' do
|
||||
|
@ -167,7 +167,7 @@ describe Pry::Hooks do
|
|||
|
||||
hooks_dup.add_hook(:test_hook, :testing2) { :okay_man }
|
||||
|
||||
hooks_dup.get_hook(:test_hook, :testing2).should.not == @hooks.get_hook(:test_hook, :testing2)
|
||||
hooks_dup.get_hook(:test_hook, :testing2).should_not == @hooks.get_hook(:test_hook, :testing2)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -403,7 +403,7 @@ describe Pry::Hooks do
|
|||
Pry.start(self, :hooks => hooks)
|
||||
end
|
||||
out.string.should =~ /little_duck/
|
||||
out.string.should.not =~ /jemima/
|
||||
out.string.should_not =~ /jemima/
|
||||
end
|
||||
|
||||
it 'should not interfere with command processing when replacing input code' do
|
||||
|
@ -420,7 +420,7 @@ describe Pry::Hooks do
|
|||
Pry.start(self, :hooks => hooks, :commands => commands)
|
||||
end
|
||||
out.string.should =~ /in hours of bitterness i imagine balls of sapphire, of metal/
|
||||
out.string.should.not =~ /little_duck/
|
||||
out.string.should_not =~ /little_duck/
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -437,9 +437,7 @@ describe Pry::Hooks do
|
|||
Pry.config.hooks.delete_hook(:after_eval, :simbads)
|
||||
end
|
||||
it "should not raise exceptions" do
|
||||
lambda{
|
||||
mock_pry("1", "2", "3")
|
||||
}.should.not.raise
|
||||
expect { mock_pry("1", "2", "3") }.to_not raise_error
|
||||
end
|
||||
|
||||
it "should print out a notice for each exception raised" do
|
||||
|
|
|
@ -287,9 +287,7 @@ OUTPUT
|
|||
result = line.split("#").last.strip
|
||||
if result == ""
|
||||
it "should fail to parse nesting on line #{i + 1} of example_nesting.rb" do
|
||||
lambda {
|
||||
Pry::Indent.nesting_at(test, i + 1)
|
||||
}.should.raise(Pry::Indent::UnparseableNestingError)
|
||||
expect { Pry::Indent.nesting_at(test, i + 1) }.to raise_error Pry::Indent::UnparseableNestingError
|
||||
end
|
||||
else
|
||||
it "should parse nesting on line #{i + 1} of example_nesting.rb" do
|
||||
|
|
|
@ -93,7 +93,7 @@ describe Pry::Method do
|
|||
end
|
||||
|
||||
it 'should not raise an exception if receiver does not exist' do
|
||||
lambda { Pry::Method.from_str("random_klass.meth", Pry.binding_for(binding)) }.should.not.raise
|
||||
expect { Pry::Method.from_str("random_klass.meth", Pry.binding_for(binding)) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -228,7 +228,7 @@ describe Pry::Method do
|
|||
|
||||
describe 'all_from_class' do
|
||||
def should_find_method(name)
|
||||
Pry::Method.all_from_class(@class).map(&:name).should.include(name)
|
||||
Pry::Method.all_from_class(@class).map(&:name).should include name
|
||||
end
|
||||
|
||||
it 'should be able to find public instance methods defined in a class' do
|
||||
|
@ -281,7 +281,7 @@ describe Pry::Method do
|
|||
describe 'all_from_obj' do
|
||||
describe 'on normal objects' do
|
||||
def should_find_method(name)
|
||||
Pry::Method.all_from_obj(@obj).map(&:name).should.include(name)
|
||||
Pry::Method.all_from_obj(@obj).map(&:name).should include name
|
||||
end
|
||||
|
||||
it "should find methods defined in the object's class" do
|
||||
|
@ -313,7 +313,7 @@ describe Pry::Method do
|
|||
|
||||
it "should not find methods defined on the classes singleton class" do
|
||||
@obj = Class.new{ class << self; def meth; 1; end; end }.new
|
||||
Pry::Method.all_from_obj(@obj).map(&:name).should.not.include('meth')
|
||||
Pry::Method.all_from_obj(@obj).map(&:name).should_not include 'meth'
|
||||
end
|
||||
|
||||
it "should work in the face of an overridden send" do
|
||||
|
@ -324,7 +324,7 @@ describe Pry::Method do
|
|||
|
||||
describe 'on classes' do
|
||||
def should_find_method(name)
|
||||
Pry::Method.all_from_obj(@class).map(&:name).should.include(name)
|
||||
Pry::Method.all_from_obj(@class).map(&:name).should include name
|
||||
end
|
||||
|
||||
it "should find methods defined in the class' singleton class" do
|
||||
|
@ -344,7 +344,7 @@ describe Pry::Method do
|
|||
|
||||
it "should not find methods defined within the class" do
|
||||
@class = Class.new{ def meth; 1; end }
|
||||
Pry::Method.all_from_obj(@obj).map(&:name).should.not.include('meth')
|
||||
Pry::Method.all_from_obj(@obj).map(&:name).should_not include 'meth'
|
||||
end
|
||||
|
||||
it "should find methods defined on Class" do
|
||||
|
@ -473,12 +473,12 @@ describe Pry::Method do
|
|||
|
||||
it 'should return an empty Array if cannot find aliases' do
|
||||
meth = Pry::Method(@class.new.method(:eruct))
|
||||
meth.aliases.should.be.empty
|
||||
meth.aliases.should be_empty
|
||||
end
|
||||
|
||||
it 'should not include the own name in the list of aliases' do
|
||||
meth = Pry::Method(@class.new.method(:eat))
|
||||
meth.aliases.should.not.include "eat"
|
||||
meth.aliases.should_not include "eat"
|
||||
end
|
||||
|
||||
it 'should find aliases for top-level methods' do
|
||||
|
@ -490,7 +490,7 @@ describe Pry::Method do
|
|||
end
|
||||
|
||||
meth = Pry::Method.new(method(:my_top_level_method))
|
||||
meth.aliases.should.include 'my_other_top_level_method'
|
||||
meth.aliases.should include 'my_other_top_level_method'
|
||||
|
||||
class Object
|
||||
remove_method :my_top_level_method
|
||||
|
|
|
@ -27,40 +27,40 @@ describe "Pry::Pager" do
|
|||
|
||||
it "records short lines that don't add up to a page" do
|
||||
9.times { record_short_line }
|
||||
@pt.page?.should.be.false
|
||||
@pt.page?.should equal false
|
||||
end
|
||||
|
||||
it "records short lines that do add up to a page" do
|
||||
10.times { record_short_line }
|
||||
@pt.page?.should.be.true
|
||||
@pt.page?.should equal true
|
||||
end
|
||||
|
||||
it "treats a long line as taking up more than one row" do
|
||||
4.times { record_long_line }
|
||||
@pt.page?.should.be.false
|
||||
@pt.page?.should equal false
|
||||
record_long_line
|
||||
@pt.page?.should.be.true
|
||||
@pt.page?.should equal true
|
||||
end
|
||||
|
||||
it "records a string with an embedded newline" do
|
||||
3.times { record_multiline }
|
||||
@pt.page?.should.be.false
|
||||
@pt.page?.should equal false
|
||||
record_short_line
|
||||
@pt.page?.should.be.true
|
||||
@pt.page?.should equal true
|
||||
end
|
||||
|
||||
it "doesn't count a line until it ends" do
|
||||
12.times { record_string_without_newline }
|
||||
@pt.page?.should.be.false
|
||||
@pt.page?.should equal false
|
||||
record_short_line
|
||||
@pt.page?.should.be.true
|
||||
@pt.page?.should equal true
|
||||
end
|
||||
|
||||
it "doesn't count ansi color codes towards length" do
|
||||
9.times { record_string_with_color_codes }
|
||||
@pt.page?.should.be.false
|
||||
@pt.page?.should equal false
|
||||
record_string_with_color_codes
|
||||
@pt.page?.should.be.true
|
||||
@pt.page?.should equal true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ describe "Prompts" do
|
|||
config.expr_number.should == 1
|
||||
config.cont.should == true
|
||||
config._pry_.is_a?(Pry).should == true
|
||||
config.object.should == self
|
||||
expect(config.object).to eq self
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ describe "test Pry defaults" do
|
|||
end
|
||||
end.new
|
||||
|
||||
lambda { Pry.start(self, :input => arity_zero_input, :output => StringIO.new) }.should.not.raise Exception
|
||||
expect { Pry.start(self, :input => arity_zero_input, :output => StringIO.new) }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'should not pass in the prompt if the arity is -1' do
|
||||
|
@ -88,7 +88,7 @@ describe "test Pry defaults" do
|
|||
Pry.config.input = InputTester.new("7")
|
||||
@str_output = StringIO.new
|
||||
Object.new.pry :output => @str_output
|
||||
@str_output.string.should.not =~ /5\n.*6/
|
||||
@str_output.string.should_not =~ /5\n.*6/
|
||||
@str_output.string.should =~ /7/
|
||||
end
|
||||
|
||||
|
@ -367,7 +367,7 @@ describe "test Pry defaults" do
|
|||
|
||||
describe 'toplevel_binding' do
|
||||
it 'should be devoid of local variables' do
|
||||
pry_eval(Pry.toplevel_binding, "ls -l").should.not =~ /version/
|
||||
pry_eval(Pry.toplevel_binding, "ls -l").should_not =~ /version/
|
||||
end
|
||||
|
||||
it 'should have self the same as TOPLEVEL_BINDING' do
|
||||
|
|
|
@ -9,9 +9,7 @@ describe Pry do
|
|||
it "should catch serialization exceptions" do
|
||||
Pry.config.print = lambda { |*a| raise "catch-22" }
|
||||
|
||||
lambda {
|
||||
mock_pry("1")
|
||||
}.should.not.raise
|
||||
expect { mock_pry("1") }.to_not raise_error
|
||||
end
|
||||
|
||||
it "should display serialization exceptions" do
|
||||
|
|
|
@ -52,12 +52,12 @@ describe Pry do
|
|||
raise
|
||||
end
|
||||
|
||||
lambda { Pry.binding_for(o) }.should.not.raise Exception
|
||||
expect { Pry.binding_for(o) }.to_not raise_error
|
||||
end
|
||||
|
||||
it "should not leak local variables" do
|
||||
[Object.new, Array, 3].each do |obj|
|
||||
Pry.binding_for(obj).eval("local_variables").should.be.empty
|
||||
Pry.binding_for(obj).eval("local_variables").should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -80,12 +80,12 @@ describe Pry do
|
|||
|
||||
it "returns a frozen exception" do
|
||||
@pry.last_exception = @e.freeze
|
||||
@pry.last_exception.should.be.frozen?
|
||||
expect(@pry.last_exception).to be_frozen
|
||||
end
|
||||
|
||||
it "returns an object who mirrors itself as the wrapped exception" do
|
||||
@pry.last_exception = @e.freeze
|
||||
@pry.last_exception.should.be.instance_of?(StandardError)
|
||||
expect(@pry.last_exception).to be_an_instance_of StandardError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -102,9 +102,7 @@ describe Pry do
|
|||
|
||||
# bug fix for https://github.com/banister/pry/issues/93
|
||||
it 'should not leak pry constants into Object namespace' do
|
||||
lambda{
|
||||
pry_eval(Object.new, "Command")
|
||||
}.should.raise(NameError)
|
||||
expect { pry_eval(Object.new, "Command") }.to raise_error
|
||||
end
|
||||
|
||||
it 'should be able to operate inside the BasicObject class' do
|
||||
|
@ -156,9 +154,9 @@ describe Pry do
|
|||
end
|
||||
|
||||
it 'should not try to catch intended exceptions' do
|
||||
lambda { mock_pry("raise SystemExit") }.should.raise SystemExit
|
||||
expect { mock_pry("raise SystemExit") }.to raise_error SystemExit
|
||||
# SIGTERM
|
||||
lambda { mock_pry("raise SignalException.new(15)") }.should.raise SignalException
|
||||
expect { mock_pry("raise SignalException.new(15)") }.to raise_error SignalException
|
||||
end
|
||||
|
||||
describe "multi-line input" do
|
||||
|
@ -247,7 +245,7 @@ describe Pry do
|
|||
t.eval "42"
|
||||
res = t.eval "_out_"
|
||||
|
||||
res.should.be.kind_of Pry::HistoryArray
|
||||
res.should be_a_kind_of Pry::HistoryArray
|
||||
res[1..2].should == [:foo, 42]
|
||||
end
|
||||
|
||||
|
@ -257,7 +255,7 @@ describe Pry do
|
|||
t.eval "42"
|
||||
res = t.eval "_in_"
|
||||
|
||||
res.should.be.kind_of Pry::HistoryArray
|
||||
res.should be_a_kind_of Pry::HistoryArray
|
||||
res[1..2].should == [":foo\n", "42\n"]
|
||||
end
|
||||
|
||||
|
@ -273,7 +271,7 @@ describe Pry do
|
|||
mock_pry("foo!", "Pad.in = _in_[-1]; Pad.out = _out_[-1]")
|
||||
|
||||
Pad.in.should == "foo!\n"
|
||||
Pad.out.should.be.kind_of NoMethodError
|
||||
expect(Pad.out).to be_a_kind_of NoMethodError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -379,7 +377,7 @@ describe Pry do
|
|||
end
|
||||
|
||||
it "should raise if more than two arguments are passed to Object#pry" do
|
||||
lambda { pry(20, :quiet, :input => Readline) }.should.raise ArgumentError
|
||||
expect { pry(20, :quiet, :input => Readline) }.to raise_error ArgumentError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -396,9 +394,7 @@ describe Pry do
|
|||
|
||||
describe 'setting custom options' do
|
||||
it 'does not raise for unrecognized options' do
|
||||
should.not.raise?(NoMethodError) {
|
||||
instance = Pry.new(:custom_option => 'custom value')
|
||||
}
|
||||
expect { instance = Pry.new(:custom_option => 'custom value') }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'correctly handles the :quiet option (#1261)' do
|
||||
|
@ -412,8 +408,8 @@ describe Pry do
|
|||
location = "#{__FILE__}:#{__LINE__ + 1}"[1..-1] # omit leading .
|
||||
backtrace = Pry.new.backtrace
|
||||
|
||||
backtrace.should.not.be.nil
|
||||
backtrace.any? { |l| l.include?(location) }.should.be.true
|
||||
backtrace.should_not equal nil
|
||||
backtrace.any? { |l| l.include?(location) }.should equal true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ describe Pry do
|
|||
old_home = ENV['HOME']
|
||||
ENV['HOME'] = nil
|
||||
Pry.config.should_load_rc = true
|
||||
lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new) }.should.not.raise
|
||||
expect { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new) }.to_not raise_error
|
||||
|
||||
ENV['HOME'] = old_home
|
||||
end
|
||||
|
@ -79,7 +79,7 @@ describe Pry do
|
|||
end
|
||||
|
||||
it "should not raise exceptions" do
|
||||
@doing_it.should.not.raise
|
||||
expect(&@doing_it).to_not raise_error
|
||||
end
|
||||
|
||||
it "should continue to run pry" do
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
# Colorize output (based on greeneggs (c) 2009 Michael Fleet)
|
||||
# TODO: Make own gem (assigned to rking)
|
||||
module Bacon
|
||||
class Context
|
||||
include PryTestHelpers
|
||||
end
|
||||
|
||||
COLORS = {'F' => 31, 'E' => 35, 'M' => 33, '.' => 32}
|
||||
USE_COLOR = !(ENV['NO_PRY_COLORED_BACON'] == 'true') && Pry::Helpers::BaseHelpers.use_ansi_codes?
|
||||
|
||||
module TestUnitOutput
|
||||
def handle_requirement(description)
|
||||
error = yield
|
||||
|
||||
if error.empty?
|
||||
print colorize_string('.')
|
||||
else
|
||||
print colorize_string(error[0..0])
|
||||
end
|
||||
end
|
||||
|
||||
def handle_summary
|
||||
puts
|
||||
puts ErrorLog if Backtraces
|
||||
|
||||
out = "%d tests, %d assertions, %d failures, %d errors" %
|
||||
Counter.values_at(:specifications, :requirements, :failed, :errors)
|
||||
|
||||
if Counter.values_at(:failed, :errors).inject(:+) > 0
|
||||
puts colorize_string(out, 'F')
|
||||
else
|
||||
puts colorize_string(out, '.')
|
||||
end
|
||||
end
|
||||
|
||||
def colorize_string(text, color = nil)
|
||||
if USE_COLOR
|
||||
"\e[#{ COLORS[color || text] }m#{ text }\e[0m"
|
||||
else
|
||||
text
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Reset top-level binding at the beginning of each test case.
|
||||
module Bacon
|
||||
class Context
|
||||
def it_with_reset_binding(description, &block)
|
||||
Pry.toplevel_binding = nil
|
||||
it_without_reset_binding(description, &block)
|
||||
end
|
||||
alias it_without_reset_binding it
|
||||
alias it it_with_reset_binding
|
||||
end
|
||||
end
|
||||
|
||||
# Support mocha
|
||||
# mocha-on-bacon (c) Copyright (C) 2011, Eloy Durán <eloy.de.enige@gmail.com>
|
||||
module Bacon
|
||||
module MochaRequirementsCounter
|
||||
def self.increment
|
||||
Counter[:requirements] += 1
|
||||
end
|
||||
end
|
||||
|
||||
class Context
|
||||
include Mocha::API
|
||||
|
||||
def it_with_mocha(description, &block)
|
||||
it_without_mocha(description) do
|
||||
begin
|
||||
mocha_setup
|
||||
block.call
|
||||
mocha_verify(MochaRequirementsCounter)
|
||||
rescue Mocha::ExpectationError => e
|
||||
raise Error.new(:failed, e.message)
|
||||
ensure
|
||||
mocha_teardown
|
||||
end
|
||||
end
|
||||
end
|
||||
alias it_without_mocha it
|
||||
alias it it_with_mocha
|
||||
end
|
||||
end
|
|
@ -89,7 +89,7 @@ class ReplTester
|
|||
# @private
|
||||
def ensure_exit
|
||||
if @should_exit_naturally
|
||||
@thread[:session_ended].should.be.true
|
||||
raise "Session was not ended!" unless @thread[:session_ended].equal?(true)
|
||||
else
|
||||
input "exit-all"
|
||||
raise "REPL didn't die" unless @thread[:session_ended]
|
||||
|
|
|
@ -2,15 +2,11 @@ require_relative 'helper'
|
|||
|
||||
describe "Sticky locals (_file_ and friends)" do
|
||||
it 'locals should all exist upon initialization' do
|
||||
proc {
|
||||
pry_eval '_file_', '_dir_', '_ex_', '_pry_', '_'
|
||||
}.should.not.raise(NameError)
|
||||
expect { pry_eval '_file_', '_dir_', '_ex_', '_pry_', '_' }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'locals should still exist after cd-ing into a new context' do
|
||||
proc {
|
||||
pry_eval 'cd 0', '_file_', '_dir_', '_ex_', '_pry_', '_'
|
||||
}.should.not.raise(NameError)
|
||||
expect { pry_eval 'cd 0', '_file_', '_dir_', '_ex_', '_pry_', '_' }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'locals should keep value after cd-ing (_pry_)' do
|
||||
|
@ -173,7 +169,7 @@ describe "Sticky locals (_file_ and friends)" do
|
|||
pry.add_sticky_local(:test_local) { rand }
|
||||
value1 = pry.evaluate_ruby 'test_local'
|
||||
value2 = pry.evaluate_ruby 'test_local'
|
||||
value1.should.not == value2
|
||||
value1.should_not == value2
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ describe Pry do
|
|||
Pry.start
|
||||
end
|
||||
|
||||
@str_output.string.should.not =~ /SyntaxError/
|
||||
@str_output.string.should_not =~ /SyntaxError/
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ describe Pry::WrappedModule do
|
|||
|
||||
describe "#initialize" do
|
||||
it "should raise an exception when a non-module is passed" do
|
||||
lambda{ Pry::WrappedModule.new(nil) }.should.raise ArgumentError
|
||||
expect { Pry::WrappedModule.new(nil) }.to raise_error ArgumentError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -67,7 +67,7 @@ describe Pry::WrappedModule do
|
|||
end
|
||||
|
||||
it 'should raise when trying to access non-existent candidate' do
|
||||
lambda { Pry::WrappedModule(Host::CandidateTest).candidate(3) }.should.raise Pry::CommandError
|
||||
expect { Pry::WrappedModule(Host::CandidateTest).candidate(3) }.to raise_error Pry::CommandError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -162,15 +162,15 @@ describe Pry::WrappedModule do
|
|||
Pry::WrappedModule.new(class << Foo; self; end).method_prefix.should == "Foo."
|
||||
end
|
||||
|
||||
describe "of singleton classes of objects" do
|
||||
example "of singleton classes of objects" do
|
||||
Pry::WrappedModule.new(class << @foo; self; end).method_prefix.should == "self."
|
||||
end
|
||||
|
||||
describe "of anonymous classes should not be empty" do
|
||||
example "of anonymous classes should not be empty" do
|
||||
Pry::WrappedModule.new(Class.new).method_prefix.should =~ /#<Class:.*>#/
|
||||
end
|
||||
|
||||
describe "of singleton classes of anonymous classes should not be empty" do
|
||||
example "of singleton classes of anonymous classes should not be empty" do
|
||||
Pry::WrappedModule.new(class << Class.new; self; end).method_prefix.should =~ /#<Class:.*>./
|
||||
end
|
||||
end
|
||||
|
@ -191,7 +191,7 @@ describe Pry::WrappedModule do
|
|||
|
||||
describe ".singleton_instance" do
|
||||
it "should raise an exception when called on a non-singleton-class" do
|
||||
lambda{ Pry::WrappedModule.new(Class).singleton_instance }.should.raise ArgumentError
|
||||
expect { Pry::WrappedModule.new(Class).singleton_instance }.to raise_error ArgumentError
|
||||
end
|
||||
|
||||
it "should return the attached object" do
|
||||
|
@ -256,21 +256,27 @@ describe Pry::WrappedModule do
|
|||
end
|
||||
|
||||
describe ".from_str" do
|
||||
before do
|
||||
class Namespace
|
||||
Value = Class.new
|
||||
end
|
||||
end
|
||||
|
||||
it 'should lookup a constant' do
|
||||
m = Pry::WrappedModule.from_str("Host::CandidateTest", binding)
|
||||
m.wrapped.should == Host::CandidateTest
|
||||
m = Pry::WrappedModule.from_str("Namespace::Value", binding)
|
||||
m.wrapped.should == Namespace::Value
|
||||
end
|
||||
|
||||
it 'should lookup a local' do
|
||||
local = Host::CandidateTest
|
||||
local = Namespace::Value
|
||||
m = Pry::WrappedModule.from_str("local", binding)
|
||||
m.wrapped.should == Host::CandidateTest
|
||||
m.wrapped.should == Namespace::Value
|
||||
end
|
||||
|
||||
it 'should lookup an ivar' do
|
||||
@ivar = Host::CandidateTest
|
||||
@ivar = Namespace::Value
|
||||
m = Pry::WrappedModule.from_str("@ivar", binding)
|
||||
m.wrapped.should == Host::CandidateTest
|
||||
m.wrapped.should == Namespace::Value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue