File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,15 @@ def padding=(value)
34
34
@padding = [ 0 , value ] . max
35
35
end
36
36
37
+ # Sets the output padding while executing a block and resets it.
38
+ #
39
+ def indent ( count = 1 , &block )
40
+ orig_padding = padding
41
+ self . padding = padding + count
42
+ yield
43
+ self . padding = orig_padding
44
+ end
45
+
37
46
# Asks something to the user and receives a response.
38
47
#
39
48
# If asked to limit the correct responses, you can pass in an
Original file line number Diff line number Diff line change @@ -16,6 +16,35 @@ def shell
16
16
end
17
17
end
18
18
19
+ describe "#indent" do
20
+ it "sets the padding temporarily" do
21
+ shell . indent { expect ( shell . padding ) . to eq ( 1 ) }
22
+ expect ( shell . padding ) . to eq ( 0 )
23
+ end
24
+
25
+ it "derives padding from original value" do
26
+ shell . padding = 6
27
+ shell . indent { expect ( shell . padding ) . to eq ( 7 ) }
28
+ end
29
+
30
+ it "accepts custom indentation amounts" do
31
+ shell . indent ( 6 ) {
32
+ expect ( shell . padding ) . to eq ( 6 )
33
+ }
34
+ end
35
+
36
+ it "increases the padding when nested" do
37
+ shell . indent {
38
+ expect ( shell . padding ) . to eq ( 1 )
39
+
40
+ shell . indent {
41
+ expect ( shell . padding ) . to eq ( 2 )
42
+ }
43
+ }
44
+ expect ( shell . padding ) . to eq ( 0 )
45
+ end
46
+ end
47
+
19
48
describe "#ask" do
20
49
it "prints a message to the user and gets the response" do
21
50
expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( "Should I overwrite it? " , { } ) . and_return ( "Sure" )
You can’t perform that action at this time.
0 commit comments