-
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
Open
neumachen
wants to merge
4
commits into
ConradIrwin:master
Choose a base branch
from
neumachen:test-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test fixes #84
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
422a7ff
Executed rspec --init and configured to use the 3.2 RSpec syntax.
neumachen c969ff7
Updated to use the RSpec 3.2 syntax. Also grouped test using contexts.
neumachen 5f8fb97
Fixed style guide for RSpec describe blocks (added # on methods or cl…
neumachen a7d0a11
added coderay dependency to try and fix the Travis CI build error.
neumachen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.