Skip to content

Commit 3d5e96f

Browse files
committed
Fix return value for Ruby < 2.6
`FileUtils.cd` only returns the value of the block in Ruby >= 2.6.
1 parent 6c14044 commit 3d5e96f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/thor/actions.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,13 @@ def inside(dir = "", config = {}, &block)
181181
FileUtils.mkdir_p(destination_root)
182182
end
183183

184-
result = if pretend
184+
result = nil
185+
if pretend
185186
# In pretend mode, just yield down to the block
186-
block.arity == 1 ? yield(destination_root) : yield
187+
result = block.arity == 1 ? yield(destination_root) : yield
187188
else
188189
require "fileutils"
189-
FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
190+
FileUtils.cd(destination_root) { result = block.arity == 1 ? yield(destination_root) : yield }
190191
end
191192

192193
@destination_stack.pop

spec/actions_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ def file
174174
runner.inside("bar", :pretend => true) {}
175175
expect(File.exist?("bar")).to be false
176176
end
177+
178+
it "returns the value yielded by the block" do
179+
expect(runner.inside("foo") { 123 }).to eq(123)
180+
end
177181
end
178182

179183
describe "when verbose" do

0 commit comments

Comments
 (0)