-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test fixes #84
base: master
Are you sure you want to change the base?
Test fixes #84
Changes from all commits
422a7ff
c969ff7
5f8fb97
a7d0a11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format documentation |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,128 @@ | ||
require './spec/spec_helper' | ||
require 'spec_helper' | ||
|
||
describe "pry-rescue commands" do | ||
describe "try-again" do | ||
it "should throw try_again" do | ||
PryRescue.should_receive(:in_exception_context?).and_return{ true } | ||
RSpec.describe "#Pry-rescue commands" do | ||
describe "#try-again" do | ||
it "expect to throw try_again" do | ||
expect(PryRescue).to receive(:in_exception_context?).and_return(true) | ||
|
||
lambda{ | ||
Pry.new.process_command "try-again", '', TOPLEVEL_BINDING | ||
}.should throw_symbol :try_again | ||
expect( lambda{ Pry.new.process_command "try-again TOPLEVEL_BINDING" } ).to throw_symbol :try_again | ||
end | ||
|
||
it "should raise a CommandError if not in Pry::rescue" do | ||
PryRescue.should_receive(:in_exception_context?).and_return{ false } | ||
it "expect to raise a CommandError if not in Pry::rescue" do | ||
# expect(PryRescue).to receive(:in_exception_context?).and_return(false) | ||
allow(PryRescue).to receive(:in_exception_context?).and_return(false) | ||
|
||
lambda{ | ||
Pry.new.process_command "try-again", '', TOPLEVEL_BINDING | ||
}.should raise_error Pry::CommandError | ||
expect{ Pry.new.process_command "try-again TOPLEVEL_BINDING" }.to raise_error Pry::CommandError | ||
end | ||
end | ||
|
||
describe "cd-cause" do | ||
it "should enter the context of an explicit exception" do | ||
describe "#cd-cause" do | ||
it "expect to not enter the context of an explicit exception" do | ||
begin | ||
b1 = binding | ||
raise "original" | ||
rescue => e1 | ||
rescue => ErrorOne | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @magicalbanana This creates a new global constant, which you almost certainly don't want to do (it will leak between tests). If you need to extend the scope of the variable use a local that's set to nil at the start of the test. Same applies everywhere you are rescuing into a constant. |
||
b2 = binding | ||
end | ||
|
||
Pry.should_receive(:rescued).once.with{ |raised| | ||
raised.should == e1 | ||
} | ||
|
||
Pry.new.process_command 'cd-cause e1', '', binding | ||
end | ||
|
||
it "should enter the context of _ex_ if no exception is given" do | ||
b2 = nil | ||
_ex_ = nil | ||
Pry::rescue do | ||
begin | ||
b1 = binding | ||
raise "original" | ||
rescue => _ex_ | ||
b2 = binding | ||
end | ||
expect(Pry).to receive(:rescued) do |raised| | ||
expect(raised).to eq(ErrorOne) | ||
end | ||
|
||
Pry.should_receive(:rescued).once.with{ |raised| | ||
raised.should == _ex_ | ||
} | ||
|
||
Pry.new.process_command 'cd-cause', '', b2 | ||
Pry.new.process_command 'cd-cause ErrorOne binding' | ||
end | ||
end | ||
|
||
describe "cd-cause" do | ||
it "should enter the next exception's context" do | ||
_ex_ = nil | ||
e1 = nil | ||
Pry::rescue do | ||
begin | ||
context "when no exception is given" do | ||
it "expect to enter the context of _ex_" do | ||
b2 = nil | ||
_ex_ = nil | ||
Pry::rescue do | ||
begin | ||
b1 = binding | ||
raise "original" | ||
rescue => e1 | ||
rescue => ErrorOne | ||
b2 = binding | ||
raise # similar to dubious re-raises you'll find in the wild | ||
end | ||
rescue => e2 | ||
_ex_ = e2 | ||
end | ||
end | ||
|
||
PryRescue.should_receive(:enter_exception_context).once.with(e1) | ||
expect(Pry).to receive(:rescued) do |raised| | ||
expect(raised).to eq(ErrorOne) | ||
end | ||
|
||
Pry.new.process_command 'cd-cause', '', binding | ||
Pry.new.process_command 'cd-cause ErrorOne binding' | ||
end | ||
end | ||
|
||
it "should raise a CommandError if no previous commands" do | ||
begin | ||
b1 = binding | ||
raise "original" | ||
rescue => e1 | ||
# Hacks due to us not really entering a pry session here | ||
_rescued_ = e1 | ||
_ex_ = e1 | ||
end | ||
context "when it has nested exceptions" do | ||
it "expect to enter the next exception's context" do | ||
_ex_ = nil | ||
e1 = nil | ||
Pry::rescue do | ||
begin | ||
begin | ||
b1 = binding | ||
raise "original" | ||
rescue => DeepException | ||
b2 = binding | ||
raise # similar to dubious re-raises you'll find in the wild | ||
end | ||
rescue => ErrorOne | ||
_ex_ = ErrorOne | ||
end | ||
end | ||
|
||
expect(PryRescue).to receive(:enter_exception_context) do |raised| | ||
expect(raised).to eq(DeepException) | ||
end | ||
|
||
lambda{ | ||
Pry.new.process_command 'cd-cause', '', binding | ||
}.should raise_error Pry::CommandError, /No previous exception/ | ||
Pry.new.process_command 'cd-cause DeepException binding' | ||
end | ||
end | ||
|
||
it "should raise a CommandError on a re-raise" do | ||
_ex_ = nil | ||
Pry::rescue do | ||
context "when there are no previous commands" do | ||
it "expect to raise a CommandError" do | ||
begin | ||
b1 = binding | ||
raise "original" | ||
rescue => ErrorOne | ||
# Hacks due to us not really entering a pry session here | ||
_rescued_ = ErrorOne | ||
_ex_ = ErrorOne | ||
end | ||
|
||
expect { | ||
Pry.new.process_command 'cd-cause' | ||
}.to raise_error Pry::CommandError, /No previous exception/ | ||
end | ||
end | ||
|
||
context "when a re-raise occurs" do | ||
it "expect to raise a CommandError" do | ||
_ex_ = nil | ||
Pry::rescue do | ||
begin | ||
raise "oops" | ||
rescue => e | ||
raise e | ||
begin | ||
raise "oops" | ||
rescue => e | ||
raise e | ||
end | ||
rescue => _ex_ | ||
end | ||
rescue => _ex_ | ||
end | ||
end | ||
_rescued_ = _ex_ | ||
_rescued_ = _ex_ | ||
|
||
lambda{ | ||
Pry.new.process_command 'cd-cause', '', binding | ||
}.should raise_error Pry::CommandError, /No previous exception/ | ||
expect { | ||
Pry.new.process_command 'cd-cause' | ||
}.to raise_error Pry::CommandError, /No previous exception/ | ||
end | ||
end | ||
|
||
it "should raise a CommandError if not in Pry::rescue" do | ||
lambda{ | ||
Pry.new.process_command 'cd-cause', '', binding | ||
}.should raise_error Pry::CommandError, /No previous exception/ | ||
context "when not in Pry::rescue" do | ||
it "should raise CommandError" do | ||
expect { | ||
Pry.new.process_command 'cd-cause' | ||
}.to raise_error Pry::CommandError, /No previous exception/ | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@magicalbanana I'm stuffy, but
it "should ..."
reads way better thanit "expect to ..."
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe.
It should be
it "is expected"
since expect commands more assertion than should in english. But when I find time will work on this and message you when it's ready.