-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #697 from TomFinill/tack-no_commands-blocks-using-…
…stack Allow for nested no_commands blocks.
- Loading branch information
Showing
5 changed files
with
70 additions
and
9 deletions.
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
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,29 @@ | ||
class Thor | ||
class NestedContext | ||
def initialize | ||
@depth = 0 | ||
end | ||
|
||
def enter | ||
push | ||
|
||
yield | ||
ensure | ||
pop | ||
end | ||
|
||
def entered? | ||
@depth > 0 | ||
end | ||
|
||
private | ||
|
||
def push | ||
@depth += 1 | ||
end | ||
|
||
def pop | ||
@depth -= 1 | ||
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
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,20 @@ | ||
require "helper" | ||
|
||
describe Thor::NestedContext do | ||
subject(:context) { described_class.new } | ||
|
||
describe "#enter" do | ||
it "is never empty within the entered block" do | ||
context.enter do | ||
context.enter {} | ||
|
||
expect(context).to be_entered | ||
end | ||
end | ||
|
||
it "is empty when outside of all blocks" do | ||
context.enter { context.enter {} } | ||
expect(context).not_to be_entered | ||
end | ||
end | ||
end |