Skip to content

Commit

Permalink
Switch test suite to RSpec
Browse files Browse the repository at this point in the history
Removes Bacon and Mocha

Reasoning explained in this comment: pry#277 (comment)

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 pry#1281 is merged.
This makes pry#1278 unnecessary.
  • Loading branch information
JoshCheek committed Aug 10, 2014
1 parent c6f8d5c commit 144d32e
Show file tree
Hide file tree
Showing 51 changed files with 276 additions and 455 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

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

Expand Down Expand Up @@ -48,8 +48,8 @@
end
end.parse_options(["--optiontest", "--optiontest2"])

run.should.be.true
run2.should.be.true
run.should equal true
run2.should equal true
end

end
Expand Down
6 changes: 3 additions & 3 deletions spec/code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
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
Expand Down Expand Up @@ -194,7 +194,7 @@ def self.main
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

Expand Down
15 changes: 5 additions & 10 deletions spec/command_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
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
Expand All @@ -248,7 +248,7 @@
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
Expand All @@ -264,13 +264,8 @@

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
Expand Down Expand Up @@ -488,7 +483,7 @@
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

Expand Down
59 changes: 22 additions & 37 deletions spec/command_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

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
Expand All @@ -33,7 +33,7 @@
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

Expand Down Expand Up @@ -67,27 +67,21 @@

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
Expand All @@ -103,9 +97,7 @@
@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
Expand Down Expand Up @@ -211,7 +203,7 @@
@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

Expand Down Expand Up @@ -289,22 +281,19 @@
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
Expand All @@ -326,7 +315,7 @@ def imported_helper_method; end
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

Expand All @@ -340,7 +329,7 @@ def imported_helper_method; end
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

Expand All @@ -358,9 +347,7 @@ def imported_helper_method; end
@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


Expand All @@ -382,13 +369,13 @@ def imported_helper_method; end
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
Expand Down Expand Up @@ -592,9 +579,7 @@ def imported_helper_method; end

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

Expand Down
17 changes: 4 additions & 13 deletions spec/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
#
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
Expand Down Expand Up @@ -198,9 +196,7 @@ def proccces
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
Expand Down Expand Up @@ -402,10 +398,7 @@ def process

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

Expand Down Expand Up @@ -619,9 +612,7 @@ def process(&block)
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
Expand Down
2 changes: 1 addition & 1 deletion spec/commands/amend_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def hello
error = e
end

error.should.not.be.nil
error.should_not equal nil
error.message.should =~ /No input to amend/
end

Expand Down
10 changes: 3 additions & 7 deletions spec/commands/cat/file_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
describe Pry::Command::Cat::FileFormatter do
describe "#file_and_line" do
before do
@p = Pry.new
@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
Expand Down Expand Up @@ -43,7 +39,7 @@
file_name, line_num = ff.file_and_line
file_name.should == "C:\\Ruby193\\pry_instance.rb"
line_num.should == 2
end
end
end

describe "UNIX-like filesystem" do
Expand Down
8 changes: 2 additions & 6 deletions spec/commands/cat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def last_exception=(e)

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

Expand Down Expand Up @@ -135,9 +133,7 @@ def @o.broken_method

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
Expand Down
Loading

0 comments on commit 144d32e

Please sign in to comment.